Add namespace.
This commit is contained in:
62
Tests/view/helpers/BreadcrumbVeiwHelperTest.php
Normal file
62
Tests/view/helpers/BreadcrumbVeiwHelperTest.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-11
|
||||
*
|
||||
* Unit tests for PHPView class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../Registry.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/ViewHelper.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/BreadcrumbViewHelper.php';
|
||||
|
||||
class BreadcrumbViewHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var BreadcrumbViewHelper
|
||||
*/
|
||||
public $helper;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Registry::set('BreadcrumbViewHelper', array());
|
||||
$this->helper = new BreadcrumbViewHelper(new PHPView('any'));
|
||||
}
|
||||
|
||||
public function testTitle()
|
||||
{
|
||||
$this->helper->breadcrumb('Guest page', 'guest.php');
|
||||
$result = Registry::get('BreadcrumbViewHelper');
|
||||
$this->assertSame(array('Guest page' => 'guest.php'), Registry::get('BreadcrumbViewHelper'));
|
||||
|
||||
$this->helper->prepend('Leave message', 'feedback.php');
|
||||
$this->assertSame(array('Leave message' => 'feedback.php', 'Guest page' => 'guest.php'), Registry::get('BreadcrumbViewHelper'));
|
||||
|
||||
$this->helper->append('Home page', 'home.php');
|
||||
$this->assertSame(array('Leave message' => 'feedback.php', 'Guest page' => 'guest.php', 'Home page' => 'home.php'), Registry::get('BreadcrumbViewHelper'));
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->helper->prepend('Home page', 'home.php');
|
||||
$this->helper->breadcrumb('Guest page', 'guest.php');
|
||||
$this->helper->append('Leave message', 'feedback.php');
|
||||
$this->assertSame(array('Home page' => 'home.php', 'Guest page' => 'guest.php', 'Leave message' => 'feedback.php'), Registry::get('BreadcrumbViewHelper'));
|
||||
|
||||
$result = $this->helper->__toString();
|
||||
$this->assertSame('<a href="home.php">Home page</a> > <a href="guest.php">Guest page</a> > <a href="feedback.php">Leave message</a>', $result);
|
||||
|
||||
$this->helper->setSeparator('-');
|
||||
$result = $this->helper->__toString();
|
||||
$this->assertSame('<a href="home.php">Home page</a>-<a href="guest.php">Guest page</a>-<a href="feedback.php">Leave message</a>', $result);
|
||||
|
||||
$this->helper->append('Last page', '');
|
||||
$result = $this->helper->__toString();
|
||||
$this->assertSame('<a href="home.php">Home page</a>-<a href="guest.php">Guest page</a>-<a href="feedback.php">Leave message</a>-Last page', $result);
|
||||
}
|
||||
}
|
83
Tests/view/helpers/GetViewHelperTest.php
Normal file
83
Tests/view/helpers/GetViewHelperTest.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-11
|
||||
*
|
||||
* Unit tests for PHPView class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../classes/Env.class.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/iView.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/PHPView.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/ViewHelper.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/GetViewHelper.php';
|
||||
|
||||
class GetViewHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var GetViewHelper
|
||||
*/
|
||||
public $helper;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->helper = new GetViewHelper(new PHPView('any'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO: GetViewHelper: initialize GetViewHelper::$get with empty array()
|
||||
*/
|
||||
public function testGetWithNull()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error');
|
||||
$this->helper->get(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO: GetViewHelper: check $_GET not null
|
||||
*/
|
||||
public function testGetEmptyGET()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error');
|
||||
$result = $this->helper->get('param');
|
||||
}
|
||||
|
||||
public function testGetWithSingleParam()
|
||||
{
|
||||
$_GET['a'] = 'b';
|
||||
$result = $this->helper->get(null);
|
||||
$this->assertSame('?a=b', $result);
|
||||
$this->helper = new GetViewHelper(new PHPView('any'));
|
||||
$_GET['a'] = 'b';
|
||||
$_GET['b'] = 'a';
|
||||
$result = $this->helper->get(array('a' => 'c'));
|
||||
$this->assertSame('?a=c&b=a', $result);
|
||||
$_GET['a'] = 'b';
|
||||
$_GET['b'] = 'a';
|
||||
$result = $this->helper->get(array('a'));
|
||||
$this->assertSame('?b=a', $result);
|
||||
}
|
||||
|
||||
public function testGetWithArray()
|
||||
{
|
||||
$_GET['a'] = array('one' => 1, 'two' => 2);
|
||||
$_GET['b'] = 'a';
|
||||
$_GET['c'] = array('three' => 'four');
|
||||
$result = $this->helper->get(array('b' => 'c', 'c' => array('five' => 'six')));
|
||||
$this->assertSame('?a[one]=1&a[two]=2&b=c&c[five]=six', $result);
|
||||
}
|
||||
|
||||
public function testGetUrlencode()
|
||||
{
|
||||
$_GET['a'] = array('one' => 1, 'two' => 2);
|
||||
$_GET['b'] = 'a';
|
||||
$_GET['c'] = array('three' => 'four');
|
||||
$result = $this->helper->get(array('b' => 'c d e', 'c' => array('five' => 'six seven')));
|
||||
$this->assertSame('?a[one]=1&a[two]=2&b=c+d+e&c[five]=six+seven', $result);
|
||||
}
|
||||
}
|
50
Tests/view/helpers/HeadViewHelperTest.php
Normal file
50
Tests/view/helpers/HeadViewHelperTest.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-11
|
||||
*
|
||||
* Unit tests for PHPView class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../Registry.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/ViewHelper.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/HeadViewHelper.php';
|
||||
|
||||
class HeadViewHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var HeadViewHelper
|
||||
*/
|
||||
public $helper;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Registry::set('HeadViewHelper', array());
|
||||
$this->helper = new HeadViewHelper(null);
|
||||
}
|
||||
|
||||
public function testHead()
|
||||
{
|
||||
$this->helper->head('<meta />');
|
||||
$result = Registry::get('HeadViewHelper');
|
||||
$this->assertSame(array('<meta />'), Registry::get('HeadViewHelper'));
|
||||
|
||||
$this->helper->head('<link />');
|
||||
$this->assertSame(array('<meta />', '<link />'), Registry::get('HeadViewHelper'));
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->helper->head('<meta />');
|
||||
$this->helper->head('<link />');
|
||||
|
||||
$result = $this->helper->__toString();
|
||||
|
||||
$this->assertSame("<meta />\n <link />\n", $result);
|
||||
}
|
||||
}
|
101
Tests/view/helpers/MsgViewHelperTest.php
Normal file
101
Tests/view/helpers/MsgViewHelperTest.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-11
|
||||
*
|
||||
* Unit tests for PHPView class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../session/Session.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/iView.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/PHPView.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/ViewHelper.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/MsgViewHelper.php';
|
||||
require_once dirname(__FILE__) . '/../../../exception/GeneralException.php';
|
||||
|
||||
class MsgViewHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var MsgViewHelper
|
||||
*/
|
||||
public $helper;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Session::del('MsgViewHelper');
|
||||
$this->helper = new MsgViewHelper(new PHPView(array('path' => 'any')));
|
||||
}
|
||||
|
||||
public function testMsg()
|
||||
{
|
||||
|
||||
$this->helper->msg('new message from test', 'success');
|
||||
$this->assertSame(array('message' => 'new message from test', 'type' => 'success'), Session::get('MsgViewHelper'));
|
||||
|
||||
$this->assertSame($this->helper, $this->helper->msg('error message', 'error'));
|
||||
$this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
|
||||
}
|
||||
|
||||
public function testWrongType()
|
||||
{
|
||||
$this->setExpectedException('GeneralException', 'Unknown message type');
|
||||
$this->helper->msg('some message', 'wrong');
|
||||
}
|
||||
|
||||
public function testSuccess()
|
||||
{
|
||||
$this->helper->success('success message');
|
||||
$this->assertSame(array('message' => 'success message', 'type' => 'success'), Session::get('MsgViewHelper'));
|
||||
}
|
||||
|
||||
public function testError()
|
||||
{
|
||||
$this->helper->error('error message');
|
||||
$this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
|
||||
$this->assertNull(Session::get('test'));
|
||||
}
|
||||
|
||||
public function testInfo()
|
||||
{
|
||||
$this->helper->info('info message');
|
||||
$this->assertSame(array('message' => 'info message', 'type' => 'info'), Session::get('MsgViewHelper'));
|
||||
$this->assertNull(Session::get('test'));
|
||||
}
|
||||
|
||||
public function testWarning()
|
||||
{
|
||||
$this->helper->warning('warning message');
|
||||
$this->assertSame(array('message' => 'warning message', 'type' => 'warning'), Session::get('MsgViewHelper'));
|
||||
$this->assertNull(Session::get('test'));
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->helper->success('yeah');
|
||||
$result = $this->helper->__toString();
|
||||
$this->assertSame('<div class="success">yeah</div>', $result);
|
||||
}
|
||||
|
||||
public function testToStringEmpty()
|
||||
{
|
||||
$result = $this->helper->__toString();
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testToStringWithPrefix()
|
||||
{
|
||||
$this->helper->success('yeah');
|
||||
$result = $this->helper->withPrefix('prefix')->__toString();
|
||||
$this->assertSame('<div class="prefixsuccess">yeah</div>', $result);
|
||||
}
|
||||
|
||||
public function testToStringEmptyWithPrefix()
|
||||
{
|
||||
$result = $this->helper->withPrefix('prefix')->__toString();
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
}
|
49
Tests/view/helpers/TitleViewHelperTest.php
Normal file
49
Tests/view/helpers/TitleViewHelperTest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-11
|
||||
*
|
||||
* Unit tests for PHPView class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../Registry.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/ViewHelper.php';
|
||||
require_once dirname(__FILE__) . '/../../../view/helpers/TitleViewHelper.php';
|
||||
|
||||
class TitleViewHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var TitleViewHelper
|
||||
*/
|
||||
public $helper;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Registry::set('TitleViewHelper', array());
|
||||
$this->helper = new TitleViewHelper('view');
|
||||
}
|
||||
|
||||
public function testTitle()
|
||||
{
|
||||
$this->helper->title('one');
|
||||
$result = Registry::get('TitleViewHelper');
|
||||
$this->assertSame(array('one'), Registry::get('TitleViewHelper'));
|
||||
|
||||
$this->helper->title('two');
|
||||
$this->assertSame(array('one', 'two'), Registry::get('TitleViewHelper'));
|
||||
}
|
||||
|
||||
public function testSeparator()
|
||||
{
|
||||
$this->helper->title('one');
|
||||
$this->helper->title('two');
|
||||
|
||||
$this->assertSame('one - two', $this->helper->__toString());
|
||||
$this->helper->setSeparator('=');
|
||||
$this->assertSame('one=two', $this->helper->__toString());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user