diff --git a/README.md b/README.md index 9dd7a55..531623f 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()__ @@ -142,4 +142,4 @@ __It's compulsory to override the `toString()` method (not the `__toString()` ma Builds the HTML and stores it in a variable. Rebuilds the HTML every time it's called. - _CHAINABLE_ \ No newline at end of file + _CHAINABLE_ 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..b74fb2d 100644 --- a/classes/Foolz/Theme/ParamManager.php +++ b/classes/Foolz/Theme/ParamManager.php @@ -36,8 +36,8 @@ 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 */ public function getParam($key) @@ -77,7 +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 8497d91..454a416 100644 --- a/classes/Foolz/Theme/Theme.php +++ b/classes/Foolz/Theme/Theme.php @@ -14,7 +14,7 @@ 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..91c2710 100644 --- a/tests/classes/BuilderTest.php +++ b/tests/classes/BuilderTest.php @@ -39,7 +39,6 @@ public function bld() return $this->theme()->createBuilder(); } - public function testConstruct() { $this->assertInstanceOf('Foolz\Theme\Builder', $this->bld()); @@ -67,6 +66,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..14bd19c 100644 --- a/tests/classes/ParamManagerTest.php +++ b/tests/classes/ParamManagerTest.php @@ -12,32 +12,30 @@ 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)); + $new = new ParamManager(); + + $new->setParam('param1', 'test'); + $new->setParam('param2', 'testtest'); + $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/UtilTest.php b/tests/classes/UtilTest.php new file mode 100644 index 0000000..482e37d --- /dev/null +++ b/tests/classes/UtilTest.php @@ -0,0 +1,16 @@ +lowercaseToClassName('HERP DERP'); + } +} \ No newline at end of file