Przeglądaj źródła

Merge remote branch 'johnwards/renderer_tests' into renderer-tests-merge

Bernhard Schussek 14 lat temu
rodzic
commit
c01419d856

+ 12 - 0
src/Symfony/Component/Form/FormInterface.php

@@ -36,6 +36,18 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
 
     function hasChildren();
 
+    function hasParent();
+
+    function getErrors();
+
+    function getData();
+
+    function getClientData();
+
+    function getRenderer();
+
+    function isBound();
+    
     /**
      * Returns the name by which the form is identified in forms.
      *

+ 2 - 0
src/Symfony/Component/Form/Renderer/FormRendererInterface.php

@@ -22,5 +22,7 @@ interface FormRendererInterface
 
     function setVar($name, $value);
 
+    public function getVar($name);
+
     function addPlugin(FormRendererPluginInterface $plugin);
 }

+ 0 - 23
src/Symfony/Component/Form/Renderer/Plugin/EnctypePlugin.php

@@ -1,23 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license infieldation, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Form\Renderer\Plugin;
-
-use Symfony\Component\Form\FormInterface;
-use Symfony\Component\Form\Renderer\FormRendererInterface;
-
-class EnctypePlugin implements FormRendererPluginInterface
-{
-    public function setUp(FormInterface $field, FormRendererInterface $renderer)
-    {
-        $renderer->setVar('enctype', $field->isMultipart() ? 'enctype="multipart/form-data"' : '');
-    }
-}

+ 51 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/CheckedPluginTest.php

@@ -0,0 +1,51 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\CheckedPlugin;
+
+class CheckedPluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testSetUpTrue()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        $field->expects($this->once())
+              ->method('getData')
+              ->will($this->returnValue(1));
+        
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('checked'), $this->equalTo(true));
+
+        $plugin = new CheckedPlugin();
+        $plugin->setUp($field, $renderer);
+    }
+
+    public function testSetUpFalse()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        $field->expects($this->once())
+              ->method('getData')
+              ->will($this->returnValue(0));
+
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('checked'), $this->equalTo(false));
+
+        $plugin = new CheckedPlugin();
+        $plugin->setUp($field, $renderer);
+    }
+    
+}

+ 56 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/ChoicePluginTest.php

@@ -0,0 +1,56 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\ChoicePlugin;
+
+class ChoicePluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testSetUp()
+    {
+        $choice = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
+        $choice->expects($this->any())
+              ->method('getOtherChoices')
+              ->will($this->returnValue('somechoices'));
+        $choice->expects($this->any())
+              ->method('getPreferredChoices')
+              ->will($this->returnValue('somethingelse'));
+
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+
+        $renderer->expects($this->at(0))
+                ->method('setVar')
+                ->with($this->equalTo('choices'), $this->equalTo('somechoices'));
+
+        $renderer->expects($this->at(1))
+                ->method('setVar')
+                ->with($this->equalTo('preferred_choices'), $this->equalTo('somethingelse'));
+
+        $renderer->expects($this->at(2))
+                ->method('setVar')
+                ->with($this->equalTo('separator'), $this->equalTo('-------------------'));
+
+        $renderer->expects($this->at(3))
+                ->method('setVar')
+                ->with($this->equalTo('choice_list'), $this->equalTo($choice));
+
+        $renderer->expects($this->at(4))
+                ->method('setVar')
+                ->with($this->equalTo('empty_value'), $this->equalTo(''));
+
+        $plugin = new ChoicePlugin($choice);
+        $plugin->setUp($field, $renderer);
+    }
+}

+ 82 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/DatePatternPluginTest.php

@@ -0,0 +1,82 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\DatePatternPlugin;
+
+class DatePatternPluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testen_US()
+    {
+
+        $intl = new \IntlDateFormatter("en_US" ,\IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
+
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('date_pattern'), $this->equalTo('{{ month }}/{{ day }}/{{ year }}'));
+        $plugin = new DatePatternPlugin($intl);
+        $plugin->setUp($field, $renderer);
+    }
+
+    public function testen_GB()
+    {
+
+        $intl = new \IntlDateFormatter("en_GB" ,\IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
+
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('date_pattern'), $this->equalTo('{{ day }}/{{ month }}/{{ year }}'));
+        $plugin = new DatePatternPlugin($intl);
+        $plugin->setUp($field, $renderer);
+    }
+
+    public function testde_DE()
+    {
+
+        $intl = new \IntlDateFormatter("de_DE" ,\IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
+
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('date_pattern'), $this->equalTo('{{ day }}.{{ month }}.{{ year }}'));
+        $plugin = new DatePatternPlugin($intl);
+        $plugin->setUp($field, $renderer);
+    }
+
+    public function testDefault()
+    {
+
+        $intl = new \IntlDateFormatter("de_DE" ,\IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);
+
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('date_pattern'), $this->equalTo('{{ year }}-{{ month }}-{{ day }}'));
+        $plugin = new DatePatternPlugin($intl);
+        $plugin->setUp($field, $renderer);
+    }
+}

+ 98 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/FieldPluginTest.php

@@ -0,0 +1,98 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\FieldPlugin;
+
+class FieldPluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testSetUp()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        $field->expects($this->any())
+              ->method('getClientData')
+              ->will($this->returnValue('bar'));
+
+        $field->expects($this->any())
+              ->method('hasParent')
+              ->will($this->returnValue(false));
+
+        $field->expects($this->any())
+              ->method('getName')
+              ->will($this->returnValue('The_Name'));
+
+        $field->expects($this->any())
+              ->method('getErrors')
+              ->will($this->returnValue('someerrors'));
+
+        $field->expects($this->any())
+              ->method('isDisabled')
+              ->will($this->returnValue(false));
+
+        $field->expects($this->any())
+              ->method('isRequired')
+              ->will($this->returnValue(true));
+
+
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+
+        $renderer->expects($this->at(0))
+                ->method('setVar')
+                ->with($this->equalTo('renderer'), $this->equalTo($renderer));
+
+        $renderer->expects($this->at(1))
+                ->method('setVar')
+                ->with($this->equalTo('id'), $this->equalTo('The_Name'));
+
+        $renderer->expects($this->at(2))
+                ->method('setVar')
+                ->with($this->equalTo('name'), $this->equalTo('The_Name'));
+
+        $renderer->expects($this->at(3))
+                ->method('setVar')
+                ->with($this->equalTo('errors'), $this->equalTo('someerrors'));
+
+        $renderer->expects($this->at(4))
+                ->method('setVar')
+                ->with($this->equalTo('value'), $this->equalTo('bar'));
+
+        $renderer->expects($this->at(5))
+                ->method('setVar')
+                ->with($this->equalTo('disabled'), $this->equalTo(false));
+
+        $renderer->expects($this->at(6))
+                ->method('setVar')
+                ->with($this->equalTo('required'), $this->equalTo(true));
+
+        $renderer->expects($this->at(7))
+                ->method('setVar')
+                ->with($this->equalTo('class'), $this->equalTo(null));
+
+        $renderer->expects($this->at(8))
+                ->method('setVar')
+                ->with($this->equalTo('max_length'), $this->equalTo(null));
+
+        $renderer->expects($this->at(9))
+                ->method('setVar')
+                ->with($this->equalTo('size'), $this->equalTo(null));
+
+        $renderer->expects($this->at(10))
+                ->method('setVar')
+                ->with($this->equalTo('label'), $this->equalTo('The name'));
+        
+
+        $plugin = new FieldPlugin();
+        $plugin->setUp($field, $renderer);
+    }
+
+}

+ 38 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/FormPluginTest.php

@@ -0,0 +1,38 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\FormPlugin;
+
+class FormPluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testSetUp()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+
+        $renderer->expects($this->at(0))
+                ->method('setVar')
+                ->with($this->equalTo('fields'), $this->equalTo(array()));
+
+        $renderer->expects($this->at(1))
+                ->method('setVar')
+                ->with($this->equalTo('multipart'), $this->equalTo(false));
+        
+
+        $plugin = new FormPlugin();
+        $plugin->setUp($field, $renderer);
+    }
+
+}

+ 32 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/MaxLengthPluginTest.php

@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\MaxLengthPlugin;
+
+class MaxLengthPluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testSetUp()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('max_length'), $this->equalTo(12));
+
+        $plugin = new MaxLengthPlugin(12);
+        $plugin->setUp($field, $renderer);
+
+    }
+}

+ 32 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/MoneyPatternPluginTest.php

@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\MoneyPatternPlugin;
+
+class MoneyPatternPluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testSetUpEur()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('money_pattern'), $this->equalTo('€ {{ widget }}'));
+
+        $plugin = new MoneyPatternPlugin('EUR');
+        $plugin->setUp($field, $renderer);
+    }
+    
+}

+ 67 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/ParentNamePluginTest.php

@@ -0,0 +1,67 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\ParentNamePlugin;
+
+class ParentNamePluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testSetUpHasParent()
+    {
+        $parentRenderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $parentRenderer->expects($this->once())
+                ->method('getVar')
+                ->will($this->returnValue("parentName"));
+
+        $parentField = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        $parentField->expects($this->once())
+              ->method('getRenderer')
+              ->will($this->returnValue($parentRenderer));
+
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        $field->expects($this->once())
+              ->method('getParent')
+              ->will($this->returnValue($parentField));
+
+        $field->expects($this->once())
+              ->method('hasParent')
+              ->will($this->returnValue(true));
+
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('name'), $this->equalTo('parentName'));
+
+        $plugin = new ParentNamePlugin();
+        $plugin->setUp($field, $renderer);
+    }
+
+    public function testSetUpNoParent()
+    {
+        
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        $field->expects($this->never())
+              ->method('getParent');
+
+        $field->expects($this->once())
+              ->method('hasParent')
+              ->will($this->returnValue(false));
+
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->never())
+                ->method('setVar');
+
+        $plugin = new ParentNamePlugin();
+        $plugin->setUp($field, $renderer);
+    }
+}

+ 58 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/PasswordValuePluginTest.php

@@ -0,0 +1,58 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\PasswordValuePlugin;
+
+class PasswordValuePluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testIsSubmittedSetUp()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        $field->expects($this->any())
+              ->method('getClientData')
+              ->will($this->returnValue('pAs5w0rd'));
+
+        $field->expects($this->any())
+              ->method('isBound')
+              ->will($this->returnValue(true));
+
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('value'), $this->equalTo('pAs5w0rd'));
+
+        $plugin = new PasswordValuePlugin(false);
+        $plugin->setUp($field, $renderer);
+    }
+
+    public function testIsNotSubmittedSetUp()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        $field->expects($this->any())
+              ->method('getClientData')
+              ->will($this->returnValue('pAs5w0rd'));
+
+        $field->expects($this->any())
+              ->method('isBound')
+              ->will($this->returnValue(false));
+
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('value'), $this->equalTo(''));
+
+        $plugin = new PasswordValuePlugin(false);
+        $plugin->setUp($field, $renderer);
+    }
+}

+ 36 - 0
tests/Symfony/Tests/Component/Form/Renderer/Plugin/SelectMultipleNamePluginTest.php

@@ -0,0 +1,36 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Renderer\Plugin;
+
+use Symfony\Component\Form\Renderer\Plugin\SelectMultipleNamePlugin;
+
+class SelectMultipleNamePluginTest extends \PHPUnit_Framework_TestCase
+{
+
+    public function testSetUp()
+    {
+        $field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
+        
+        $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
+        $renderer->expects($this->once())
+                ->method('getVar')
+                ->with($this->equalTo('name'))
+                ->will($this->returnValue('multiname'));
+
+        $renderer->expects($this->once())
+                ->method('setVar')
+                ->with($this->equalTo('name'), $this->equalTo('multiname[]'));
+
+        $plugin = new SelectMultipleNamePlugin();
+        $plugin->setUp($field, $renderer);
+    }
+}