8000 merged branch willdurand/form-date-types (PR #4204) · symfony/symfony@46ffbd5 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 46ffbd5

Browse files
committed
merged branch willdurand/form-date-types (PR #4204)
Commits ------- ceb5ce6 [Form] fixed tests a1e3a59 [TwigBridge] Switched to composer df36afb [Form] Added tests 6d5ad3b [Form] Added right HTML types to Datetime/Date/Time types if single_text is true Discussion ---------- [Form] Added right HTML types to Datetime/Date/Time types if single_text is true When you set the `widget` option to `single_text`, you get a HTML input tag which is fine, but you the type is `text`, and it's wrong. You don't have any other way to get the right `type` as this attribute is defined to the FormView instance itself (see FileType for instance). This PR adds right HTML types like the FileType does. Cheers, William --------------------------------------------------------------------------- by willdurand at 2012-05-09T16:04:16Z @fabpot anything else to do there? --------------------------------------------------------------------------- by fabpot at 2012-05-11T16:28:43Z adding some unit tests? --------------------------------------------------------------------------- by willdurand at 2012-05-11T16:35:40Z fair point :) --------------------------------------------------------------------------- by travisbot at 2012-05-12T16:34:43Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1314731) (merged 2631c8b7 into cb905c5). --------------------------------------------------------------------------- by travisbot at 2012-05-12T17:14:12Z This pull request [passe 10000 s](http://travis-ci.org/symfony/symfony/builds/1314902) (merged ceb5ce6 into e193452). --------------------------------------------------------------------------- by willdurand at 2012-05-12T17:16:17Z @fabpot ok, so I had to fix some other tests but there is a weird dependency between the tests in TwigBridge, and the Form component. I fixed the test suite's setup in the TwigBridge, and fixed some failing tests.
2 parents 6fba6d7 + ceb5ce6 commit 46ffbd5

File tree

13 files changed

+68
-48
lines changed

13 files changed

+68
-48
lines changed

src/Symfony/Bridge/Twig/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
composer.lock

src/Symfony/Bridge/Twig/README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ Symfony2 components.
77
Resources
88
---------
99

10-
You can run the unit tests with the following command:
10+
If you want to run the unit tests, install dev dependencies before
11+
running PHPUnit:
1112

12-
phpunit -c src/Symfony/Bridge/Twig/
13+
php composer.phar install --dev
1314

14-
If you also want to run the unit tests that depend on other Symfony
15-
Components, declare the following environment variables before running
16-
PHPUnit:
17-
18-
export TWIG=../path/to/Twig
19-
export SYMFONY_EVENT_DISPATCHER=../path/to/EventDispatcher
20-
export SYMFONY_FORM=../path/to/Form
21-
export SYMFONY_LOCALE=../path/to/Locale
22-
export SYMFONY_TEMPLATING=../path/to/Templating
23-
export SYMFONY_TRANSLATION=../path/to/Translation
15+
phpunit

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Symfony\Bridge\Twig\Tests\Extension;
1313

14-
use Symfony\Component\Form\FormView;
1514
use Symfony\Bridge\Twig\Extension\FormExtension;
1615
use Symfony\Bridge\Twig\Extension\TranslationExtension;
17-
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
1816
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
1917
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
18+
use Symfony\Component\Form\FormView;
19+
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
2020

2121
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
2222
{

src/Symfony/Bridge/Twig/Tests/bootstrap.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
spl_autoload_register(function ($class) {
13-
foreach (array(
14-
'SYMFONY_EVENT_DISPATCHER' => 'EventDispatcher',
15-
'SYMFONY_FORM' => 'Form',
16-
'SYMFONY_LOCALE' => 'Locale',
17-
'SYMFONY_TEMPLATING' => 'Templating',
18-
'SYMFONY_TRANSLATION' => 'Translation',
19-
) as $env => $name) {
20-
if (isset($_SERVER[$env]) && 0 === strpos(ltrim($class, '/'), 'Symfony\Component\\'.$name)) {
21-
if (file_exists($file = $_SERVER[$env].'/'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\\'.$name)).'.php')) {
22-
require_once $file;
23-
}
24-
}
25-
}
26-
27-
if (isset($_SERVER['TWIG']) && 0 === strpos(ltrim($class, '/'), 'Twig_')) {
28-
if (file_exists($file = $_SERVER['TWIG'].'/lib/'.str_replace('_', '/', $class).'.php')) {
29-
require_once $file;
30-
}
31-
}
32-
33-
if (0 === strpos(ltrim($class, '/'), 'Symfony\Bridge\Twig')) {
34-
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Bridge\Twig')).'.php')) {
35-
require_once $file;
36-
}
37-
}
38-
});
12+
if (file_exists($loader = __DIR__.'/../vendor/autoload.php')) {
13+
require_once $loader;
14+
}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
"php": ">=5.3.3",
2020
"twig/twig": ">=1.8,<2.0-dev"
2121
},
22+
"require-dev": {
23+
"symfony/form": "2.1.*",
24+
"symfony/routing": "2.1.*",
25+
"symfony/templating": "2.1.*",
26+
"symfony/translation": "2.1.*",
27+
"symfony/yaml": "2.1.*"
28+
},
2229
"suggest": {
2330
"symfony/form": "self.version",
2431
"symfony/routing": "self.version",

src/Symfony/Bridge/Twig/phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
processIsolation="false"
1010
stopOnFailure="false"
1111
syntaxCheck="false"
12-
bootstrap="tests/bootstrap.php"
12+
bootstrap="Tests/bootstrap.php"
1313
>
1414
<testsuites>
1515
<testsuite name="Symfony Twig Bridge Test Suite">
@@ -23,6 +23,7 @@
2323
<exclude>
2424
<directory>./Resources</directory>
2525
<directory>./Tests</directory>
26+
<directory>./vendor</directory>
2627
</exclude>
2728
</whitelist>
2829
</filter>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ public function buildForm(FormBuilder $builder, array $options)
124124
public function buildView(FormView $view, FormInterface $form)
125125
{
126126
$view->set('widget', $form->getAttribute('widget'));
127+
128+
if ('single_text' === $form->getAttribute('widget')) {
129+
$view->set('type', 'datetime');
130+
}
127131
}
128132

129133
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public function buildViewBottomUp(FormView $view, FormInterface $form)
142142
{
143143
$view->set('widget', $form->getAttribute('widget'));
144144

145+
if ('single_text' === $form->getAttribute('widget')) {
146+
$view->set('type', 'date');
147+
}
148+
145149
if ($view->hasChildren()) {
146150
$pattern = $form->getAttribute('formatter')->getPattern();
147151

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public function buildView(FormView $view, FormInterface $form)
130130
->set('widget', $form->getAttribute('widget'))
131131
->set('with_seconds', $form->getAttribute('with_seconds'))
132132
;
133+
134+
if ('single_text' === $form->getAttribute('widget')) {
135+
$view->set('type', 'time');
136+
}
133137
}
134138

135139
/**

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,12 +947,12 @@ public function testDateTimeSingleText()
947947
'/div
948948
[
949949
./input
950-
[@type="text"]
950+
[@type="date"]
951951
[@id="name_date"]
952952
[@name="name[date]"]
953953
[@value="Feb 3, 2011"]
954954
/following-sibling::input
955-
[@type="text"]
955+
[@type="time"]
956956
[@id="name_time"]
957957
[@name="name[time]"]
958958
[@value="04:05"]
@@ -970,7 +970,7 @@ public function testDateTimeWithWidgetSingleText()
970970

971971
$this->assertWidgetMatchesXpath($form->createView(), array(),
972972
'/input
973-
[@type="text"]
973+
[@type="datetime"]
974974
[@name="name"]
975975
[@value="2011-02-03 04:05"]
976976
'
@@ -988,7 +988,7 @@ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
988988

989989
$this->assertWidgetMatchesXpath($form->createView(), array(),
990990
'/input
991-
[@type="text"]
991+
[@type="datetime"]
992992
[@name="name"]
993993
[@value="2011-02-03 04:05"]
994994
'
@@ -1111,7 +1111,7 @@ public function testDateSingleText()
11111111

11121112
$this->assertWidgetMatchesXpath($form->createView(), array(),
11131113
'/input
1114-
[@type="text"]
1114+
[@type="date"]
11151115
[@name="name"]
11161116
[@value="Feb 3, 2011"]
11171117
'
@@ -1586,7 +1586,7 @@ public function testTimeSingleText()
15861586

15871587
$this->assertWidgetMatchesXpath($form->createView(), array(),
15881588
'/input
1589-
[@type="text"]
1589+
[@type="time"]
15901590
[@name="name"]
15911591
[@value="04:05"]
15921592
'

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,14 @@ public function testInitializeWithDateTime()
259259
// to null in the type
260260
$this->factory->create('datetime', new \DateTime());
261261
}
262+
263+
public function testSingleTextWidgetShouldUseTheRightInputType()
264+
{
265+
$form = $this->factory->create('datetime', null, array(
266+
'widget' => 'single_text',
267+
));
268+
269+
$view = $form->createView();
270+
$this->assertEquals('datetime', $view->get('type'));
271+
}
262272
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,14 @@ public function testInitializeWithDateTime()
536536
// to null in the type
537537
$this->factory->create('date', new \DateTime());
538538
}
539+
540+
public function testSingleTextWidgetShouldUseTheRightInputType()
541+
{
542+
$form = $this->factory->create('date', null, array(
543+
'widget' => 'single_text',
544+
));
545+
546+
$view = $form->createView();
547+
$this->assertEquals('date', $view->get('type'));
548+
}
539549
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,14 @@ public function testInitializeWithDateTime()
406406
// to null in the type
407407
$this->factory->create('time', new \DateTime());
408408
}
409+
410+
public function testSingleTextWidgetShouldUseTheRightInputType()
411+
{
412+
$form = $this->factory->create('time', null, array(
413+
'widget' => 'single_text',
414+
));
415+
416+
$view = $form->createView();
417+
$this->assertEquals('time', $view->get('type'));
418+
}
409419
}

0 commit comments

Comments
 (0)
0