1 | <?php |
||
8 | class LanguageMapSpec extends ObjectBehavior |
||
9 | { |
||
10 | function let() |
||
11 | { |
||
12 | $this->beConstructedThrough('create', array(array( |
||
13 | 'de-DE' => 'teilgenommen', |
||
14 | 'en-GB' => 'attended', |
||
15 | ))); |
||
16 | } |
||
17 | |||
18 | function it_is_initializable() |
||
19 | { |
||
20 | $this->shouldHaveType('Xabbuh\XApi\Model\LanguageMap'); |
||
21 | } |
||
22 | |||
23 | function it_can_be_created_with_an_existing_array_map() |
||
24 | { |
||
25 | $this->beConstructedThrough('create', array(array( |
||
26 | 'de-DE' => 'teilgenommen', |
||
27 | 'en-GB' => 'attended', |
||
28 | 'en-US' => 'attended', |
||
29 | ))); |
||
30 | |||
31 | $this->offsetGet('de-DE')->shouldReturn('teilgenommen'); |
||
32 | $this->offsetGet('en-GB')->shouldReturn('attended'); |
||
33 | $this->offsetGet('en-US')->shouldReturn('attended'); |
||
34 | } |
||
35 | |||
36 | function it_returns_a_new_instance_with_an_added_entry() |
||
37 | { |
||
38 | $languageTag = $this->withEntry('en-US', 'attended'); |
||
39 | $languageTag->offsetExists('en-US')->shouldReturn(true); |
||
40 | $languageTag->shouldNotBe($this); |
||
41 | $this->offsetExists('en-US')->shouldReturn(false); |
||
42 | } |
||
43 | |||
44 | function it_returns_a_new_instance_with_a_modified_entry() |
||
45 | { |
||
46 | $languageTag = $this->withEntry('en-GB', 'test'); |
||
47 | $languageTag->offsetGet('en-GB')->shouldReturn('test'); |
||
48 | $languageTag->shouldNotBe($this); |
||
49 | $this->offsetGet('en-GB')->shouldReturn('attended'); |
||
50 | } |
||
51 | |||
52 | function its_language_tags_can_be_retrieved() |
||
53 | { |
||
54 | $languageTags = $this->languageTags(); |
||
55 | $languageTags->shouldBeArray(); |
||
56 | $languageTags->shouldHaveCount(2); |
||
57 | $languageTags->shouldContain('de-DE'); |
||
58 | $languageTags->shouldContain('en-GB'); |
||
59 | } |
||
60 | |||
61 | function it_throws_an_exception_when_a_non_existent_language_tag_is_requested() |
||
62 | { |
||
63 | $this->shouldThrow('\InvalidArgumentException')->during('offsetGet', array('en-US')); |
||
64 | } |
||
65 | |||
66 | function it_can_be_asked_if_a_language_tag_is_known() |
||
67 | { |
||
68 | $this->offsetExists('en-GB')->shouldReturn(true); |
||
69 | $this->offsetExists('en-US')->shouldReturn(false); |
||
70 | } |
||
71 | |||
72 | function its_values_cannot_be_modified() |
||
73 | { |
||
74 | $this->shouldThrow('\LogicException')->during('offsetSet', array('en-US', 'attended')); |
||
75 | } |
||
76 | |||
77 | function its_values_cannot_be_removed() |
||
78 | { |
||
79 | $this->shouldThrow('\LogicException')->during('offsetUnset', array('en-US')); |
||
80 | } |
||
81 | |||
82 | function it_is_not_equal_with_another_language_map_if_number_of_entries_differ() |
||
83 | { |
||
84 | $languageMap = LanguageMap::create(array( |
||
85 | 'de-DE' => 'teilgenommen', |
||
86 | 'en-GB' => 'attended', |
||
87 | 'en-US' => 'attended', |
||
88 | )); |
||
89 | |||
90 | $this->equals($languageMap)->shouldReturn(false); |
||
91 | } |
||
92 | |||
93 | function it_is_not_equal_with_another_language_map_if_keys_differ() |
||
94 | { |
||
95 | $languageMap = LanguageMap::create(array( |
||
96 | 'de-DE' => 'teilgenommen', |
||
97 | 'en-US' => 'attended', |
||
98 | )); |
||
99 | |||
100 | $this->equals($languageMap)->shouldReturn(false); |
||
101 | } |
||
102 | |||
103 | function it_is_not_equal_with_another_language_map_if_values_differ() |
||
104 | { |
||
105 | $languageMap = LanguageMap::create(array( |
||
106 | 'de-DE' => 'teilgenommen', |
||
107 | 'en-GB' => 'participated', |
||
108 | )); |
||
109 | |||
110 | $this->equals($languageMap)->shouldReturn(false); |
||
111 | } |
||
112 | |||
113 | function it_is_equal_with_itself() |
||
114 | { |
||
115 | $this->equals($this)->shouldReturn(true); |
||
116 | } |
||
117 | |||
118 | function it_is_equal_with_another_language_map_if_key_value_pairs_are_equal() |
||
119 | { |
||
120 | $languageMap = LanguageMap::create(array( |
||
121 | 'en-GB' => 'attended', |
||
122 | 'de-DE' => 'teilgenommen', |
||
123 | )); |
||
124 | |||
125 | $this->equals($languageMap)->shouldReturn(true); |
||
126 | } |
||
127 | } |
||
128 |