From 07a244ca35f63bcc0ecb12938e39626bb475df9a Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 21 Nov 2012 15:43:20 +0400 Subject: [PATCH] Code formatting for ViewHelper & tests --- tests/view/helpers/BreadcrumbVeiwHelperTest.php | 34 +++++++++++++------------ tests/view/helpers/GetViewHelperTest.php | 16 +++++++----- tests/view/helpers/HeadViewHelperTest.php | 25 ++++++++++-------- tests/view/helpers/MsgViewHelperTest.php | 23 ++++++++--------- tests/view/helpers/TitleViewHelperTest.php | 24 +++++++++-------- view/helpers/BreadcrumbViewHelper.php | 12 ++++----- view/helpers/GetViewHelper.php | 10 ++++---- view/helpers/HeadViewHelper.php | 4 +-- view/helpers/MsgViewHelper.php | 6 ++--- view/helpers/TitleViewHelper.php | 8 +++--- view/helpers/ViewHelper.php | 4 +-- 11 files changed, 87 insertions(+), 79 deletions(-) diff --git a/tests/view/helpers/BreadcrumbVeiwHelperTest.php b/tests/view/helpers/BreadcrumbVeiwHelperTest.php index db4351b..d490280 100644 --- a/tests/view/helpers/BreadcrumbVeiwHelperTest.php +++ b/tests/view/helpers/BreadcrumbVeiwHelperTest.php @@ -16,45 +16,47 @@ require_once dirname(__FILE__) . '/../../../view/helpers/BreadcrumbViewHelper.ph 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'); + $this->helper->breadcrumb('Guest page', 'guest.php'); $result = Registry::get('BreadcrumbViewHelper'); - $this->assertSame(array('Guest page' => 'guest.php'), 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->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')); + $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->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')); - + $this->assertSame(array('Home page' => 'home.php', 'Guest page' => 'guest.php', 'Leave message' => 'feedback.php'), Registry::get('BreadcrumbViewHelper')); + $result = $this->helper->__toString(); $this->assertSame('Home page > Guest page > Leave message', $result); - + $this->helper->setSeparator('-'); $result = $this->helper->__toString(); $this->assertSame('Home page-Guest page-Leave message', $result); - + $this->helper->append('Last page', ''); $result = $this->helper->__toString(); $this->assertSame('Home page-Guest page-Leave message-Last page', $result); - } } diff --git a/tests/view/helpers/GetViewHelperTest.php b/tests/view/helpers/GetViewHelperTest.php index dac3f28..5449c74 100644 --- a/tests/view/helpers/GetViewHelperTest.php +++ b/tests/view/helpers/GetViewHelperTest.php @@ -18,14 +18,17 @@ 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() */ @@ -34,7 +37,7 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase $this->setExpectedException('PHPUnit_Framework_Error'); $this->helper->get(null); } - + /** * @TODO: GetViewHelper: check $_GET not null */ @@ -43,7 +46,7 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase $this->setExpectedException('PHPUnit_Framework_Error'); $result = $this->helper->get('param'); } - + public function testGetWithSingleParam() { $_GET['a'] = 'b'; @@ -59,7 +62,7 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase $result = $this->helper->get(array('a')); $this->assertSame('?b=a', $result); } - + public function testGetWithArray() { $_GET['a'] = array('one' => 1, 'two' => 2); @@ -77,5 +80,4 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase $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); } - } diff --git a/tests/view/helpers/HeadViewHelperTest.php b/tests/view/helpers/HeadViewHelperTest.php index e75e52a..6887af9 100644 --- a/tests/view/helpers/HeadViewHelperTest.php +++ b/tests/view/helpers/HeadViewHelperTest.php @@ -16,32 +16,35 @@ 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(''); + $this->helper->head(''); $result = Registry::get('HeadViewHelper'); $this->assertSame(array(''), Registry::get('HeadViewHelper')); - - $this->helper->head(''); + + $this->helper->head(''); $this->assertSame(array('', ''), Registry::get('HeadViewHelper')); } - + public function testToString() { - $this->helper->head(''); - $this->helper->head(''); - + $this->helper->head(''); + $this->helper->head(''); + $result = $this->helper->__toString(); - + $this->assertSame("\n \n", $result); } } diff --git a/tests/view/helpers/MsgViewHelperTest.php b/tests/view/helpers/MsgViewHelperTest.php index 1c83619..d9405e9 100644 --- a/tests/view/helpers/MsgViewHelperTest.php +++ b/tests/view/helpers/MsgViewHelperTest.php @@ -19,25 +19,25 @@ 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->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')); - + $this->assertSame($this->helper, $this->helper->msg('error message', 'error')); + $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper')); } public function testWrongType() @@ -45,13 +45,13 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase $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'); @@ -65,11 +65,10 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase $result = $this->helper->__toString(); $this->assertSame('
yeah
', $result); } - + public function testToStringEmpty() { $result = $this->helper->__toString(); $this->assertEmpty($result); } - } diff --git a/tests/view/helpers/TitleViewHelperTest.php b/tests/view/helpers/TitleViewHelperTest.php index 4f040f3..03538c9 100644 --- a/tests/view/helpers/TitleViewHelperTest.php +++ b/tests/view/helpers/TitleViewHelperTest.php @@ -16,32 +16,34 @@ 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'); + $this->helper->title('one'); $result = Registry::get('TitleViewHelper'); $this->assertSame(array('one'), Registry::get('TitleViewHelper')); - - $this->helper->title('two'); + + $this->helper->title('two'); $this->assertSame(array('one', 'two'), Registry::get('TitleViewHelper')); } - + public function testSeparator() { - $this->helper->title('one'); - $this->helper->title('two'); - + $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()); + $this->assertSame('one=two', $this->helper->__toString()); } } diff --git a/view/helpers/BreadcrumbViewHelper.php b/view/helpers/BreadcrumbViewHelper.php index 04df5be..10f8122 100644 --- a/view/helpers/BreadcrumbViewHelper.php +++ b/view/helpers/BreadcrumbViewHelper.php @@ -11,9 +11,9 @@ class BreadcrumbViewHelper extends ViewHelper { - + protected $separator = ' > '; - + public function breadcrumb($text = false, $href = false) { if ($text) { @@ -21,22 +21,22 @@ class BreadcrumbViewHelper extends ViewHelper } return $this; } - + public function prepend($text, $href) { Registry::set(__CLASS__, array($text => $href) + Registry::get(__CLASS__, array())); } - + public function append($text, $href) { Registry::set(__CLASS__, Registry::get(__CLASS__, array()) + array($text => $href)); } - + public function setSeparator($sep) { $this->separator = $sep; } - + public function __toString() { $data = array(); diff --git a/view/helpers/GetViewHelper.php b/view/helpers/GetViewHelper.php index 78cb75a..d0d488b 100644 --- a/view/helpers/GetViewHelper.php +++ b/view/helpers/GetViewHelper.php @@ -11,9 +11,9 @@ class GetViewHelper extends ViewHelper { - + protected $get; - + public function get($replace) { $get = $this->getSanitizedRequest(); @@ -29,7 +29,7 @@ class GetViewHelper extends ViewHelper } return '?' . $this->view->escape(implode('&', $get)); } - + protected function getSanitizedRequest() { if ($this->get === null) { @@ -40,10 +40,10 @@ class GetViewHelper extends ViewHelper } return $this->get; } - + protected function impl($name, $value) { - if (is_array($value)){ + if (is_array($value)) { $result = array(); foreach ($value as $key => $val) { $result[] = $name . '[' . $key . ']=' . urlencode($val); diff --git a/view/helpers/HeadViewHelper.php b/view/helpers/HeadViewHelper.php index ffbb444..f797056 100644 --- a/view/helpers/HeadViewHelper.php +++ b/view/helpers/HeadViewHelper.php @@ -11,7 +11,7 @@ class HeadViewHelper extends ViewHelper { - + public function head($string = false) { if ($string) { @@ -21,7 +21,7 @@ class HeadViewHelper extends ViewHelper } return $this; } - + public function __toString() { return implode("\n ", Registry::get(__CLASS__, array())) . "\n"; diff --git a/view/helpers/MsgViewHelper.php b/view/helpers/MsgViewHelper.php index b548ff7..c45bdc4 100644 --- a/view/helpers/MsgViewHelper.php +++ b/view/helpers/MsgViewHelper.php @@ -11,7 +11,7 @@ class MsgViewHelper extends ViewHelper { - + const SUCCESS = 'success'; const ERROR = 'error'; @@ -27,12 +27,12 @@ class MsgViewHelper extends ViewHelper } return $this; } - + public function success($msg) { Session::set(__CLASS__, array('message' => $msg, 'type' => self::SUCCESS)); } - + public function error($msg) { Session::set(__CLASS__, array('message' => $msg, 'type' => self::ERROR)); diff --git a/view/helpers/TitleViewHelper.php b/view/helpers/TitleViewHelper.php index 812230d..56fd7c7 100644 --- a/view/helpers/TitleViewHelper.php +++ b/view/helpers/TitleViewHelper.php @@ -11,9 +11,9 @@ class TitleViewHelper extends ViewHelper { - + protected $separator = ' - '; - + public function title($string = false) { if ($string) { @@ -23,12 +23,12 @@ class TitleViewHelper extends ViewHelper } return $this; } - + public function setSeparator($sep) { $this->separator = $sep; } - + public function __toString() { return implode($this->separator, Registry::get(__CLASS__, array())); diff --git a/view/helpers/ViewHelper.php b/view/helpers/ViewHelper.php index 177666d..59a52cb 100644 --- a/view/helpers/ViewHelper.php +++ b/view/helpers/ViewHelper.php @@ -11,12 +11,12 @@ abstract class ViewHelper { - + /** * @var PHPView */ protected $view = null; - + public function __construct($view) { $this->view = $view;