Hoa central
Public Member Functions | List of all members
Hoa\Locale\Test\Unit\Locale Class Reference
Inheritance diagram for Hoa\Locale\Test\Unit\Locale:

Public Member Functions

 case_no_default_no_locale ()
 
 case_no_locale ()
 
 case_locale_autoBoxing ()
 
 case_invalid_locale ()
 
 case_type_privateUse ()
 
 case_type_grandfathered ()
 
 case_type_langtag ()
 
 case_langtag_exploded ()
 
 case_langtag_default ()
 
 case_reset ()
 
- Public Member Functions inherited from Hoa\Test\Unit\Suite
 __construct ()
 
 getTestedClassName ()
 
 getTestedClassNamespace ()
 
 beforeTestMethod ($methodName)
 

Detailed Description

Class .

Test suite of the locale main object.

Definition at line 50 of file Locale.php.

Member Function Documentation

Hoa\Locale\Test\Unit\Locale::case_invalid_locale ( )

Definition at line 94 of file Locale.php.

95  {
96  $this
97  ->exception(function () {
98  new LUT('fr_FR');
99  })
100  ->isInstanceOf('Hoa\Locale\Exception');
101  }
Hoa\Locale\Test\Unit\Locale::case_langtag_default ( )

Definition at line 202 of file Locale.php.

203  {
204  $this
205  ->given($locale = 'fr')
206  ->when($result = new LUT($locale))
207  ->then
208  ->string($result->getLanguage())
209  ->isEqualTo('fr')
210  ->variable($result->getScript())
211  ->isNull()
212  ->variable($result->getRegion())
213  ->isNull()
214  ->array($result->getVariants())
215  ->isEmpty()
216  ->array($result->getExtensions())
217  ->isEmpty()
218  ->variable($result->getPrivateUse())
219  ->isNull();
220  }
Hoa\Locale\Test\Unit\Locale::case_langtag_exploded ( )

Definition at line 182 of file Locale.php.

183  {
184  $this
185  ->given($locale = 'zh-Hant-TW-xy-ab-123-f-oo-4-42-x-qux')
186  ->when($result = new LUT($locale))
187  ->then
188  ->string($result->getLanguage())
189  ->isEqualTo('zh')
190  ->string($result->getScript())
191  ->isEqualTo('Hant')
192  ->string($result->getRegion())
193  ->isEqualTo('TW')
194  ->array($result->getVariants())
195  ->isEqualTo(['xy', 'ab', '123'])
196  ->array($result->getExtensions())
197  ->isEqualTo(['f' => 'oo', 4 => '42'])
198  ->string($result->getPrivateUse())
199  ->isEqualTo('qux');
200  }
Hoa\Locale\Test\Unit\Locale::case_locale_autoBoxing ( )

Definition at line 84 of file Locale.php.

85  {
86  $this
87  ->given($locale = new LUT('fr-FR'))
88  ->when($localizer = $locale->getLocalizer())
89  ->then
90  ->object($localizer)
91  ->isInstanceOf('Hoa\Locale\Localizer\Coerce');
92  }
Hoa\Locale\Test\Unit\Locale::case_no_default_no_locale ( )

Definition at line 52 of file Locale.php.

53  {
54  $this
55  ->exception(function () {
56  new LUT();
57  })
58  ->isInstanceOf('Hoa\Locale\Exception');
59  }
Hoa\Locale\Test\Unit\Locale::case_no_locale ( )

Definition at line 61 of file Locale.php.

62  {
63  $this
64  ->given(
65  LUT::setDefault('fr-FR'),
66  $locale = new LUT()
67  )
68  ->when(
69  $localizer = $locale->getLocalizer(),
70  $language = $locale->getLanguage(),
71  $region = $locale->getRegion()
72  )
73  ->then
74  ->object($localizer)
75  ->isInstanceOf('Hoa\Locale\Localizer\Coerce')
76  ->variable($localizer->getLocale())
77  ->isNull()
78  ->string($language)
79  ->isEqualTo('fr')
80  ->string($region)
81  ->isEqualTo('FR');
82  }
Hoa\Locale\Test\Unit\Locale::case_reset ( )

Definition at line 222 of file Locale.php.

