Пример #1
0
    /**
     * @ZF-9488
     */
    public function testTerritoryToGetLocale()
    {
        $value = Locale::findLocale('US');
        $this->assertEquals('en_US', $value);

        $value = new Locale('US');
        $this->assertEquals('en_US', $value->toString());

        $value = new Locale('TR');
        $this->assertEquals('tr_TR', $value->toString());
    }
Пример #2
0
 public function testDefaultLocale()
 {
     $lang = new Translator\Translator(Translator\Translator::AN_ARRAY, array('msg1' => 'message1'));
     $defaultLocale = new Locale\Locale();
     $this->assertEquals($defaultLocale->toString(), $lang->getLocale());
 }
Пример #3
0
 /**
  * Returns true if both locales are equal
  *
  * @param  \Zend\Locale\Locale $object Locale to check for equality
  * @return boolean
  */
 public function equals(Locale $object)
 {
     if ($object->toString() === $this->toString()) {
         return true;
     }
     return false;
 }
Пример #4
0
 /**
  * test setOption
  * expected boolean
  */
 public function testSetOption()
 {
     $this->assertEquals(8, count(Format::setOptions(array('format_type' => 'php'))));
     $this->assertTrue(is_array(Format::setOptions()));
     try {
         $this->assertTrue(Format::setOptions(array('format_type' => 'xxx')));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     try {
         $this->assertTrue(Format::setOptions(array('myformat' => 'xxx')));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     $format = Format::setOptions(array('locale' => 'de', 'number_format' => Format::STANDARD));
     $test = Cldr::getContent('de', 'decimalnumber');
     $this->assertEquals($test, $format['number_format']);
     try {
         $this->assertFalse(Format::setOptions(array('number_format' => array('x' => 'x'))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     $format = Format::setOptions(array('locale' => 'de', 'date_format' => Format::STANDARD));
     $test = Format::getDateFormat('de');
     $this->assertEquals($test, $format['date_format']);
     try {
         $this->assertFalse(Format::setOptions(array('date_format' => array('x' => 'x'))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     try {
         $this->assertFalse(is_array(Format::setOptions(array('fix_date' => 'no'))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     $format = Format::setOptions(array('locale' => Format::STANDARD));
     $locale = new Locale();
     $this->assertEquals($locale->toString(), $format['locale']);
     try {
         $this->assertFalse(is_array(Format::setOptions(array('locale' => 'nolocale'))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     try {
         $this->assertFalse(is_array(Format::setOptions(array('precision' => 50))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     // test interaction between class-wide default date format and using locale's default format
     try {
         $result = array('date_format' => 'MMM d, y', 'locale' => 'en_US', 'month' => '7', 'day' => '4', 'year' => '2007');
         Format::setOptions(array('format_type' => 'iso', 'date_format' => 'MMM d, y', 'locale' => 'en_US'));
         // test setUp
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // uses global date_format with global locale
         $this->assertSame($result, Format::getDate('July 4, 2007'));
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // uses global date_format with given locale
         $this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US')));
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // sets a new global date format
         Format::setOptions(array('date_format' => 'M-d-y'));
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // uses global date format with given locale
         // but this date format differs from the original set... (MMMM d, yyyy != M-d-y)
         $expected = Format::getDate('July 4, 2007', array('locale' => 'en_US'));
         $this->assertSame($expected['year'], $result['year']);
         $this->assertSame($expected['month'], $result['month']);
         $this->assertSame($expected['day'], $result['day']);
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // the following should not be used... instead of null, Locale::ZFDEFAULT should be used
         // uses given local with standard format from this locale
         $this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => null)));
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // uses given locale with standard format from this locale
         $this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => Format::STANDARD)));
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // uses standard locale with standard format from this locale
         $expect = Format::getDate('July 4, 2007', array('locale' => Format::STANDARD));
         $testlocale = new Locale();
         $this->assertEquals($testlocale->toString(), $expect['locale']);
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     Format::setOptions(array('date_format' => null, 'locale' => null));
     // test tearDown
 }