From 4f5b44bd3bd490309eb2ba7b44df4769816ba729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 19:26:54 +0200 Subject: twig implementation --- .../Tests/ResourceBundle/AbstractBundleTest.php | 55 +++++ .../Tests/ResourceBundle/CurrencyBundleTest.php | 98 +++++++++ .../Tests/ResourceBundle/LanguageBundleTest.php | 197 ++++++++++++++++++ .../Intl/Tests/ResourceBundle/LocaleBundleTest.php | 64 ++++++ .../Reader/AbstractBundleReaderTest.php | 64 ++++++ .../Reader/BinaryBundleReaderTest.php | 58 ++++++ .../Reader/Fixtures/NotAFile/en.php/.gitkeep | 0 .../Tests/ResourceBundle/Reader/Fixtures/en.php | 14 ++ .../Tests/ResourceBundle/Reader/Fixtures/en.res | Bin 0 -> 84 bytes .../Tests/ResourceBundle/Reader/Fixtures/en.txt | 3 + .../ResourceBundle/Reader/PhpBundleReaderTest.php | 63 ++++++ .../Reader/StructuredBundleReaderTest.php | 223 +++++++++++++++++++++ .../Intl/Tests/ResourceBundle/RegionBundleTest.php | 63 ++++++ .../Tests/ResourceBundle/Util/RingBufferTest.php | 101 ++++++++++ .../Tests/ResourceBundle/Writer/Fixtures/en.php | 23 +++ .../Tests/ResourceBundle/Writer/Fixtures/en.res | Bin 0 -> 316 bytes .../Tests/ResourceBundle/Writer/Fixtures/en.txt | 23 +++ .../ResourceBundle/Writer/PhpBundleWriterTest.php | 62 ++++++ .../ResourceBundle/Writer/TextBundleWriterTest.php | 67 +++++++ 19 files changed, 1178 insertions(+) create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/AbstractBundleTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/AbstractBundleReaderTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/BinaryBundleReaderTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/NotAFile/en.php/.gitkeep create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.res create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.txt create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/PhpBundleReaderTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/StructuredBundleReaderTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Util/RingBufferTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.res create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.txt create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/PhpBundleWriterTest.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/TextBundleWriterTest.php (limited to 'vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle') diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/AbstractBundleTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/AbstractBundleTest.php new file mode 100644 index 00000000..6b075865 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/AbstractBundleTest.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle; + +/** + * @author Bernhard Schussek + */ +class AbstractBundleTest extends \PHPUnit_Framework_TestCase +{ + const RES_DIR = '/base/dirName'; + + /** + * @var \Symfony\Component\Intl\ResourceBundle\AbstractBundle + */ + private $bundle; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $reader; + + protected function setUp() + { + $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface'); + $this->bundle = $this->getMockForAbstractClass( + 'Symfony\Component\Intl\ResourceBundle\AbstractBundle', + array(self::RES_DIR, $this->reader) + ); + + $this->bundle->expects($this->any()) + ->method('getDirectoryName') + ->will($this->returnValue('dirName')); + } + + public function testGetLocales() + { + $locales = array('de', 'en', 'fr'); + + $this->reader->expects($this->once()) + ->method('getLocales') + ->with(self::RES_DIR) + ->will($this->returnValue($locales)); + + $this->assertSame($locales, $this->bundle->getLocales()); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php new file mode 100644 index 00000000..b66a6727 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle; + +use Symfony\Component\Intl\ResourceBundle\CurrencyBundle; + +/** + * @author Bernhard Schussek + */ +class CurrencyBundleTest extends \PHPUnit_Framework_TestCase +{ + const RES_DIR = '/base/curr'; + + /** + * @var CurrencyBundle + */ + private $bundle; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $reader; + + protected function setUp() + { + $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface'); + $this->bundle = new CurrencyBundle(self::RES_DIR, $this->reader); + } + + public function testGetCurrencySymbol() + { + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 1)) + ->will($this->returnValue('€')); + + $this->assertSame('€', $this->bundle->getCurrencySymbol('EUR', 'en')); + } + + public function testGetCurrencyName() + { + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 0)) + ->will($this->returnValue('Euro')); + + $this->assertSame('Euro', $this->bundle->getCurrencyName('EUR', 'en')); + } + + public function testGetCurrencyNames() + { + $sortedCurrencies = array( + 'USD' => array(0 => 'Dollar'), + 'EUR' => array(0 => 'Euro'), + ); + + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Currencies')) + ->will($this->returnValue($sortedCurrencies)); + + $sortedNames = array( + 'USD' => 'Dollar', + 'EUR' => 'Euro', + ); + + $this->assertSame($sortedNames, $this->bundle->getCurrencyNames('en')); + } + + public function testGetFractionDigits() + { + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 2)) + ->will($this->returnValue(123)); + + $this->assertSame(123, $this->bundle->getFractionDigits('EUR')); + } + + public function testGetRoundingIncrement() + { + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 3)) + ->will($this->returnValue(123)); + + $this->assertSame(123, $this->bundle->getRoundingIncrement('EUR')); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php new file mode 100644 index 00000000..96031fc7 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php @@ -0,0 +1,197 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle; + +use Symfony\Component\Intl\ResourceBundle\LanguageBundle; + +/** + * @author Bernhard Schussek + */ +class LanguageBundleTest extends \PHPUnit_Framework_TestCase +{ + const RES_DIR = '/base/lang'; + + /** + * @var LanguageBundle + */ + private $bundle; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $reader; + + protected function setUp() + { + $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface'); + $this->bundle = new LanguageBundle(self::RES_DIR, $this->reader); + } + + public function testGetLanguageName() + { + $languages = array( + 'de' => 'German', + 'en' => 'English', + ); + + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Languages')) + ->will($this->returnValue($languages)); + + $this->assertSame('German', $this->bundle->getLanguageName('de', null, 'en')); + } + + public function testGetLanguageNameWithRegion() + { + $languages = array( + 'de' => 'German', + 'en' => 'English', + 'en_GB' => 'British English', + ); + + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Languages')) + ->will($this->returnValue($languages)); + + $this->assertSame('British English', $this->bundle->getLanguageName('en', 'GB', 'en')); + } + + public function testGetLanguageNameWithUntranslatedRegion() + { + $languages = array( + 'de' => 'German', + 'en' => 'English', + ); + + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Languages')) + ->will($this->returnValue($languages)); + + $this->assertSame('English', $this->bundle->getLanguageName('en', 'US', 'en')); + } + + public function testGetLanguageNames() + { + $sortedLanguages = array( + 'en' => 'English', + 'de' => 'German', + ); + + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Languages')) + ->will($this->returnValue($sortedLanguages)); + + $this->assertSame($sortedLanguages, $this->bundle->getLanguageNames('en')); + } + + public function testGetScriptName() + { + $data = array( + 'Languages' => array( + 'de' => 'German', + 'en' => 'English', + ), + 'Scripts' => array( + 'Latn' => 'latin', + 'Cyrl' => 'cyrillique', + ), + ); + + $this->reader->expects($this->once()) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($data)); + + $this->assertSame('latin', $this->bundle->getScriptName('Latn', null, 'en')); + } + + public function testGetScriptNameIncludedInLanguage() + { + $data = array( + 'Languages' => array( + 'de' => 'German', + 'en' => 'English', + 'zh_Hans' => 'Simplified Chinese', + ), + 'Scripts' => array( + 'Latn' => 'latin', + 'Cyrl' => 'cyrillique', + ), + ); + + $this->reader->expects($this->once()) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($data)); + + // Null because the script is included in the language anyway + $this->assertNull($this->bundle->getScriptName('Hans', 'zh', 'en')); + } + + public function testGetScriptNameIncludedInLanguageInBraces() + { + $data = array( + 'Languages' => array( + 'de' => 'German', + 'en' => 'English', + 'zh_Hans' => 'Chinese (simplified)', + ), + 'Scripts' => array( + 'Latn' => 'latin', + 'Cyrl' => 'cyrillique', + ), + ); + + $this->reader->expects($this->once()) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($data)); + + $this->assertSame('simplified', $this->bundle->getScriptName('Hans', 'zh', 'en')); + } + + public function testGetScriptNameNoScriptsBlock() + { + $data = array( + 'Languages' => array( + 'de' => 'German', + 'en' => 'English', + ), + ); + + $this->reader->expects($this->once()) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($data)); + + $this->assertNull($this->bundle->getScriptName('Latn', null, 'en')); + } + + public function testGetScriptNames() + { + $sortedScripts = array( + 'Cyrl' => 'cyrillique', + 'Latn' => 'latin', + ); + + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Scripts')) + ->will($this->returnValue($sortedScripts)); + + $this->assertSame($sortedScripts, $this->bundle->getScriptNames('en')); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php new file mode 100644 index 00000000..ddfdc3d2 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle; + +use Symfony\Component\Intl\ResourceBundle\LocaleBundle; + +/** + * @author Bernhard Schussek + */ +class LocaleBundleTest extends \PHPUnit_Framework_TestCase +{ + const RES_DIR = '/base/locales'; + + /** + * @var LocaleBundle + */ + private $bundle; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $reader; + + protected function setUp() + { + $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface'); + $this->bundle = new LocaleBundle(self::RES_DIR, $this->reader); + } + + public function testGetLocaleName() + { + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Locales', 'de_AT')) + ->will($this->returnValue('German (Austria)')); + + $this->assertSame('German (Austria)', $this->bundle->getLocaleName('de_AT', 'en')); + } + + public function testGetLocaleNames() + { + $sortedLocales = array( + 'en_IE' => 'English (Ireland)', + 'en_GB' => 'English (United Kingdom)', + 'en_US' => 'English (United States)', + ); + + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Locales')) + ->will($this->returnValue($sortedLocales)); + + $this->assertSame($sortedLocales, $this->bundle->getLocaleNames('en')); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/AbstractBundleReaderTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/AbstractBundleReaderTest.php new file mode 100644 index 00000000..2da7f90d --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/AbstractBundleReaderTest.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle\Reader; + +use Symfony\Component\Filesystem\Filesystem; + +/** + * @author Bernhard Schussek + */ +class AbstractBundleReaderTest extends \PHPUnit_Framework_TestCase +{ + private $directory; + + /** + * @var Filesystem + */ + private $filesystem; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $reader; + + protected function setUp() + { + $this->directory = sys_get_temp_dir() . '/AbstractBundleReaderTest/' . rand(1000, 9999); + $this->filesystem = new Filesystem(); + $this->reader = $this->getMockForAbstractClass('Symfony\Component\Intl\ResourceBundle\Reader\AbstractBundleReader'); + + $this->filesystem->mkdir($this->directory); + } + + protected function tearDown() + { + $this->filesystem->remove($this->directory); + } + + public function testGetLocales() + { + $this->filesystem->touch($this->directory . '/en.foo'); + $this->filesystem->touch($this->directory . '/de.foo'); + $this->filesystem->touch($this->directory . '/fr.foo'); + $this->filesystem->touch($this->directory . '/bo.txt'); + $this->filesystem->touch($this->directory . '/gu.bin'); + $this->filesystem->touch($this->directory . '/s.lol'); + + $this->reader->expects($this->any()) + ->method('getFileExtension') + ->will($this->returnValue('foo')); + + $sortedLocales = array('de', 'en', 'fr'); + + $this->assertSame($sortedLocales, $this->reader->getLocales($this->directory)); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/BinaryBundleReaderTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/BinaryBundleReaderTest.php new file mode 100644 index 00000000..3aefbae7 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/BinaryBundleReaderTest.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle\Reader; + +use Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader; +use Symfony\Component\Intl\Util\IntlTestHelper; + +/** + * @author Bernhard Schussek + */ +class BinaryBundleReaderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var BinaryBundleReader + */ + private $reader; + + protected function setUp() + { + IntlTestHelper::requireFullIntl($this); + + $this->reader = new BinaryBundleReader(); + } + + public function testReadReturnsArrayAccess() + { + $data = $this->reader->read(__DIR__ . '/Fixtures', 'en'); + + $this->assertInstanceOf('\ArrayAccess', $data); + $this->assertSame('Bar', $data['Foo']); + $this->assertFalse(isset($data['ExistsNot'])); + } + + /** + * @expectedException \Symfony\Component\Intl\Exception\RuntimeException + */ + public function testReadFailsIfNonExistingLocale() + { + $this->reader->read(__DIR__ . '/Fixtures', 'foo'); + } + + /** + * @expectedException \Symfony\Component\Intl\Exception\RuntimeException + */ + public function testReadFailsIfNonExistingDirectory() + { + $this->reader->read(__DIR__ . '/foo', 'en'); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/NotAFile/en.php/.gitkeep b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/NotAFile/en.php/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.php new file mode 100644 index 00000000..f2b06a91 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.php @@ -0,0 +1,14 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return array( + 'Foo' => 'Bar', +); diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.res b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.res new file mode 100644 index 00000000..c78e9045 Binary files /dev/null and b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.res differ diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.txt b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.txt new file mode 100644 index 00000000..c788e996 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/Fixtures/en.txt @@ -0,0 +1,3 @@ +en{ + Foo{"Bar"} +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/PhpBundleReaderTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/PhpBundleReaderTest.php new file mode 100644 index 00000000..2fee3559 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/PhpBundleReaderTest.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle\Reader; + +use Symfony\Component\Intl\ResourceBundle\Reader\PhpBundleReader; + +/** + * @author Bernhard Schussek + */ +class PhpBundleReaderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var PhpBundleReader + */ + private $reader; + + protected function setUp() + { + $this->reader = new PhpBundleReader(); + } + + public function testReadReturnsArray() + { + $data = $this->reader->read(__DIR__ . '/Fixtures', 'en'); + + $this->assertTrue(is_array($data)); + $this->assertSame('Bar', $data['Foo']); + $this->assertFalse(isset($data['ExistsNot'])); + } + + /** + * @expectedException \Symfony\Component\Intl\Exception\InvalidArgumentException + */ + public function testReadFailsIfLocaleOtherThanEn() + { + $this->reader->read(__DIR__ . '/Fixtures', 'foo'); + } + + /** + * @expectedException \Symfony\Component\Intl\Exception\RuntimeException + */ + public function testReadFailsIfNonExistingDirectory() + { + $this->reader->read(__DIR__ . '/foo', 'en'); + } + + /** + * @expectedException \Symfony\Component\Intl\Exception\RuntimeException + */ + public function testReadFailsIfNotAFile() + { + $this->reader->read(__DIR__ . '/Fixtures/NotAFile', 'en'); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/StructuredBundleReaderTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/StructuredBundleReaderTest.php new file mode 100644 index 00000000..600236eb --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Reader/StructuredBundleReaderTest.php @@ -0,0 +1,223 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle\Reader; + +use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReader; + +/** + * @author Bernhard Schussek + */ +class StructuredBundleReaderTest extends \PHPUnit_Framework_TestCase +{ + const RES_DIR = '/res/dir'; + + /** + * @var StructuredBundleReader + */ + private $reader; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $readerImpl; + + protected function setUp() + { + $this->readerImpl = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface'); + $this->reader = new StructuredBundleReader($this->readerImpl); + } + + public function testGetLocales() + { + $locales = array('en', 'de', 'fr'); + + $this->readerImpl->expects($this->once()) + ->method('getLocales') + ->with(self::RES_DIR) + ->will($this->returnValue($locales)); + + $this->assertSame($locales, $this->reader->getLocales(self::RES_DIR)); + } + + public function testRead() + { + $data = array('foo', 'bar'); + + $this->readerImpl->expects($this->once()) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($data)); + + $this->assertSame($data, $this->reader->read(self::RES_DIR, 'en')); + } + + public function testReadEntryNoParams() + { + $data = array('foo', 'bar'); + + $this->readerImpl->expects($this->once()) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($data)); + + $this->assertSame($data, $this->reader->readEntry(self::RES_DIR, 'en', array())); + } + + public function testReadEntryWithParam() + { + $data = array('Foo' => array('Bar' => 'Baz')); + + $this->readerImpl->expects($this->once()) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($data)); + + $this->assertSame('Baz', $this->reader->readEntry(self::RES_DIR, 'en', array('Foo', 'Bar'))); + } + + public function testReadEntryWithUnresolvablePath() + { + $data = array('Foo' => 'Baz'); + + $this->readerImpl->expects($this->once()) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($data)); + + $this->assertNull($this->reader->readEntry(self::RES_DIR, 'en', array('Foo', 'Bar'))); + } + + public function readMergedEntryProvider() + { + return array( + array('foo', null, 'foo'), + array(null, 'foo', 'foo'), + array(array('foo', 'bar'), null, array('foo', 'bar')), + array(array('foo', 'bar'), array(), array('foo', 'bar')), + array(null, array('baz'), array('baz')), + array(array(), array('baz'), array('baz')), + array(array('foo', 'bar'), array('baz'), array('baz', 'foo', 'bar')), + ); + } + + /** + * @dataProvider readMergedEntryProvider + */ + public function testReadMergedEntryNoParams($childData, $parentData, $result) + { + $this->readerImpl->expects($this->at(0)) + ->method('read') + ->with(self::RES_DIR, 'en_GB') + ->will($this->returnValue($childData)); + + if (null === $childData || is_array($childData)) { + $this->readerImpl->expects($this->at(1)) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue($parentData)); + } + + $this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en_GB', array(), true)); + } + + /** + * @dataProvider readMergedEntryProvider + */ + public function testReadMergedEntryWithParams($childData, $parentData, $result) + { + $this->readerImpl->expects($this->at(0)) + ->method('read') + ->with(self::RES_DIR, 'en_GB') + ->will($this->returnValue(array('Foo' => array('Bar' => $childData)))); + + if (null === $childData || is_array($childData)) { + $this->readerImpl->expects($this->at(1)) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue(array('Foo' => array('Bar' => $parentData)))); + } + + $this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en_GB', array('Foo', 'Bar'), true)); + } + + public function testReadMergedEntryWithUnresolvablePath() + { + $this->readerImpl->expects($this->at(0)) + ->method('read') + ->with(self::RES_DIR, 'en_GB') + ->will($this->returnValue(array('Foo' => 'Baz'))); + + $this->readerImpl->expects($this->at(1)) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue(array('Foo' => 'Bar'))); + + $this->assertNull($this->reader->readEntry(self::RES_DIR, 'en_GB', array('Foo', 'Bar'), true)); + } + + public function testReadMergedEntryWithUnresolvablePathInParent() + { + $this->readerImpl->expects($this->at(0)) + ->method('read') + ->with(self::RES_DIR, 'en_GB') + ->will($this->returnValue(array('Foo' => array('Bar' => array('three'))))); + + $this->readerImpl->expects($this->at(1)) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue(array('Foo' => 'Bar'))); + + $result = array('three'); + + $this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en_GB', array('Foo', 'Bar'), true)); + } + + public function testReadMergedEntryWithUnresolvablePathInChild() + { + $this->readerImpl->expects($this->at(0)) + ->method('read') + ->with(self::RES_DIR, 'en_GB') + ->will($this->returnValue(array('Foo' => 'Baz'))); + + $this->readerImpl->expects($this->at(1)) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue(array('Foo' => array('Bar' => array('one', 'two'))))); + + $result = array('one', 'two'); + + $this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en_GB', array('Foo', 'Bar'), true)); + } + + /** + * @dataProvider readMergedEntryProvider + */ + public function testReadMergedEntryWithTraversables($childData, $parentData, $result) + { + $parentData = is_array($parentData) ? new \ArrayObject($parentData) : $parentData; + $childData = is_array($childData) ? new \ArrayObject($childData) : $childData; + + $this->readerImpl->expects($this->at(0)) + ->method('read') + ->with(self::RES_DIR, 'en_GB') + ->will($this->returnValue(array('Foo' => array('Bar' => $childData)))); + + if (null === $childData || $childData instanceof \ArrayObject) { + $this->readerImpl->expects($this->at(1)) + ->method('read') + ->with(self::RES_DIR, 'en') + ->will($this->returnValue(array('Foo' => array('Bar' => $parentData)))); + } + + $this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en_GB', array('Foo', 'Bar'), true)); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php new file mode 100644 index 00000000..ccdf904c --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle; + +use Symfony\Component\Intl\ResourceBundle\RegionBundle; + +/** + * @author Bernhard Schussek + */ +class RegionBundleTest extends \PHPUnit_Framework_TestCase +{ + const RES_DIR = '/base/region'; + + /** + * @var RegionBundle + */ + private $bundle; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $reader; + + protected function setUp() + { + $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface'); + $this->bundle = new RegionBundle(self::RES_DIR, $this->reader); + } + + public function testGetCountryName() + { + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Countries', 'AT')) + ->will($this->returnValue('Austria')); + + $this->assertSame('Austria', $this->bundle->getCountryName('AT', 'en')); + } + + public function testGetCountryNames() + { + $sortedCountries = array( + 'AT' => 'Austria', + 'DE' => 'Germany', + ); + + $this->reader->expects($this->once()) + ->method('readEntry') + ->with(self::RES_DIR, 'en', array('Countries')) + ->will($this->returnValue($sortedCountries)); + + $this->assertSame($sortedCountries, $this->bundle->getCountryNames('en')); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Util/RingBufferTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Util/RingBufferTest.php new file mode 100644 index 00000000..d6f7d8a0 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Util/RingBufferTest.php @@ -0,0 +1,101 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle\Util; + +use Symfony\Component\Intl\ResourceBundle\Util\RingBuffer; + +/** + * @author Bernhard Schussek + */ +class RingBufferTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var RingBuffer + */ + private $buffer; + + protected function setUp() + { + $this->buffer = new RingBuffer(2); + } + + public function testWriteWithinBuffer() + { + $this->buffer[0] = 'foo'; + $this->buffer['bar'] = 'baz'; + + $this->assertTrue(isset($this->buffer[0])); + $this->assertTrue(isset($this->buffer['bar'])); + $this->assertSame('foo', $this->buffer[0]); + $this->assertSame('baz', $this->buffer['bar']); + } + + public function testWritePastBuffer() + { + $this->buffer[0] = 'foo'; + $this->buffer['bar'] = 'baz'; + $this->buffer[2] = 'bam'; + + $this->assertTrue(isset($this->buffer['bar'])); + $this->assertTrue(isset($this->buffer[2])); + $this->assertSame('baz', $this->buffer['bar']); + $this->assertSame('bam', $this->buffer[2]); + } + + /** + * @expectedException \Symfony\Component\Intl\Exception\OutOfBoundsException + */ + public function testReadNonExistingFails() + { + $this->buffer['foo']; + } + + public function testQueryNonExisting() + { + $this->assertFalse(isset($this->buffer['foo'])); + } + + public function testUnsetNonExistingSucceeds() + { + unset($this->buffer['foo']); + + $this->assertFalse(isset($this->buffer['foo'])); + } + + /** + * @expectedException \Symfony\Component\Intl\Exception\OutOfBoundsException + */ + public function testReadOverwrittenFails() + { + $this->buffer[0] = 'foo'; + $this->buffer['bar'] = 'baz'; + $this->buffer[2] = 'bam'; + + $this->buffer[0]; + } + + public function testQueryOverwritten() + { + $this->assertFalse(isset($this->buffer[0])); + } + + public function testUnsetOverwrittenSucceeds() + { + $this->buffer[0] = 'foo'; + $this->buffer['bar'] = 'baz'; + $this->buffer[2] = 'bam'; + + unset($this->buffer[0]); + + $this->assertFalse(isset($this->buffer[0])); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.php new file mode 100644 index 00000000..1ded57a7 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return array( + 'Entry1' => array( + 'Array' => array( + 0 => 'foo', + 1 => 'bar', + ), + 'Integer' => 5, + 'Boolean' => false, + 'Float' => 1.23, + ), + 'Entry2' => 'String', +); diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.res b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.res new file mode 100644 index 00000000..7c1f71eb Binary files /dev/null and b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.res differ diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.txt b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.txt new file mode 100644 index 00000000..0ee0d7f2 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/Fixtures/en.txt @@ -0,0 +1,23 @@ +en{ + Entry1{ + Array{ + "foo", + "bar", + { + Key{"value"} + }, + } + Integer:int{5} + IntVector:intvector{ + 0, + 1, + 2, + 3, + } + FalseBoolean{"false"} + TrueBoolean{"true"} + Null{""} + Float{"1.23"} + } + Entry2{"String"} +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/PhpBundleWriterTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/PhpBundleWriterTest.php new file mode 100644 index 00000000..03302834 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/PhpBundleWriterTest.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle\Writer; + +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Intl\ResourceBundle\Writer\PhpBundleWriter; + +/** + * @author Bernhard Schussek + */ +class PhpBundleWriterTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var PhpBundleWriter + */ + private $writer; + + private $directory; + + /** + * @var Filesystem + */ + private $filesystem; + + protected function setUp() + { + $this->writer = new PhpBundleWriter(); + $this->directory = sys_get_temp_dir() . '/PhpBundleWriterTest/' . rand(1000, 9999); + $this->filesystem = new Filesystem(); + + $this->filesystem->mkdir($this->directory); + } + + protected function tearDown() + { + $this->filesystem->remove($this->directory); + } + + public function testWrite() + { + $this->writer->write($this->directory, 'en', array( + 'Entry1' => array( + 'Array' => array('foo', 'bar'), + 'Integer' => 5, + 'Boolean' => false, + 'Float' => 1.23, + ), + 'Entry2' => 'String', + )); + + $this->assertFileEquals(__DIR__ . '/Fixtures/en.php', $this->directory . '/en.php'); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/TextBundleWriterTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/TextBundleWriterTest.php new file mode 100644 index 00000000..cbe0c8d8 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/Writer/TextBundleWriterTest.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests\ResourceBundle\Writer; + +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Intl\ResourceBundle\Writer\TextBundleWriter; + +/** + * @author Bernhard Schussek + * + * @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt + */ +class TextBundleWriterTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var TextBundleWriter + */ + private $writer; + + private $directory; + + /** + * @var Filesystem + */ + private $filesystem; + + protected function setUp() + { + $this->writer = new TextBundleWriter(); + $this->directory = sys_get_temp_dir() . '/TextBundleWriterTest/' . rand(1000, 9999); + $this->filesystem = new Filesystem(); + + $this->filesystem->mkdir($this->directory); + } + + protected function tearDown() + { + $this->filesystem->remove($this->directory); + } + + public function testWrite() + { + $this->writer->write($this->directory, 'en', array( + 'Entry1' => array( + 'Array' => array('foo', 'bar', array('Key' => 'value')), + 'Integer' => 5, + 'IntVector' => array(0, 1, 2, 3), + 'FalseBoolean' => false, + 'TrueBoolean' => true, + 'Null' => null, + 'Float' => 1.23, + ), + 'Entry2' => 'String', + )); + + $this->assertFileEquals(__DIR__ . '/Fixtures/en.txt', $this->directory . '/en.txt'); + } +} -- cgit v1.2.3