223  {
224  $this
225  ->given(
226  $localizer = new LUT\Localizer\Coerce(
227  'zh-Hant-TW-xy-ab-123-f-oo-4-42-x-qux'
228  )
229  )
230  ->when($locale = new LUT($localizer))
231  ->then
232  ->string($locale->getLanguage())
233  ->isEqualTo('zh')
234  ->string($locale->getScript())
235  ->isEqualTo('Hant')
236  ->string($locale->getRegion())
237  ->isEqualTo('TW')
238  ->array($locale->getVariants())
239  ->isEqualTo(['xy', 'ab', '123'])
240  ->array($locale->getExtensions())
241  ->isEqualTo(['f' => 'oo', 4 => '42'])
242  ->string($locale->getPrivateUse())
243  ->isEqualTo('qux')
244 
245  ->given($localizer = new LUT\Localizer\Coerce('fr'))
246  ->when($locale->setLocalizer($localizer))
247  ->then
248  ->string($locale->getLanguage())
249  ->isEqualTo('fr')
250  ->variable($locale->getScript())
251  ->isNull()
252  ->variable($locale->getRegion())
253  ->isNull()
254  ->array($locale->getVariants())
255  ->isEmpty()
256  ->array($locale->getExtensions())
257  ->isEmpty()
258  ->variable($locale->getPrivateUse())
259  ->isNull();
260  }
Hoa\Locale\Test\Unit\Locale::case_type_grandfathered ( )

Definition at line 128 of file Locale.php.

129  {
130  $this
131  ->given(
132  $regex = $this->realdom->regex(
133  // Modified regular expression,
134  // to avoid conflict with TYPE_LANGTAG
135  '/[a-wyz](\-[a-z0-9]{2,8}){1,2}/'
136  )
137  )
138  ->when(function () use ($regex) {
139  foreach ($this->sampleMany($regex, 1000) as $datum) {
140  $this
141  ->given($locale = new LUT($datum))
142  ->when(
143  $type = $locale->getType(),
144  $grandFathered = $locale->getGrandfathered()
145  )
146  ->then
147  ->integer($type)
148  ->isEqualTo(LUT::TYPE_GRANDFATHERED)
149  ->string($grandFathered)
150  ->isEqualTo($datum);
151  }
152  });
153  }
Hoa\Locale\Test\Unit\Locale::case_type_langtag ( )

Definition at line 155 of file Locale.php.

156  {
157  $this
158  ->given(
159  $regex = $this->realdom->regex(
160  '/' .
161  '[a-z]{2,3}' .
162  '(\-[a-z]{4})?' .
163  '(\-(?:[a-z]{2}|[0-9]{4}))?' .
164  '((?:\-(?:[a-z]{2}|[0-9]{3}))+)?' .
165  '((?:\-(?:[a-wy-z]|\d)\-[a-z0-9]{2,8})+)?' .
166  '(\-x\-[a-z0-9]{1,8})?' .
167  '/'
168  )
169  )
170  ->when(function () use ($regex) {
171  foreach ($this->sampleMany($regex, 1000) as $datum) {
172  $this
173  ->given($locale = new LUT($datum))
174  ->when($type = $locale->getType())
175  ->then
176  ->integer($type)
177  ->isEqualTo(LUT::TYPE_LANGTAG);
178  }
179  });
180  }
Hoa\Locale\Test\Unit\Locale::case_type_privateUse ( )

Definition at line 103 of file Locale.php.

104  {
105  $this
106  ->given(
107  $regex = $this->realdom->regex(
108  '/x\-[a-z0-9]{1,8}/'
109  )
110  )
111  ->when(function () use ($regex) {
112  foreach ($this->sampleMany($regex, 1000) as $datum) {
113  $this
114  ->given($locale = new LUT($datum))
115  ->when(
116  $type = $locale->getType(),
117  $privateUse = $locale->getPrivateUse()
118  )
119  ->then
120  ->integer($type)
121  ->isEqualTo(LUT::TYPE_PRIVATEUSE)
122  ->string('x-' . $privateUse)
123  ->isEqualTo($datum);
124  }
125  });
126  }

The documentation for this class was generated from the following file: