diff --git a/src/Cloud/Decorator/HtmlCloud.php b/src/Cloud/Decorator/HtmlCloud.php index 8afa634..569645d 100644 --- a/src/Cloud/Decorator/HtmlCloud.php +++ b/src/Cloud/Decorator/HtmlCloud.php @@ -20,7 +20,7 @@ class HtmlCloud extends AbstractCloud * @var array */ protected $htmlTags = array( - 'ul' => array('class' => 'Zend\Tag\Cloud') + 'ul' => array('class' => 'zend-tag-cloud'), ); /** diff --git a/test/Cloud/CloudTest.php b/test/Cloud/CloudTest.php index 613296e..31e8042 100644 --- a/test/Cloud/CloudTest.php +++ b/test/Cloud/CloudTest.php @@ -10,6 +10,7 @@ namespace ZendTest\Tag\Cloud; +use stdClass; use Zend\Tag; use Zend\Tag\Cloud; use Zend\Tag\Cloud\DecoratorPluginManager; @@ -29,28 +30,31 @@ class CloudTest extends \PHPUnit_Framework_TestCase public function testGetAndSetItemList() { $cloud = $this->_getCloud(); - $this->assertTrue($cloud->getItemList() instanceof Tag\ItemList); + $this->assertInstanceOf('Zend\Tag\ItemList', $cloud->getItemList()); $cloud->setItemList(new ItemListDummy); - $this->assertTrue($cloud->getItemList() instanceof ItemListDummy); + $this->assertInstanceOf('ZendTest\Tag\Cloud\ItemListDummy', $cloud->getItemList()); } public function testSetCloudDecoratorViaArray() { $cloud = $this->_getCloud(); - $cloud->setCloudDecorator(array('decorator' => 'CloudDummy', 'options' => array('foo' => 'bar'))); - $this->assertTrue($cloud->getCloudDecorator() instanceof TestAsset\CloudDummy); + $cloud->setCloudDecorator(array( + 'decorator' => 'CloudDummy', + 'options' => array('foo' => 'bar'), + )); + $this->assertInstanceOf('ZendTest\Tag\Cloud\TestAsset\CloudDummy', $cloud->getCloudDecorator()); $this->assertEquals('bar', $cloud->getCloudDecorator()->getFoo()); } public function testGetAndSetCloudDecorator() { $cloud = $this->_getCloud(); - $this->assertTrue($cloud->getCloudDecorator() instanceof \Zend\Tag\Cloud\Decorator\HtmlCloud); + $this->assertInstanceOf('Zend\Tag\Cloud\Decorator\HtmlCloud', $cloud->getCloudDecorator()); $cloud->setCloudDecorator(new TestAsset\CloudDummy()); - $this->assertTrue($cloud->getCloudDecorator() instanceof TestAsset\CloudDummy); + $this->assertInstanceOf('ZendTest\Tag\Cloud\TestAsset\CloudDummy', $cloud->getCloudDecorator()); } public function testSetInvalidCloudDecorator() @@ -58,25 +62,28 @@ public function testSetInvalidCloudDecorator() $cloud = $this->_getCloud(); $this->setExpectedException('Zend\Tag\Exception\InvalidArgumentException', 'DecoratorInterface'); - $cloud->setCloudDecorator(new \stdClass()); + $cloud->setCloudDecorator(new stdClass()); } public function testSetTagDecoratorViaArray() { $cloud = $this->_getCloud(); - $cloud->setTagDecorator(array('decorator' => 'TagDummy', 'options' => array('foo' => 'bar'))); - $this->assertTrue($cloud->getTagDecorator() instanceof TestAsset\TagDummy); + $cloud->setTagDecorator(array( + 'decorator' => 'TagDummy', + 'options' => array('foo' => 'bar'), + )); + $this->assertInstanceOf('ZendTest\Tag\Cloud\TestAsset\TagDummy', $cloud->getTagDecorator()); $this->assertEquals('bar', $cloud->getTagDecorator()->getFoo()); } public function testGetAndSetTagDecorator() { $cloud = $this->_getCloud(); - $this->assertTrue($cloud->getTagDecorator() instanceof \Zend\Tag\Cloud\Decorator\HtmlTag); + $this->assertInstanceOf('Zend\Tag\Cloud\Decorator\HtmlTag', $cloud->getTagDecorator()); $cloud->setTagDecorator(new TestAsset\TagDummy()); - $this->assertTrue($cloud->getTagDecorator() instanceof TestAsset\TagDummy); + $this->assertInstanceOf('ZendTest\Tag\Cloud\TestAsset\TagDummy', $cloud->getTagDecorator()); } public function testSetInvalidTagDecorator() @@ -84,7 +91,7 @@ public function testSetInvalidTagDecorator() $cloud = $this->_getCloud(); $this->setExpectedException('Zend\Tag\Exception\InvalidArgumentException', 'DecoratorInterface'); - $cloud->setTagDecorator(new \stdClass()); + $cloud->setTagDecorator(new stdClass()); } public function testSetDecoratorPluginManager() @@ -98,7 +105,10 @@ public function testSetDecoratorPluginManager() public function testSetDecoratorPluginManagerViaOptions() { $decorators = new DecoratorPluginManager(); - $cloud = $this->_getCloud(array('decoratorPluginManager' => $decorators), null); + $cloud = $this->_getCloud( + array('decoratorPluginManager' => $decorators), + null + ); $this->assertSame($decorators, $cloud->getDecoratorPluginManager()); } @@ -107,7 +117,10 @@ public function testAppendTagAsArray() $cloud = $this->_getCloud(); $list = $cloud->getItemList(); - $cloud->appendTag(array('title' => 'foo', 'weight' => 1)); + $cloud->appendTag(array( + 'title' => 'foo', + 'weight' => 1, + )); $this->assertEquals('foo', $list[0]->getTitle()); } @@ -117,7 +130,10 @@ public function testAppendTagAsItem() $cloud = $this->_getCloud(); $list = $cloud->getItemList(); - $cloud->appendTag(new Tag\Item(array('title' => 'foo', 'weight' => 1))); + $cloud->appendTag(new Tag\Item(array( + 'title' => 'foo', + 'weight' => 1, + ))); $this->assertEquals('foo', $list[0]->getTitle()); } @@ -135,8 +151,16 @@ public function testSetTagsAsArray() $cloud = $this->_getCloud(); $list = $cloud->getItemList(); - $cloud->setTags(array(array('title' => 'foo', 'weight' => 1), - array('title' => 'bar', 'weight' => 2))); + $cloud->setTags(array( + array( + 'title' => 'foo', + 'weight' => 1, + ), + array( + 'title' => 'bar', + 'weight' => 2, + ) + )); $this->assertEquals('foo', $list[0]->getTitle()); $this->assertEquals('bar', $list[1]->getTitle()); @@ -147,8 +171,16 @@ public function testSetTagsAsItem() $cloud = $this->_getCloud(); $list = $cloud->getItemList(); - $cloud->setTags(array(new Tag\Item(array('title' => 'foo', 'weight' => 1)), - new Tag\Item(array('title' => 'bar', 'weight' => 2)))); + $cloud->setTags(array( + new Tag\Item( array( + 'title' => 'foo', + 'weight' => 1, + )), + new Tag\Item( array( + 'title' => 'bar', + 'weight' => 2, + )), + )); $this->assertEquals('foo', $list[0]->getTitle()); $this->assertEquals('bar', $list[1]->getTitle()); @@ -159,8 +191,16 @@ public function testSetTagsMixed() $cloud = $this->_getCloud(); $list = $cloud->getItemList(); - $cloud->setTags(array(array('title' => 'foo', 'weight' => 1), - new Tag\Item(array('title' => 'bar', 'weight' => 2)))); + $cloud->setTags(array( + array( + 'title' => 'foo', + 'weight' => 1, + ), + new Tag\Item(array( + 'title' => 'bar', + 'weight' => 2, + )), + )); $this->assertEquals('foo', $list[0]->getTitle()); $this->assertEquals('bar', $list[1]->getTitle()); @@ -176,7 +216,14 @@ public function testSetInvalidTags() public function testConstructorWithArray() { - $cloud = $this->_getCloud(array('tags' => array(array('title' => 'foo', 'weight' => 1)))); + $cloud = $this->_getCloud(array( + 'tags' => array( + array( + 'title' => 'foo', + 'weight' => 1, + ), + ), + )); $list = $cloud->getItemList(); $this->assertEquals('foo', $list[0]->getTitle()); @@ -184,7 +231,14 @@ public function testConstructorWithArray() public function testConstructorWithConfig() { - $cloud = $this->_getCloud(new \Zend\Config\Config(array('tags' => array(array('title' => 'foo', 'weight' => 1))))); + $cloud = $this->_getCloud( new \Zend\Config\Config(array( + 'tags' => array( + array( + 'title' => 'foo', + 'weight' => 1, + ), + ), + ))); $list = $cloud->getItemList(); $this->assertEquals('foo', $list[0]->getTitle()); @@ -193,8 +247,15 @@ public function testConstructorWithConfig() public function testSetOptions() { $cloud = $this->_getCloud(); - $cloud->setOptions(array('tags' => array(array('title' => 'foo', 'weight' => 1)))); - $list = $cloud->getItemList(); + $cloud->setOptions(array( + 'tags' => array( + array( + 'title' => 'foo', + 'weight' => 1, + ), + ), + )); + $list = $cloud->getItemList(); $this->assertEquals('foo', $list[0]->getTitle()); } @@ -207,11 +268,22 @@ public function testSkipOptions() public function testRender() { - $cloud = $this->_getCloud(array('tags' => array(array('title' => 'foo', 'weight' => 1), array('title' => 'bar', 'weight' => 3)))); - $expected = ''; + $cloud = $this->_getCloud(array( + 'tags' => array( + array( + 'title' => 'foo', + 'weight' => 1, + ), + array( + 'title' => 'bar', + 'weight' => 3, + ), + ), + )); + $expected = ''; $this->assertEquals($expected, $cloud->render()); } @@ -223,28 +295,51 @@ public function testRenderEmptyCloud() public function testRenderViaToString() { - $cloud = $this->_getCloud(array('tags' => array(array('title' => 'foo', 'weight' => 1), array('title' => 'bar', 'weight' => 3)))); - $expected = ''; - $this->assertEquals($expected, (string) $cloud); + $cloud = $this->_getCloud(array( + 'tags' => array( + array( + 'title' => 'foo', + 'weight' => 1, + ), + array( + 'title' => 'bar', + 'weight' => 3, + ), + ), + )); + $expected = ''; + $this->assertEquals($expected, (string)$cloud); } - protected function _getCloud($options = null, $setDecoratorPluginManager = true) - { + protected function _getCloud( + $options = null, + $setDecoratorPluginManager = true + ) { $cloud = new Tag\Cloud($options); if ($setDecoratorPluginManager) { $decorators = $cloud->getDecoratorPluginManager(); - $decorators->setInvokableClass('clouddummy', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy'); - $decorators->setInvokableClass('clouddummy1', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy1'); - $decorators->setInvokableClass('clouddummy2', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy2'); - $decorators->setInvokableClass('tagdummy', 'ZendTest\Tag\Cloud\TestAsset\TagDummy'); + $decorators->setInvokableClass( + 'clouddummy', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy' + ); + $decorators->setInvokableClass( + 'clouddummy1', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy1' + ); + $decorators->setInvokableClass( + 'clouddummy2', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy2' + ); + $decorators->setInvokableClass( + 'tagdummy', 'ZendTest\Tag\Cloud\TestAsset\TagDummy' + ); } return $cloud; } } -class ItemListDummy extends Tag\ItemList {} +class ItemListDummy extends Tag\ItemList +{ +} diff --git a/test/Cloud/Decorator/HtmlCloudTest.php b/test/Cloud/Decorator/HtmlCloudTest.php index a5b941d..a2ea521 100644 --- a/test/Cloud/Decorator/HtmlCloudTest.php +++ b/test/Cloud/Decorator/HtmlCloudTest.php @@ -25,15 +25,36 @@ public function testDefaultOutput() { $decorator = new Decorator\HtmlCloud(); - $this->assertEquals('', $decorator->render(array('foo', 'bar'))); + $this->assertEquals( + '', + $decorator->render( + array( + 'foo', + 'bar' + ) + ) + ); } public function testNestedTags() { $decorator = new Decorator\HtmlCloud(); - $decorator->setHtmlTags(array('span', 'div' => array('id' => 'tag-cloud'))); + $decorator->setHtmlTags( + array( + 'span', + 'div' => array('id' => 'tag-cloud') + ) + ); - $this->assertEquals('
foo bar
', $decorator->render(array('foo', 'bar'))); + $this->assertEquals( + '
foo bar
', + $decorator->render( + array( + 'foo', + 'bar' + ) + ) + ); } public function testSeparator() @@ -41,29 +62,73 @@ public function testSeparator() $decorator = new Decorator\HtmlCloud(); $decorator->setSeparator('-'); - $this->assertEquals('', $decorator->render(array('foo', 'bar'))); + $this->assertEquals( + '', + $decorator->render( + array( + 'foo', + 'bar' + ) + ) + ); } public function testConstructorWithArray() { - $decorator = new Decorator\HtmlCloud(array('htmlTags' => array('div'), 'separator' => ' ')); - - $this->assertEquals('
foo bar
', $decorator->render(array('foo', 'bar'))); + $decorator = new Decorator\HtmlCloud(array( + 'htmlTags' => array('div'), + 'separator' => ' ' + )); + + $this->assertEquals( + '
foo bar
', $decorator->render( + array( + 'foo', + 'bar' + ) + ) + ); } public function testConstructorWithConfig() { - $decorator = new Decorator\HtmlCloud(new \Zend\Config\Config(array('htmlTags' => array('div'), 'separator' => ' '))); + $decorator = new Decorator\HtmlCloud( + new \Zend\Config\Config( + array( + 'htmlTags' => array('div'), + 'separator' => ' ' + ) + ) + ); - $this->assertEquals('
foo bar
', $decorator->render(array('foo', 'bar'))); + $this->assertEquals( + '
foo bar
', $decorator->render( + array( + 'foo', + 'bar' + ) + ) + ); } public function testSetOptions() { $decorator = new Decorator\HtmlCloud(); - $decorator->setOptions(array('htmlTags' => array('div'), 'separator' => ' ')); + $decorator->setOptions( + array( + 'htmlTags' => array('div'), + 'separator' => ' ' + ) + ); - $this->assertEquals('
foo bar
', $decorator->render(array('foo', 'bar'))); + $this->assertEquals( + '
foo bar
', $decorator->render( + array( + 'foo', + 'bar' + ) + ) + ); } public function testSkipOptions() @@ -79,9 +144,11 @@ public function invalidHtmlTagProvider() array(array('&foo')), array(array(' foo')), array(array(' foo')), - array(array( - '_foo' => array(), - )), + array( + array( + '_foo' => array(), + ) + ), ); } @@ -92,28 +159,36 @@ public function testInvalidHtmlTagsRaiseAnException($tags) { $decorator = new Decorator\HtmlCloud(); $decorator->setHTMLTags($tags); - $this->setExpectedException('Zend\Tag\Exception\InvalidElementNameException'); + $this->setExpectedException( + 'Zend\Tag\Exception\InvalidElementNameException' + ); $decorator->render(array()); } public function invalidAttributeProvider() { return array( - array(array( - 'foo' => array( - '&bar' => 'baz', - ), - )), - array(array( - 'foo' => array( - ':bar&baz' => 'bat', - ), - )), - array(array( - 'foo' => array( - 'bar/baz' => 'bat', - ), - )), + array( + array( + 'foo' => array( + '&bar' => 'baz', + ), + ) + ), + array( + array( + 'foo' => array( + ':bar&baz' => 'bat', + ), + ) + ), + array( + array( + 'foo' => array( + 'bar/baz' => 'bat', + ), + ) + ), ); } @@ -124,7 +199,9 @@ public function testInvalidAttributeNamesRaiseAnException($tags) { $decorator = new Decorator\HtmlCloud(); $decorator->setHTMLTags($tags); - $this->setExpectedException('Zend\Tag\Exception\InvalidAttributeNameException'); + $this->setExpectedException( + 'Zend\Tag\Exception\InvalidAttributeNameException' + ); $decorator->render(array()); } }