Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Refactoring: extracted sample tag data in a field
Browse files Browse the repository at this point in the history
.... it will allow to maintain tests more easily and create
smaller unit tests
  • Loading branch information
real34 committed Feb 24, 2014
1 parent 8fa7b42 commit 946a44a
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions Test/Case/View/Helper/TagCloudHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,32 @@
*/
class TagCloudHelperTest extends CakeTestCase {

/**
* Sample data for testing purposes
*
* @var array
*/
public $sampleTags = array(
array(
'Tag' => array(
'id' => 1,
'identifier' => null,
'name' => 'CakePHP',
'keyname' => 'cakephp',
'weight' => 2,
'created' => '2008-06-02 18:18:11',
'modified' => '2008-06-02 18:18:37')),
array(
'Tag' => array(
'id' => 2,
'identifier' => null,
'name' => 'CakeDC',
'keyname' => 'cakedc',
'weight' => 2,
'created' => '2008-06-01 18:18:15',
'modified' => '2008-06-01 18:18:15')),
);

/**
* Helper being tested
*
Expand All @@ -47,26 +73,6 @@ public function setUp() {
*/
public function testDisplay() {
$this->assertEqual($this->TagCloud->display(), '');
$tags = array(
array(
'Tag' => array(
'id' => 1,
'identifier' => null,
'name' => 'CakePHP',
'keyname' => 'cakephp',
'weight' => 2,
'created' => '2008-06-02 18:18:11',
'modified' => '2008-06-02 18:18:37')),
array(
'Tag' => array(
'id' => 2,
'identifier' => null,
'name' => 'CakeDC',
'keyname' => 'cakedc',
'weight' => 2,
'created' => '2008-06-01 18:18:15',
'modified' => '2008-06-01 18:18:15')),
);

// Test tags shuffling
$options = array(
Expand All @@ -75,14 +81,14 @@ public function testDisplay() {
$i = 100;
do {
$i--;
$result = $this->TagCloud->display($tags, $options);
$result = $this->TagCloud->display($this->sampleTags, $options);
} while ($result == $expected && $i > 0);
$this->assertNotEqual($result, $expected);

// Test normal display
$options = array(
'shuffle' => false);
$result = $this->TagCloud->display($tags, $options);
$result = $this->TagCloud->display($this->sampleTags, $options);
$this->assertEqual($result, $expected);

// Test options
Expand All @@ -94,11 +100,12 @@ public function testDisplay() {
'url' => array('controller' => 'search', 'from' => 'twitter'),
'named' => 'query'
));
$result = $this->TagCloud->display($tags, $options);
$result = $this->TagCloud->display($this->sampleTags, $options);
$expected = '<span size="1"><a href="/search/index/from:twitter/query:cakephp" id="tag-1">CakePHP</a> </span><!-- size: 1 -->'.
'<span size="1"><a href="/search/index/from:twitter/query:cakedc" id="tag-2">CakeDC</a> </span><!-- size: 1 -->';
$this->assertEqual($result, $expected);

$tags = $this->sampleTags;
$tags[1]['Tag']['weight'] = 1;
$result = $this->TagCloud->display($tags, $options);
$expected = '<span size="100"><a href="/search/index/from:twitter/query:cakephp" id="tag-1">CakePHP</a> </span><!-- size: 100 -->'.
Expand Down

0 comments on commit 946a44a

Please sign in to comment.