1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-05 18:41:02 +00:00

twig implementation

This commit is contained in:
Nicolas Lœuillet 2013-08-03 19:26:54 +02:00
parent 2b840e0cfb
commit 4f5b44bd3b
1418 changed files with 108207 additions and 1586 deletions

View file

@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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());
}
}

View file

@ -0,0 +1,98 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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'));
}
}

View file

@ -0,0 +1,197 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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'));
}
}

View file

@ -0,0 +1,64 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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'));
}
}

View file

@ -0,0 +1,64 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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));
}
}

View file

@ -0,0 +1,58 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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');
}
}

View file

@ -0,0 +1,14 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return array(
'Foo' => 'Bar',
);

View file

@ -0,0 +1,3 @@
en{
Foo{"Bar"}
}

View file

@ -0,0 +1,63 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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');
}
}

View file

@ -0,0 +1,223 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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));
}
}

View file

@ -0,0 +1,63 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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'));
}
}

View file

@ -0,0 +1,101 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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]));
}
}

View file

@ -0,0 +1,23 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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',
);

View file

@ -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"}
}

View file

@ -0,0 +1,62 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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');
}
}

View file

@ -0,0 +1,67 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*
* @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');
}
}