Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the Decorator helper unit test.
- Loading branch information
Joey Trapp
committed
Feb 20, 2012
1 parent
b259894
commit 525c934
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
App::uses("DecoratorHelper", "Decorator.View/Helper"); | ||
App::uses("Controller", "Controller"); | ||
require_once(App::pluginPath("Decorator") . "View" . DS . "Decorator" . DS . "Decorator.php"); | ||
|
||
class DecoratorHelperTestDecorator extends Decorator { | ||
} | ||
|
||
class DecoratorHelperTestController extends Controller { | ||
} | ||
|
||
class DecoratorHelperTest extends CakeTestCase { | ||
|
||
public $Decorator; | ||
|
||
public $View; | ||
|
||
public $data = array("DecoratorHelperTest" => array( | ||
"id" => 5, | ||
"content" => "Some content" | ||
)); | ||
|
||
public function setUp() { | ||
parent::setUp(); | ||
$this->View = $this->getMock('View', array('addScript'), array(new DecoratorHelperTestController())); | ||
$this->Decorator = new DecoratorHelper($this->View); | ||
} | ||
|
||
public function tearDown() { | ||
parent::tearDown(); | ||
} | ||
|
||
public function testCreateReturnsBaseDecoratorIfClassNotFound() { | ||
$d = $this->Decorator->create("NoExist", array()); | ||
$this->assertEquals("Decorator", get_class($d)); | ||
} | ||
|
||
public function testCreateReturnsDecoratorClassIfExists() { | ||
$d = $this->Decorator->create("DecoratorHelperTest", $this->data); | ||
$this->assertEquals("DecoratorHelperTestDecorator", get_class($d)); | ||
$this->assertEquals(5, $d->id()); | ||
} | ||
|
||
public function testBuildReturnsListOfTheSameSizeFromInvalidName() { | ||
$data = array($this->data, $this->data); | ||
$d = $this->Decorator->build("NoExist", $data); | ||
$this->assertEquals(2, count($d)); | ||
$this->assertEquals("Decorator", get_class($d[0])); | ||
$this->assertEmpty($d[0]->model); | ||
$this->assertEquals(5, $d[0]->DecoratorHelperTest->id()); | ||
} | ||
|
||
public function testBuildReturnsListOfTheSameSizeValidName() { | ||
$data = array($this->data, $this->data, $this->data); | ||
$d = $this->Decorator->build("DecoratorHelperTest", $data); | ||
$this->assertEquals(3, count($d)); | ||
$this->assertEquals("DecoratorHelperTestDecorator", get_class($d[0])); | ||
$this->assertEquals("Some content", $d[2]->content()); | ||
} | ||
|
||
} |