Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/Cloud/Decorator/HtmlCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);

/**
Expand Down
181 changes: 138 additions & 43 deletions test/Cloud/CloudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace ZendTest\Tag\Cloud;

use stdClass;
use Zend\Tag;
use Zend\Tag\Cloud;
use Zend\Tag\Cloud\DecoratorPluginManager;
Expand All @@ -29,62 +30,68 @@ 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()
{
$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()
{
$cloud = $this->_getCloud();

$this->setExpectedException('Zend\Tag\Exception\InvalidArgumentException', 'DecoratorInterface');
$cloud->setTagDecorator(new \stdClass());
$cloud->setTagDecorator(new stdClass());
}

public function testSetDecoratorPluginManager()
Expand All @@ -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());
}

Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -176,15 +216,29 @@ 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());
}

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());
Expand All @@ -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());
}
Expand All @@ -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 = '<ul class="Zend&#x5C;Tag&#x5C;Cloud">'
. '<li><a href="" style="font-size: 10px;">foo</a></li> '
. '<li><a href="" style="font-size: 20px;">bar</a></li>'
. '</ul>';
$cloud = $this->_getCloud(array(
'tags' => array(
array(
'title' => 'foo',
'weight' => 1,
),
array(
'title' => 'bar',
'weight' => 3,
),
),
));
$expected = '<ul class="zend-tag-cloud">'
. '<li><a href="" style="font-size: 10px;">foo</a></li> '
. '<li><a href="" style="font-size: 20px;">bar</a></li>'
. '</ul>';
$this->assertEquals($expected, $cloud->render());
}

Expand All @@ -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 = '<ul class="Zend&#x5C;Tag&#x5C;Cloud">'
. '<li><a href="" style="font-size: 10px;">foo</a></li> '
. '<li><a href="" style="font-size: 20px;">bar</a></li>'
. '</ul>';
$this->assertEquals($expected, (string) $cloud);
$cloud = $this->_getCloud(array(
'tags' => array(
array(
'title' => 'foo',
'weight' => 1,
),
array(
'title' => 'bar',
'weight' => 3,
),
),
));
$expected = '<ul class="zend-tag-cloud">'
. '<li><a href="" style="font-size: 10px;">foo</a></li> '
. '<li><a href="" style="font-size: 20px;">bar</a></li>'
. '</ul>';
$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
{
}
Loading

0 comments on commit 1cc7b7d

Please sign in to comment.