8000 merged 2.0 · fh-github/symfony@a8faa83 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8faa83

Browse files
committed
merged 2.0
2 parents 36f619b + d2d849c commit a8faa83

File tree

16 files changed

+131
-12
lines changed

16 files changed

+131
-12
lines changed

src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class_exists('Doctrine\ORM\Mapping\Driver\AnnotationDriver');
4949
$className = substr($class, strlen($namespace) +1);
5050
$file = $dir.DIRECTORY_SEPARATOR.$className.'.php';
5151

52-
if (!is_file($file) && $this->container->getParameter('kernel.debug')) {
52+
if (!is_file($file) && $container->getParameter('kernel.debug')) {
5353
$originalClassName = substr($className, 0, -5);
5454
$registry = $container->get('doctrine');
5555

src/Symfony/Component/Form/Extension/Core/DataTransformer/ScalarToChoiceTransformer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@
1313

1414
use Symfony\Component\Form\Util\FormUtil;
1515
use Symfony\Component\Form\DataTransformerInterface;
16+
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1617

1718
class ScalarToChoiceTransformer implements DataTransformerInterface
1819
{
1920
public function transform($value)
2021
{
22+
if (null !== $value && !is_scalar($value)) {
23+
throw new UnexpectedTypeException($value, 'scalar');
24+
}
25+
2126
return FormUtil::toArrayKey($value);
2227
}
2328

2429
public function reverseTransform($value)
2530
{
31+
if (null !== $value && !is_scalar($value)) {
32+
throw new UnexpectedTypeException($value, 'scalar');
33+
}
34+
2635
return $value;
2736
}
2837
}

src/Symfony/Component/Form/Extension/Core/Type/EmailType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EmailType extends AbstractType
2020
*/
2121
public function getParent(array $options)
2222
{
23-
return 'field';
23+
return 'text';
2424
}
2525

2626
/**

src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TextareaType extends AbstractType
2020
*/
2121
public function getParent(array $options)
2222
{
23-
return 'field';
23+
return 'text';
2424
}
2525

2626
/**

src/Symfony/Component/Form/Util/FormUtil.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ abstract class FormUtil
1515
{
1616
static public function toArrayKey($value)
1717
{
18-
if ((string) (int) $value === (string) $value) {
19-
return (int) $value;
20-
}
21-
22-
if (is_bool($value)) {
18+
if (is_bool($value) || (string) (int) $value === (string) $value) {
2319
return (int) $value;
2420
}
2521

@@ -52,7 +48,7 @@ static public function isChoiceGroup($choice)
5248
*/
5349
static public function isChoiceSelected($choice, $value)
5450
{
55-
$choice = FormUtil::toArrayKey($choice);
51+
$choice = static::toArrayKey($choice);
5652

5753
// The value should already have been converted by value transformers,
5854
// otherwise we had to do the conversion on every call of this method

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ protected function prepareRequestUri()
11211121
{
11221122
$requestUri = '';
11231123

1124-
if ($this->headers->has('X_REWRITE_URL')) {
1124+
if ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
11251125
// check this first so IIS will catch
11261126
$requestUri = $this->headers->get('X_REWRITE_URL');
11271127
} elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {

src/Symfony/Component/Translation/Loader/CsvFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function load($resource, $locale, $domain = 'messages')
3535
{
3636
$messages = array();
3737

38+
if (!stream_is_local($resource)) {
39+
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
40+
}
41+
3842
try {
3943
$file = new \SplFileObject($resource, 'rb');
4044
} catch(\RuntimeException $e) {

src/Symfony/Component/Translation/Loader/PhpFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class PhpFileLoader extends ArrayLoader implements LoaderInterface
2929
*/
3030
public function load($resource, $locale, $domain = 'messages')
3131
{
32+
if (!stream_is_local($resource)) {
33+
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
34+
}
35+
3236
$messages = require($resource);
3337

3438
$catalogue = parent::load($messages, $locale, $domain);

src/Symfony/Component/Translation/Loader/XliffFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class XliffFileLoader implements LoaderInterface
3030
*/
3131
public function load($resource, $locale, $domain = 'messages')
3232
{
33+
if (!stream_is_local($resource)) {
34+
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
35+
}
36+
3337
$xml = $this->parseFile($resource);
3438
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
3539

tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/ScalarToChoiceTransformerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,20 @@ public function testReverseTransform($in, $out)
6262
{
6363
$this->assertSame($out, $this->transformer->transform($in));
6464
}
65+
66+
/**
67+
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
68+
*/
69+
public function testTransformExpectsScalar()
70+
{
71+
$this->transformer->transform(array());
72+
}
73+
74+
/**
75+
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
76+
*/
77+
public function testReverseTransformExpectsScalar()
78+
{
79+
$this->transformer->reverseTransform(array());
80+
}
6581
}

tests/Symfony/Tests/Component/Form/Util/FormUtilTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,56 @@ public function testToArrayKeys()
5050

5151
$this->assertSame($out, FormUtil::toArrayKeys($in));
5252
}
53+
54+
public function isChoiceGroupProvider()
55+
{
56+
return array(
57+
array(false, 0),
58+
array(false, '0'),
59+
array(false, '1'),
60+
array(false, 1),
61+
array(false, ''),
62+
array(false, null),
63+
array(false, true),
64+
65+
array(true, array()),
66+
array(true, new \SplFixedArray(1)),
67+
);
68+
}
69+
70+
/**
71+
* @dataProvider isChoiceGroupProvider
72+
*/
73+
public function testIsChoiceGroup($expected, $value)
74+
{
75+
$this->assertSame($expected, FormUtil::isChoiceGroup($value));
76+
}
77+
78+
public function isChoiceSelectedProvider()
79+
{
80+
return array(
81+
array(true, 0, 0),
82+
array(true, '0', 0),
83+
array(true, '1', 1),
84+
array(true, false, 0),
85+
array(true, true, 1),
86+
array(true, '', ''),
87+
array(true, null, ''),
88+
array(true, '1.23', '1.23'),
89+
array(true, 'foo', 'foo'),
90+
array(true, 'foo10', 'foo10'),
91+
array(true, 'foo', array(1, 'foo', 'foo10')),
92+
93+
array(false, 10, array(1, 'foo', 'foo10')),
94+
array(false, 0, array(1, 'foo', 'foo10')),
95+
);
96+
}
97+
98+
/**
99+
* @dataProvider isChoiceSelectedProvider
100+
*/
101+
public function testIsChoiceSelected($expected, $choice, $value)
102+
{
103+
$this->assertSame($expected, FormUtil::isChoiceSelected($choice, $value));
104+
}
53105
}

tests/Symfony/Tests/Component/Translation/Loader/CsvFileLoaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,14 @@ public function testLoadThrowsAnExceptionIfFileNotExists()
4747
$resource = __DIR__.'/../fixtures/not-exists.csv';
4848
$loader->load($resource, 'en', 'domain1');
4949
}
50+
51+
/**
52+
* @expectedException \InvalidArgumentException
53+
*/
54+
public function testLoadThrowsAnExceptionIfFileNotLocal()
55+
{
56+
$loader = new CsvFileLoader();
57+
$resource = 'http://example.com/resources.csv';
58+
$loader->load($resource, 'en', 'domain1');
59+
}
5060
}

tests/Symfony/Tests/Component/Translation/Loader/PhpFileLoaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,14 @@ public function testLoad()
2626
$this->assertEquals('en', $catalogue->getLocale());
2727
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
2828
}
29+
30+
/**
31+
* @expectedException \InvalidArgumentException
32+
*/
33+
public function testLoadThrowsAnExceptionIfFileNotLocal()
34+
{
35+
$loader = new PhpFileLoader();
36+
$resource = 'http://example.com/resources.php';
37+
$loader->load($resource, 'en', 'domain1');
38+
}
2939
}

tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ public function testLoadResourceDoesNotValidate()
4444
$loader = new XliffFileLoader();
4545
$catalogue = $loader->load(__DIR__.'/../fixtures/non-valid.xliff', 'en', 'domain1');
4646
}
47+
48+
/**
49+
* @expectedException \InvalidArgumentException
50+
*/
51+
public function testLoadThrowsAnExceptionIfFileNotLocal()
52+
{
53+
$loader = new XliffFileLoader();
54+
$resource = 'http://example.com/resources.xliff';
55+
$loader->load($resource, 'en', 'domain1');
56+
}
4757
}

tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testEmptyStringIsValid()
4040

4141
public function testDateTimeClassIsValid()
4242
{
43-
$this->validator->isValid(new \DateTime(), new Date());
43+
$this->assertTrue($this->validator->isValid(new \DateTime(), new Date()));
4444
}
4545

4646
public function testExpectsStringCompatibleType()
@@ -79,6 +79,8 @@ public function getInvalidDates()
7979
{
8080
return array(
8181
array('foobar'),
82+
array('foobar 2010-13-01'),
83+
array('2010-13-01 foobar'),
8284
array('2010-13-01'),
8385
array('2010-04-32'),
8486
array('2010-02-29'),

tests/Symfony/Tests/Component/Validator/Constraints/TimeValidatorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testEmptyStringIsValid()
4040

4141
public function testDateTimeClassIsValid()
4242
{
43-
$this->validator->isValid(new \DateTime(), new Time());
43+
$this->assertTrue($this->validator->isValid(new \DateTime(), new Time()));
4444
}
4545

4646
public function testExpectsStringCompatibleType()
@@ -79,6 +79,8 @@ public function getInvalidTimes()
7979
{
8080
return array(
8181
array('foobar'),
82+
array('foobar 12:34:56'),
83+
array('12:34:56 foobar'),
8284
array('00:00'),
8385
array('24:00:00'),
8486
array('00:60:00'),

0 commit comments

Comments
 (0)
0