From 9cd3994f615658c90f308632607122de3827cff5 Mon Sep 17 00:00:00 2001 From: Wohlfe Date: Thu, 20 Dec 2012 05:58:37 +0100 Subject: [PATCH 1/3] More tests, edited some inglese. --- README.md | 20 +++++++-------- classes/Foolz/Theme/Builder.php | 2 +- classes/Foolz/Theme/ParamManager.php | 5 ---- classes/Foolz/Theme/Theme.php | 1 - classes/Foolz/Theme/Void.php | 2 +- tests/classes/BuilderTest.php | 38 +++++++++++++++++++++++++--- tests/classes/LoaderTest.php | 14 ++++++++++ tests/classes/ParamManagerTest.php | 25 +++++++++--------- tests/classes/ThemeTest.php | 2 -- tests/classes/UtilTest.php | 15 +++++++++++ 10 files changed, 87 insertions(+), 37 deletions(-) create mode 100644 tests/classes/LoaderTest.php create mode 100644 tests/classes/UtilTest.php diff --git a/README.md b/README.md index 3fc91fe..2a9067e 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,28 @@ Foolz PHP Theme system ======================= -A theme system that abuses OOP to give those features you always dreamed about. +A theme system that abuses OOP to give you those features you've always dreamed of. You will need PHP 5.4 for this to work. You can install it through [Composer](http://getcomposer.org/) and [Packagist](https://packagist.org/packages/foolz/plugin). ## What a mess! -Foolz\Theme works upon Foolz\Plugin. This means it has inbuilt support for plugin-like stuff, and use it if you wish, or just forget about it. We use it plenty to allow re-skinning and hooking links on the interface. +Foolz\Theme works on top of Foolz\Plugin. This means it has built-in support for plugin-like stuff, that you can use or ignore at will. We use it to allow re-skinning and hooking links on the interface. -What we disliked about other theme systems is that they were nothing more than View managers, monolithic and raw. +We created our own Theme system because other theme systems were nothing more than View managers, monolithic and raw. -This package aims to use a multi-level approach to themes, where you can go up and down in the system and build components at the very last moment - by interacting with the theme in the theme itself. The structure is the following: +This package aims to use a multi-level approach to themes, where you can go up and down in the system and build components at the very last moment - by interacting with the theme directly. The structure goes like this: * Loader * Theme * Builder -> Global Parameter Manager * View -> Local Parameter Manager -From the View you can bubble up to the Loader, grab the global parameters, enter other partials, build them within the View. +From the View you can bubble up to the Loader, grab the global parameters, enter other partials, and build them within the View. Other features: -* Child themes: Instead of having to duplicate the entire theme directory, you can extend another and fallback on its files. You can also extend a theme that by itself extends another, without depth limit. +* Child themes: Instead of having to duplicate the entire theme directory, you can extend another theme and fallback on its files. You can also extend from an extended theme, with no limit. * Asset Manager: compile LESS files on the fly. @@ -81,7 +81,7 @@ The builder is used to create the HTML. It divides the job between layouts and p #### Parameter Manager -Parameter managers are used to consistently store variables for being used in the theme. The Builder owns a global one, and every View has a local one. +Parameter managers are used to consistently store variables for use in the theme. The Builder has a global one, and every View has a local one. * __$pm->reset()__ @@ -114,7 +114,7 @@ Parameter managers are used to consistently store variables for being used in th #### View -The View returned by the Builder is most often a custom object extending \Foolz\Theme\View. +The View returned by the Builder is usually a custom object extending \Foolz\Theme\View. __It's compulsory to override the `toString()` method (not the `__toString()` magic method!) in order to output the HTML. This function should output HTML or return a string.__ @@ -124,7 +124,7 @@ __It's compulsory to override the `toString()` method (not the `__toString()` ma * __$view->getType()__ - Returns the type of View. `layout` or `partial`. + Returns the type of View, either `layout` or `partial`. * __$view->getView()__ @@ -136,7 +136,7 @@ __It's compulsory to override the `toString()` method (not the `__toString()` ma * __$view->build()__ - Builds _and cached_ the HTML. Returns the HTML. + Builds _and caches_ the HTML. Returns the HTML. * __$view->doBuild()__ diff --git a/classes/Foolz/Theme/Builder.php b/classes/Foolz/Theme/Builder.php index 3f53054..2fce728 100644 --- a/classes/Foolz/Theme/Builder.php +++ b/classes/Foolz/Theme/Builder.php @@ -119,7 +119,7 @@ public function getPartial($name) return $this->partials[$name]; } - throw new \OutOfBoundsException('No such a partial exists.'); + throw new \OutOfBoundsException('No such partial exists.'); } /** diff --git a/classes/Foolz/Theme/ParamManager.php b/classes/Foolz/Theme/ParamManager.php index 3ad06fd..96874ab 100644 --- a/classes/Foolz/Theme/ParamManager.php +++ b/classes/Foolz/Theme/ParamManager.php @@ -36,7 +36,6 @@ public function getParams() * Returns the parameter with the key * * @param string $key - * * @return mixed The value of the parameter * @throws \OutOfBoundsException If the key is not set */ @@ -46,7 +45,6 @@ public function getParam($key) { throw new \OutOfBoundsException('Undefined parameter.'); } - return $this->params[$key]; } @@ -55,13 +53,11 @@ public function getParam($key) * * @param string $key The key for the value * @param mixed $value The value - * * @return \Foolz\Theme\ParamManager The current object */ public function setParam($key, $value) { $this->params[$key] = $value; - return $this; } @@ -77,7 +73,6 @@ public function setParams($array) { $this->params[$key] = $item; } - return $this; } } \ No newline at end of file diff --git a/classes/Foolz/Theme/Theme.php b/classes/Foolz/Theme/Theme.php index bb0498f..1d7dc34 100644 --- a/classes/Foolz/Theme/Theme.php +++ b/classes/Foolz/Theme/Theme.php @@ -14,7 +14,6 @@ public function __construct($dir) $this->enableAutoloader(); static::$autoloaded[] = __CLASS__; } - } /** diff --git a/classes/Foolz/Theme/Void.php b/classes/Foolz/Theme/Void.php index cb0ab60..48f4ece 100644 --- a/classes/Foolz/Theme/Void.php +++ b/classes/Foolz/Theme/Void.php @@ -4,5 +4,5 @@ class Void extends \Foolz\Plugin\Void { - + } \ No newline at end of file diff --git a/tests/classes/BuilderTest.php b/tests/classes/BuilderTest.php index f5fbbcc..2c6a6d6 100644 --- a/tests/classes/BuilderTest.php +++ b/tests/classes/BuilderTest.php @@ -10,7 +10,6 @@ public function tearDown() } /** - * * @return \Foolz\Theme\Loader */ public function load() @@ -21,7 +20,6 @@ public function load() } /** - * * @return \Foolz\Theme\Theme */ public function theme() @@ -31,7 +29,6 @@ public function theme() } /** - * * @return \Foolz\Theme\Builder */ public function bld() @@ -39,7 +36,6 @@ public function bld() return $this->theme()->createBuilder(); } - public function testConstruct() { $this->assertInstanceOf('Foolz\Theme\Builder', $this->bld()); @@ -67,6 +63,40 @@ public function testCreatePartial() $this->assertInstanceOf('Foolz\Foolfake\Theme\Fake\Partial\ThisPartial', $this->bld()->createPartial('one_partial', 'this_partial')); } + public function testGetLayout() + { + $bld = $this->bld(); + $bld->createLayout('this_layout'); + $this->assertInstanceOf('Foolz\Theme\View', $bld->getLayout('this_layout')); + $this->assertInstanceOf('Foolz\Foolfake\Theme\Fake\Layout\ThisLayout', $bld->getLayout('this_layout')); + } + + public function testGetPartial() + { + $bld = $this->bld(); + $bld->createPartial('one_partial', 'this_partial'); + $this->assertInstanceOf('Foolz\Theme\View', $bld->getPartial('one_partial', 'this_partial')); + $this->assertInstanceOf('Foolz\Foolfake\Theme\Fake\Partial\ThisPartial', $bld->getPartial('one_partial', 'this_partial')); + } + + /** + * @expectedException \BadMethodCallException + * @expectedExceptionMessage The layout wasn't set. + */ + public function testGetLayoutThrowsBadMethodCall() + { + $this->bld()->getLayout(); + } + + /** + * @expectedException \OutOfBoundsException + * @expectedExceptionMessage No such partial exists. + */ + public function testGetPartialThrowsOutOfBounds() + { + $this->bld()->getPartial('derp'); + } + public function testBuild() { $bld = $this->bld(); diff --git a/tests/classes/LoaderTest.php b/tests/classes/LoaderTest.php new file mode 100644 index 0000000..6a233b7 --- /dev/null +++ b/tests/classes/LoaderTest.php @@ -0,0 +1,14 @@ +addDir('test', __DIR__.'/../../tests/mock/'); + $theme = $new->get('test', 'foolz/foolfake-theme-fake'); + $this->assertInstanceOf('Foolz\Theme\Theme', $theme); + } +} \ No newline at end of file diff --git a/tests/classes/ParamManagerTest.php b/tests/classes/ParamManagerTest.php index 8f1ede3..66d049a 100644 --- a/tests/classes/ParamManagerTest.php +++ b/tests/classes/ParamManagerTest.php @@ -12,32 +12,31 @@ public function testGetParamsEmpty() /** * @expectedException \OutOfBoundsException + * @expectedExceptionMessage Undefined parameter. */ public function testSetGetParamThrowsOutOfBounds() { $new = new ParamManager(); - $new->getParam('derp'); + $new->getParam('herp'); } - public function testGetSetParam() + public function testSetGetParam() { - $stack = array(); - $this->assertEquals(0, count($stack)); - - array_push($stack, 'foo'); - $this->assertEquals('foo', $stack[count($stack)-1]); - $this->assertEquals(1, count($stack)); - - $this->assertEquals('foo', array_pop($stack)); - $this->assertEquals(0, count($stack)); + $arr = array('param1' => 'test', 'param2' => 'testtest'); + $new = new ParamManager($arr); + + $new->setParams($arr); + $this->assertSame($arr, $new->getParams()); + $this->assertSame('test', $new->getParam('param1')); + $this->assertSame('testtest', $new->getParam('param2')); } - public function testGetSetParams() + public function testSetGetParams() { $arr = array('param1' => 'test', 'param2' => 'testtest'); $new = new ParamManager(); - $new->setParams($arr); + $new->setParams($arr); $this->assertSame($arr, $new->getParams()); } } diff --git a/tests/classes/ThemeTest.php b/tests/classes/ThemeTest.php index 947296d..9818356 100644 --- a/tests/classes/ThemeTest.php +++ b/tests/classes/ThemeTest.php @@ -6,7 +6,6 @@ class ThemeTest extends PHPUnit_Framework_TestCase { /** - * * @return \Foolz\Theme\Loader */ public function load() @@ -17,7 +16,6 @@ public function load() } /** - * * @return \Foolz\Theme\Theme */ public function theme() diff --git a/tests/classes/UtilTest.php b/tests/classes/UtilTest.php new file mode 100644 index 0000000..9af22fb --- /dev/null +++ b/tests/classes/UtilTest.php @@ -0,0 +1,15 @@ +lowercaseToClassName('HERP DERP'); + } +} \ No newline at end of file From 7426c88525fea467285b2b18946359c6ae03730e Mon Sep 17 00:00:00 2001 From: Wohlfe Date: Thu, 20 Dec 2012 06:10:13 +0100 Subject: [PATCH 2/3] Fixed the docblocks. --- tests/classes/BuilderTest.php | 3 +++ tests/classes/ThemeTest.php | 2 ++ tests/classes/UtilTest.php | 1 + 3 files changed, 6 insertions(+) diff --git a/tests/classes/BuilderTest.php b/tests/classes/BuilderTest.php index 2c6a6d6..91c2710 100644 --- a/tests/classes/BuilderTest.php +++ b/tests/classes/BuilderTest.php @@ -10,6 +10,7 @@ public function tearDown() } /** + * * @return \Foolz\Theme\Loader */ public function load() @@ -20,6 +21,7 @@ public function load() } /** + * * @return \Foolz\Theme\Theme */ public function theme() @@ -29,6 +31,7 @@ public function theme() } /** + * * @return \Foolz\Theme\Builder */ public function bld() diff --git a/tests/classes/ThemeTest.php b/tests/classes/ThemeTest.php index 9818356..947296d 100644 --- a/tests/classes/ThemeTest.php +++ b/tests/classes/ThemeTest.php @@ -6,6 +6,7 @@ class ThemeTest extends PHPUnit_Framework_TestCase { /** + * * @return \Foolz\Theme\Loader */ public function load() @@ -16,6 +17,7 @@ public function load() } /** + * * @return \Foolz\Theme\Theme */ public function theme() diff --git a/tests/classes/UtilTest.php b/tests/classes/UtilTest.php index 9af22fb..482e37d 100644 --- a/tests/classes/UtilTest.php +++ b/tests/classes/UtilTest.php @@ -5,6 +5,7 @@ class UtilTest extends PHPUnit_Framework_TestCase { /** + * * @return herp_derp */ public function testLowercaseToClassName() From 094007b1d43133fe2fa7158e542e628524af56a1 Mon Sep 17 00:00:00 2001 From: Wohlfe Date: Thu, 20 Dec 2012 06:34:25 +0100 Subject: [PATCH 3/3] Reverted formatting, changed testSetGetParam --- classes/Foolz/Theme/ParamManager.php | 5 +++++ classes/Foolz/Theme/Theme.php | 1 + tests/classes/ParamManagerTest.php | 7 +++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/classes/Foolz/Theme/ParamManager.php b/classes/Foolz/Theme/ParamManager.php index 96874ab..b74fb2d 100644 --- a/classes/Foolz/Theme/ParamManager.php +++ b/classes/Foolz/Theme/ParamManager.php @@ -37,6 +37,7 @@ public function getParams() * * @param string $key * @return mixed The value of the parameter + * * @throws \OutOfBoundsException If the key is not set */ public function getParam($key) @@ -45,6 +46,7 @@ public function getParam($key) { throw new \OutOfBoundsException('Undefined parameter.'); } + return $this->params[$key]; } @@ -53,11 +55,13 @@ public function getParam($key) * * @param string $key The key for the value * @param mixed $value The value + * * @return \Foolz\Theme\ParamManager The current object */ public function setParam($key, $value) { $this->params[$key] = $value; + return $this; } @@ -73,6 +77,7 @@ public function setParams($array) { $this->params[$key] = $item; } + return $this; } } \ No newline at end of file diff --git a/classes/Foolz/Theme/Theme.php b/classes/Foolz/Theme/Theme.php index 1d7dc34..0ededfb 100644 --- a/classes/Foolz/Theme/Theme.php +++ b/classes/Foolz/Theme/Theme.php @@ -14,6 +14,7 @@ public function __construct($dir) $this->enableAutoloader(); static::$autoloaded[] = __CLASS__; } + } /** diff --git a/tests/classes/ParamManagerTest.php b/tests/classes/ParamManagerTest.php index 66d049a..14bd19c 100644 --- a/tests/classes/ParamManagerTest.php +++ b/tests/classes/ParamManagerTest.php @@ -22,11 +22,10 @@ public function testSetGetParamThrowsOutOfBounds() public function testSetGetParam() { - $arr = array('param1' => 'test', 'param2' => 'testtest'); - $new = new ParamManager($arr); + $new = new ParamManager(); - $new->setParams($arr); - $this->assertSame($arr, $new->getParams()); + $new->setParam('param1', 'test'); + $new->setParam('param2', 'testtest'); $this->assertSame('test', $new->getParam('param1')); $this->assertSame('testtest', $new->getParam('param2')); }