Fixed trash on Form tests
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Form
|
||||
* @since 2010-04-25
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-07
|
||||
*
|
||||
* Unit tests for Form class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../view/iView.php';
|
||||
@ -19,53 +19,79 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
Session::start();
|
||||
$phpview = new PHPView(array('path' => 'document_root'));
|
||||
$this->form = new FormViewHelper($phpview);
|
||||
$_SESSION['path'] = array(
|
||||
'values'=>array(
|
||||
'path'=>'path'
|
||||
),
|
||||
'messages'=>array(
|
||||
'path'=>'path'
|
||||
)
|
||||
);
|
||||
$this->view = new PHPView(array('path' => '/path/to/templates'));
|
||||
$this->formname = 'formname';
|
||||
$this->test_array = array('values' => array('key1' => 'val"ue1'), 'messages' => array('field1' => 'Can\'t serialize "value"'));
|
||||
Session::set($this->formname, $this->test_array);
|
||||
}
|
||||
|
||||
public function testForm2()
|
||||
|
||||
public function testFormWithNotViewInstance()
|
||||
{
|
||||
$this->assertNull($this->assertAttributeEquals(null, 'data', $this->form));
|
||||
$this->setExpectedException('Exception');
|
||||
$this->form->form(null);
|
||||
// @TODO check, that iView used in construct
|
||||
$form = new FormViewHelper('something');
|
||||
$this->assertInstanceOf('FormViewHelper', $form);
|
||||
}
|
||||
|
||||
public function testForm1()
|
||||
|
||||
public function testFormUnsetFormName()
|
||||
{
|
||||
$this->assertNull($this->assertAttributeEquals(null, 'data', $this->form)); //аналог getProp
|
||||
$this->form->form('path');
|
||||
$helper = new FormViewHelper($this->view);
|
||||
$this->setExpectedException('Exception', 'Form name required for helper init');
|
||||
// @TODO Refactor for form name is required param?
|
||||
$helper->form();
|
||||
}
|
||||
|
||||
public function testValueIsset()
|
||||
|
||||
public function testFormEmptyFormName()
|
||||
{
|
||||
$this->form->form('path');
|
||||
$this->assertEquals(htmlentities('path', ENT_QUOTES, 'UTF-8'), $this->form->value('path'));
|
||||
$helper = new FormViewHelper($this->view);
|
||||
$this->setExpectedException('Exception', 'Form name required for helper init');
|
||||
$helper->form('');
|
||||
}
|
||||
|
||||
public function testValueNotIsset()
|
||||
|
||||
public function testFillData()
|
||||
{
|
||||
$this->form->form('path');
|
||||
$this->assertEquals(htmlentities('param2', ENT_QUOTES, 'UTF-8'), $this->form->value('param1','param2'));
|
||||
$helper = new FormViewHelper($this->view);
|
||||
|
||||
$this->assertAttributeSame(null, 'data', $helper);
|
||||
$return_obj = $helper->form($this->formname);
|
||||
$this->assertAttributeSame($this->test_array, 'data', $helper);
|
||||
$this->assertNull(Session::get($this->formname));
|
||||
$this->assertSame($helper, $return_obj);
|
||||
}
|
||||
|
||||
public function testMessageIsset()
|
||||
|
||||
public function testValueSet()
|
||||
{
|
||||
$this->form->form('path');
|
||||
$this->assertEquals('<span class="error">' . htmlentities('path', ENT_QUOTES, 'UTF-8') . '</span>', $this->form->message('path'));
|
||||
$helper = new FormViewHelper($this->view);
|
||||
$helper->form($this->formname);
|
||||
|
||||
$value = $helper->value('key1');
|
||||
$this->assertSame($this->view->escape('val"ue1'), $value);
|
||||
}
|
||||
|
||||
public function testMessageNotIsset()
|
||||
|
||||
public function testValueDefault()
|
||||
{
|
||||
$this->form->form('path');
|
||||
$this->assertEmpty($this->form->message(''));
|
||||
$helper = new FormViewHelper($this->view);
|
||||
$helper->form($this->formname);
|
||||
|
||||
$value = $helper->value('key_not_exist', 'default"');
|
||||
$this->assertSame($this->view->escape('default"'), $value);
|
||||
}
|
||||
|
||||
public function testMessageSet()
|
||||
{
|
||||
$helper = new FormViewHelper($this->view);
|
||||
$helper->form($this->formname);
|
||||
|
||||
$value = $helper->message('field1');
|
||||
$this->assertSame('<span class="error">' . $this->view->escape('Can\'t serialize "value"') . '</span>', $value);
|
||||
}
|
||||
|
||||
public function testMessageNotSet()
|
||||
{
|
||||
|
||||
$helper = new FormViewHelper($this->view);
|
||||
$helper->form($this->formname);
|
||||
|
||||
$value = $helper->message('key_not_exist', 'default"');
|
||||
$this->assertSame('', $value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user