Skip to content

Commit

Permalink
[Form] Tests for Renderer Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwards committed Mar 22, 2011
1 parent ef8113c commit 1a014d1
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 169 deletions.
23 changes: 0 additions & 23 deletions src/Symfony/Component/Form/Renderer/Plugin/EnctypePlugin.php

This file was deleted.

Expand Up @@ -13,41 +13,39 @@

use Symfony\Component\Form\Renderer\Plugin\CheckedPlugin;

use Symfony\Component\Form\Renderer\DefaultRenderer;
use Symfony\Component\Form\FieldInterface;

class CheckedPluginTest extends \PHPUnit_Framework_TestCase
{

public function testSetUpTrue()
{
$field = $this->getMock('Symfony\Component\Form\FieldInterface');
$field->expects($this->any())
$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\RendererInterface');
$renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
$renderer->expects($this->once())
->method('setVar')
->with($this->equalTo('checked'), $this->equalTo(true));

$plugin = new CheckedPlugin($field);
$plugin->setUp($renderer);
$plugin = new CheckedPlugin();
$plugin->setUp($field, $renderer);
}

public function testSetUpFalse()
{
$field = $this->getMock('Symfony\Component\Form\FieldInterface');
$field->expects($this->any())
$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\RendererInterface');
$renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
$renderer->expects($this->once())
->method('setVar')
->with($this->equalTo('checked'), $this->equalTo(false));

$plugin = new CheckedPlugin($field);
$plugin->setUp($renderer);
$plugin = new CheckedPlugin();
$plugin->setUp($field, $renderer);
}

}
Expand Up @@ -13,24 +13,22 @@

use Symfony\Component\Form\Renderer\Plugin\ChoicePlugin;

use Symfony\Component\Form\Renderer\DefaultRenderer;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;

class ChoicePluginTest extends \PHPUnit_Framework_TestCase
{

public function testSetUp()
{
$field = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
$field->expects($this->any())
$choice = $this->getMock('Symfony\Component\Form\ChoiceList\ChoiceListInterface');
$choice->expects($this->any())
->method('getOtherChoices')
->will($this->returnValue('somechoices'));
$field->expects($this->any())
$choice->expects($this->any())
->method('getPreferredChoices')
->will($this->returnValue('somethingelse'));


$renderer = $this->getMock('Symfony\Component\Form\Renderer\RendererInterface');
$field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');

$renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');

$renderer->expects($this->at(0))
->method('setVar')
Expand All @@ -46,13 +44,13 @@ public function testSetUp()

$renderer->expects($this->at(3))
->method('setVar')
->with($this->equalTo('choice_list'), $this->equalTo($field));
->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($field);
$plugin->setUp($renderer);
$plugin = new ChoicePlugin($choice);
$plugin->setUp($field, $renderer);
}
}
Expand Up @@ -13,9 +13,6 @@

use Symfony\Component\Form\Renderer\Plugin\DatePatternPlugin;

use Symfony\Component\Form\Renderer\DefaultRenderer;
use Symfony\Component\Form\FieldInterface;

class DatePatternPluginTest extends \PHPUnit_Framework_TestCase
{

Expand All @@ -24,54 +21,62 @@ public function testen_US()

$intl = new \IntlDateFormatter("en_US" ,\IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);

$renderer = $this->getMock('Symfony\Component\Form\Renderer\RendererInterface');
$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($renderer);
$plugin->setUp($field, $renderer);
}

public function testen_GB()
{

$intl = new \IntlDateFormatter("en_GB" ,\IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);

$renderer = $this->getMock('Symfony\Component\Form\Renderer\RendererInterface');
$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($renderer);
$plugin->setUp($field, $renderer);
}

public function testde_DE()
{

$intl = new \IntlDateFormatter("de_DE" ,\IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);

$renderer = $this->getMock('Symfony\Component\Form\Renderer\RendererInterface');
$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($renderer);
$plugin->setUp($field, $renderer);
}

public function testDefault()
{

$intl = new \IntlDateFormatter("de_DE" ,\IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);

$renderer = $this->getMock('Symfony\Component\Form\Renderer\RendererInterface');
$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($renderer);
$plugin->setUp($field, $renderer);
}
}

This file was deleted.

Expand Up @@ -13,26 +13,23 @@

use Symfony\Component\Form\Renderer\Plugin\FieldPlugin;

use Symfony\Component\Form\Renderer\DefaultRenderer;
use Symfony\Component\Form\FieldInterface;

class FieldPluginTest extends \PHPUnit_Framework_TestCase
{

public function testSetUp()
{
$field = $this->getMock('Symfony\Component\Form\FieldInterface');
$field = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
$field->expects($this->any())
->method('getDisplayedData')
->method('getClientData')
->will($this->returnValue('bar'));

$field->expects($this->any())
->method('hasParent')
->will($this->returnValue(false));

$field->expects($this->any())
->method('getKey')
->will($this->returnValue('The_Key'));
->method('getName')
->will($this->returnValue('The_Name'));

$field->expects($this->any())
->method('getErrors')
Expand All @@ -47,19 +44,19 @@ public function testSetUp()
->will($this->returnValue(true));


$renderer = $this->getMock('Symfony\Component\Form\Renderer\RendererInterface');
$renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');

$renderer->expects($this->at(0))
->method('setVar')
->with($this->equalTo('this'), $this->equalTo($renderer));
->with($this->equalTo('renderer'), $this->equalTo($renderer));

$renderer->expects($this->at(1))
->method('setVar')
->with($this->equalTo('id'), $this->equalTo('The_Key'));
->with($this->equalTo('id'), $this->equalTo('The_Name'));

$renderer->expects($this->at(2))
->method('setVar')
->with($this->equalTo('name'), $this->equalTo('The_Key'));
->with($this->equalTo('name'), $this->equalTo('The_Name'));

$renderer->expects($this->at(3))
->method('setVar')
Expand Down Expand Up @@ -91,11 +88,11 @@ public function testSetUp()

$renderer->expects($this->at(10))
->method('setVar')
->with($this->equalTo('label'), $this->equalTo('The key'));
->with($this->equalTo('label'), $this->equalTo('The name'));


$plugin = new FieldPlugin($field);
$plugin->setUp($renderer);
$plugin = new FieldPlugin();
$plugin->setUp($field, $renderer);
}

}
@@ -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);
}

}

0 comments on commit 1a014d1

Please sign in to comment.