', 'UTF-8');
$this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addHtmlContent() adds nodes from an HTML string');
+
+ $crawler->addHtmlContent('
', 'UTF-8');
+
+ $this->assertEquals('http://symfony.com', $crawler->filter('base')->attr('href'), '->addHtmlContent() adds nodes from an HTML string');
+ $this->assertEquals('http://symfony.com/contact', $crawler->filter('a')->link()->getUri(), '->addHtmlContent() adds nodes from an HTML string');
}
/**
diff --git a/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php b/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php
index eef61fb90e..9abe423ac2 100644
--- a/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php
+++ b/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php
@@ -147,6 +147,7 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->dispatcher->hasListeners(self::preBar));
$this->dispatcher->removeListener(array('preBar'), $this->listener);
$this->assertFalse($this->dispatcher->hasListeners(self::preBar));
+ $this->dispatcher->removeListener(array('notExists'), $this->listener);
}
public function testAddSubscriber()
diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php
index 7ec762dce0..5ffc781721 100644
--- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php
+++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php
@@ -158,12 +158,18 @@ class StubNumberFormatterTest extends LocaleTestCase
array(-100, 'JPY', '(¥100)'),
array(1000.12, 'JPY', '¥1,000'),
+ array(100, 'EUR', '€100.00'),
+ array(-100, 'EUR', '(€100.00)'),
+ array(1000.12, 'EUR', '€1,000.12'),
+
// Rounding checks
array(1000.121, 'BRL', 'R$1,000.12'),
array(1000.123, 'BRL', 'R$1,000.12'),
array(1000.125, 'BRL', 'R$1,000.12'),
array(1000.127, 'BRL', 'R$1,000.13'),
array(1000.129, 'BRL', 'R$1,000.13'),
+ array(11.50999, 'BRL', 'R$11.51'),
+ array(11.9999464, 'BRL', 'R$12.00')
);
}
@@ -200,13 +206,19 @@ class StubNumberFormatterTest extends LocaleTestCase
array(100, 'CHF', $chf, '%s100.00'),
array(-100, 'CHF', $chf, '(%s100.00)'),
array(1000.12, 'CHF', $chf, '%s1,000.10'),
+ array('1000.12', 'CHF', $chf, '%s1,000.10'),
// Rounding checks
array(1000.121, 'CHF', $chf, '%s1,000.10'),
array(1000.123, 'CHF', $chf, '%s1,000.10'),
array(1000.125, 'CHF', $chf, '%s1,000.10'),
array(1000.127, 'CHF', $chf, '%s1,000.15'),
- array(1000.129, 'CHF', $chf, '%s1,000.15')
+ array(1000.129, 'CHF', $chf, '%s1,000.15'),
+
+ array(1200000.00, 'CHF', $chf, '%s1,200,000.00'),
+ array(1200000.1, 'CHF', $chf, '%s1,200,000.10'),
+ array(1200000.10, 'CHF', $chf, '%s1,200,000.10'),
+ array(1200000.101, 'CHF', $chf, '%s1,200,000.10')
);
}
@@ -356,6 +368,12 @@ class StubNumberFormatterTest extends LocaleTestCase
$formatter->format(1, StubNumberFormatter::TYPE_CURRENCY);
}
+ public function testFormatTypeCurrencyReturnStub()
+ {
+ $formatter = $this->getStubFormatterWithDecimalStyle();
+ $this->assertFalse(@$formatter->format(1, StubNumberFormatter::TYPE_CURRENCY));
+ }
+
/**
* @dataProvider formatTypeCurrencyProvider
* @expectedException PHPUnit_Framework_Error_Warning
diff --git a/tests/Symfony/Tests/Component/Serializer/Normalizer/CustomNormalizerTest.php b/tests/Symfony/Tests/Component/Serializer/Normalizer/CustomNormalizerTest.php
index a441544b4d..4a98954dcc 100644
--- a/tests/Symfony/Tests/Component/Serializer/Normalizer/CustomNormalizerTest.php
+++ b/tests/Symfony/Tests/Component/Serializer/Normalizer/CustomNormalizerTest.php
@@ -44,9 +44,15 @@ class CustomNormalizerTest extends \PHPUnit_Framework_TestCase
$this->assertNull($obj->xmlFoo);
}
- public function testSupports()
+ public function testSupportsNormalization()
{
- $this->assertTrue($this->normalizer->supports(new \ReflectionClass(get_class(new ScalarDummy))));
- $this->assertFalse($this->normalizer->supports(new \ReflectionClass('stdClass')));
+ $this->assertTrue($this->normalizer->supportsNormalization(new ScalarDummy));
+ $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass));
+ }
+
+ public function testSupportsDenormalization()
+ {
+ $this->assertTrue($this->normalizer->supportsDenormalization(array(), 'Symfony\Tests\Component\Serializer\Fixtures\ScalarDummy'));
+ $this->assertFalse($this->normalizer->supportsDenormalization(array(), 'stdClass'));
}
}
diff --git a/tests/Symfony/Tests/Component/Serializer/Normalizer/GetSetMethodNormalizerTest.php b/tests/Symfony/Tests/Component/Serializer/Normalizer/GetSetMethodNormalizerTest.php
index 6544075598..2ac0b1c024 100644
--- a/tests/Symfony/Tests/Component/Serializer/Normalizer/GetSetMethodNormalizerTest.php
+++ b/tests/Symfony/Tests/Component/Serializer/Normalizer/GetSetMethodNormalizerTest.php
@@ -29,7 +29,8 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
$obj->setBar('bar');
$this->assertEquals(
array('foo' => 'foo', 'bar' => 'bar', 'foobar' => 'foobar'),
- $this->normalizer->normalize($obj, 'any'));
+ $this->normalizer->normalize($obj, 'any')
+ );
}
public function testNormalizeRestricted()
@@ -39,14 +40,17 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
$obj->setBar('bar');
$this->assertEquals(
array('foo' => 'foo'),
- $this->normalizer->normalize($obj, 'any', array('foo')));
+ $this->normalizer->normalize($obj, 'any', array('foo'))
+ );
}
public function testDenormalize()
{
$obj = $this->normalizer->denormalize(
array('foo' => 'foo', 'bar' => 'bar', 'foobar' => 'foobar'),
- __NAMESPACE__.'\GetSetDummy', 'any');
+ __NAMESPACE__.'\GetSetDummy',
+ 'any'
+ );
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
}
diff --git a/tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php b/tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php
index 9eed61c318..e6724a87f7 100644
--- a/tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php
+++ b/tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php
@@ -37,4 +37,14 @@ class CsvFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('en', $catalogue->getLocale());
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
}
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testLoadThrowsAnExceptionIfFileNotExists()
+ {
+ $loader = new CsvFileLoader();
+ $resource = __DIR__.'/../fixtures/not-exists.csv';
+ $loader->load($resource, 'en', 'domain1');
+ }
}
diff --git a/tests/Symfony/Tests/Component/Translation/fixtures/resources.csv b/tests/Symfony/Tests/Component/Translation/fixtures/resources.csv
index b6467f0653..374b9eb5eb 100644
--- a/tests/Symfony/Tests/Component/Translation/fixtures/resources.csv
+++ b/tests/Symfony/Tests/Component/Translation/fixtures/resources.csv
@@ -1 +1,4 @@
-"foo"; "bar"
\ No newline at end of file
+"foo"; "bar"
+#"bar"; "foo"
+"incorrect"; "number"; "columns"; "will"; "be"; "ignored"
+"incorrect"
\ No newline at end of file
diff --git a/tests/Symfony/Tests/Component/Validator/ConstraintTest.php b/tests/Symfony/Tests/Component/Validator/ConstraintTest.php
index c49e6c2ff5..79ddf95ee5 100644
--- a/tests/Symfony/Tests/Component/Validator/ConstraintTest.php
+++ b/tests/Symfony/Tests/Component/Validator/ConstraintTest.php
@@ -78,6 +78,11 @@ class ConstraintTest extends \PHPUnit_Framework_TestCase
new ConstraintC();
}
+ public function testRequiredOptionsPassed()
+ {
+ new ConstraintC(array('option1' => 'default'));
+ }
+
public function testGroupsAreConvertedToArray()
{
$constraint = new ConstraintA(array('groups' => 'Foo'));
diff --git a/tests/Symfony/Tests/Component/Validator/ExecutionContextTest.php b/tests/Symfony/Tests/Component/Validator/ExecutionContextTest.php
new file mode 100644
index 0000000000..b2ab95660e
--- /dev/null
+++ b/tests/Symfony/Tests/Component/Validator/ExecutionContextTest.php
@@ -0,0 +1,102 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Validator;
+
+use Symfony\Component\Validator\ExecutionContext;
+
+class ExecutionContextTest extends \PHPUnit_Framework_TestCase
+{
+ protected $walker;
+ protected $metadataFactory;
+ protected $context;
+
+ protected function setUp()
+ {
+ $this->walker = $this->getMock('Symfony\Component\Validator\GraphWalker', array(), array(), '', false);
+ $this->metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
+ $this->context = new ExecutionContext('Root', $this->walker, $this->metadataFactory);
+ }
+
+ public function testClone()
+ {
+ $clone = clone $this->context;
+
+ $this->assertNotSame($this->context, $clone);
+ }
+
+ public function testAddViolation()
+ {
+ $this->assertEquals(0, count($this->context->getViolations()));
+ $this->context->addViolation('', array(), '');
+
+ $this->assertEquals(1, count($this->context->getViolations()));
+ }
+
+ public function testGetViolations()
+ {
+ $this->context->addViolation('', array(), '');
+
+ $this->assertEquals(1, count($this->context->getViolations()));
+ $this->assertInstanceOf('Symfony\Component\Validator\ConstraintViolationList', $this->context->getViolations());
+ }
+
+ public function testGetRoot()
+ {
+ $this->assertEquals('Root', $this->context->getRoot());
+ }
+
+ public function testSetGetPropertyPath()
+ {
+ $this->context->setPropertyPath('property_path');
+
+ $this->assertEquals('property_path', $this->context->getPropertyPath());
+ }
+
+ public function testSetGetCurrentClass()
+ {
+ $this->context->setCurrentClass('current_class');
+
+ $this->assertEquals('current_class', $this->context->getCurrentClass());
+ }
+
+ public function testSetGetCurrentProperty()
+ {
+ $this->context->setCurrentProperty('current_property');
+
+ $this->assertEquals('current_property', $this->context->getCurrentProperty());
+ }
+
+ public function testSetGetGroup()
+ {
+ $this->context->setGroup('group');
+
+ $this->assertEquals('group', $this->context->getGroup());
+ }
+
+ public function testGetGraphWalker()
+ {
+ $this->assertSame($this->walker, $this->context->getGraphWalker());
+ $this->assertInstanceOf(
+ 'Symfony\Component\Validator\GraphWalker',
+ $this->context->getGraphWalker()
+ );
+ }
+
+ public function testGetMetadataFactory()
+ {
+ $this->assertSame($this->metadataFactory, $this->context->getMetadataFactory());
+ $this->assertInstanceOf(
+ 'Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface',
+ $this->context->getMetadataFactory()
+ );
+ }
+}
\ No newline at end of file
diff --git a/tests/Symfony/Tests/Component/Validator/ValidatorTest.php b/tests/Symfony/Tests/Component/Validator/ValidatorTest.php
index d48f591f70..ca30cc9848 100644
--- a/tests/Symfony/Tests/Component/Validator/ValidatorTest.php
+++ b/tests/Symfony/Tests/Component/Validator/ValidatorTest.php
@@ -146,4 +146,12 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(1, count($result));
}
+
+ public function testGetMetadataFactory()
+ {
+ $this->assertInstanceOf(
+ 'Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface',
+ $this->validator->getMetadataFactory()
+ );
+ }
}
\ No newline at end of file