Skip to content

Commit

Permalink
Completed UnitTests for Columns
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaDafinser committed Jul 26, 2013
1 parent 2009b62 commit ebfc7a8
Show file tree
Hide file tree
Showing 10 changed files with 640 additions and 0 deletions.
140 changes: 140 additions & 0 deletions tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
namespace ZfcDatagridTest\Column\Action;

use PHPUnit_Framework_TestCase;
use ZfcDatagrid\Filter;

/**
* @group Column
* @covers ZfcDatagrid\Column\Action\AbstractAction
*/
class AbstractActionTest extends PHPUnit_Framework_TestCase
{

/**
*
* @var \ZfcDatagrid\Column\AbstractColumn
*/
private $column;

public function setUp ()
{
$this->column = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn');
$this->column->setUniqueId('colName');
}

public function testLink ()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');

$this->assertEquals('#', $action->getLink());

$action->setLink('/my/page/is/cool');
$this->assertEquals('/my/page/is/cool', $action->getLink());
}

public function testAttributes ()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');

$this->assertEquals(array(), $action->getAttributes());

$this->assertEquals('', $action->getAttribute('something'));

$action->setAttribute('class', 'error');
$this->assertCount(1, $action->getAttributes());
$this->assertEquals(array(
'class' => 'error'
), $action->getAttributes());

$this->assertEquals('error', $action->getAttribute('class'));
}

public function testTitle ()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');

$this->assertEquals('', $action->getTitle());

$action->setTitle('This is my action');
$this->assertEquals('This is my action', $action->getTitle());
}

public function testAddClass ()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');

$this->assertEquals('', $action->getAttribute('class'));

$action->addClass('cssClass');
$this->assertEquals('cssClass', $action->getAttribute('class'));

$action->addClass('cssClass2');
$this->assertEquals('cssClass cssClass2', $action->getAttribute('class'));
}

public function testShowOnValue ()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');

$this->assertCount(0, $action->getShowOnValues());

$this->assertFalse($action->hasShowOnValues());
$action->addShowOnValue($this->column, '23', Filter::EQUAL);
$this->assertTrue($action->hasShowOnValues());
}

public function testIsDisplayed ()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');

$this->assertTrue($action->isDisplayed(array(
$this->column->getUniqueId() => '23'
)));

// EQUAL
$action->addShowOnValue($this->column, '23', Filter::EQUAL);

$this->assertTrue($action->isDisplayed(array(
$this->column->getUniqueId() => '23'
)));

$this->assertFalse($action->isDisplayed(array(
$this->column->getUniqueId() => '33'
)));
}

public function testIsDisplayedNotEqual ()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');

$action->addShowOnValue($this->column, '23', Filter::NOT_EQUAL);

$this->assertTrue($action->isDisplayed(array(
$this->column->getUniqueId() => '32'
)));

$this->assertFalse($action->isDisplayed(array(
$this->column->getUniqueId() => '23'
)));
}

public function testIsDisplayedException ()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');

$this->setExpectedException('Exception');
$action->addShowOnValue($this->column, '23', Filter::BETWEEN);
$action->isDisplayed(array(
$this->column->getUniqueId() => '32'
));
}
}
33 changes: 33 additions & 0 deletions tests/ZfcDatagridTest/Column/Action/ButtonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace ZfcDatagridTest\Column\Action;

use PHPUnit_Framework_TestCase;
use ZfcDatagrid\Column\Action\Button;

/**
* @group Column
* @covers ZfcDatagrid\Column\Action\Button
*/
class ButtonTest extends PHPUnit_Framework_TestCase
{

public function testConstruct ()
{
$button = new Button();

$this->assertEquals(array(
'class' => 'btn'
), $button->getAttributes());
}

public function testLabel ()
{
$button = new Button();

$button->setLabel('My label');
$this->assertEquals('My label', $button->getLabel());

$html = '<a href="#" class="btn">My label</a>';
$this->assertEquals($html, $button->toHtml());
}
}
35 changes: 35 additions & 0 deletions tests/ZfcDatagridTest/Column/Action/IconTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace ZfcDatagridTest\Column\Action;

use PHPUnit_Framework_TestCase;
use ZfcDatagrid\Column\Action\Icon;

/**
* @group Column
* @covers ZfcDatagrid\Column\Action\Icon
*/
class IconTest extends PHPUnit_Framework_TestCase
{

public function testConstruct ()
{
$icon = new Icon();

$this->assertEquals(array(), $icon->getAttributes());
}

public function testIcon ()
{
$icon = new Icon();
$icon->setIconClass('icon-add');

$this->assertEquals(array(
'class' => 'icon-add'
), $icon->getAttributes());

$icon->setIconLink('/images/icon/add.png');

$html = '<i title="" class="icon-add"></i>';
$this->assertEquals($html, $icon->toHtml());
}
}
43 changes: 43 additions & 0 deletions tests/ZfcDatagridTest/Column/ActionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace ZfcDatagridTest\Column;

use ZfcDatagrid\Column;
use PHPUnit_Framework_TestCase;

/**
* @group Column
* @covers ZfcDatagrid\Column\Action
*/
class ActionTest extends PHPUnit_Framework_TestCase
{

public function testConstructDefaultBoth ()
{
$column = new Column\Action();

$this->assertEquals('action', $column->getUniqueId());
$this->assertEquals('Actions', $column->getLabel());
$this->assertFalse($column->isUserSortEnabled());
$this->assertFalse($column->isUserFilterEnabled());
$this->assertFalse($column->isRowClickEnabled());
}

public function testAddAction ()
{
$column = new Column\Action();

$this->assertCount(0, $column->getActions());

$action = $this->getMock('ZfcDatagrid\Column\Action\Button');
$column->addAction($action);

$this->assertCount(1, $column->getActions());

$action2 = $this->getMock('ZfcDatagrid\Column\Action\Button');
$column->addAction($action2);
$action3 = $this->getMock('ZfcDatagrid\Column\Action\Button');
$column->addAction($action3);

$this->assertCount(3, $column->getActions());
}
}
57 changes: 57 additions & 0 deletions tests/ZfcDatagridTest/Column/IconTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
namespace ZfcDatagridTest\Column;

use PHPUnit_Framework_TestCase;
use ZfcDatagrid\Column\Icon;

/**
* @group Column
* @covers ZfcDatagrid\Column\Icon
*/
class IconTest extends PHPUnit_Framework_TestCase
{

public function testConstruct ()
{
$col = new Icon();

$this->assertEquals('icon', $col->getUniqueId());
$this->assertFalse($col->isUserSortEnabled());
$this->assertFalse($col->isUserFilterEnabled());
$this->assertEquals(5, $col->getWidth());
}

public function testIconClass ()
{
$col = new Icon();

$this->assertFalse($col->hasIconClass());

$col->setIconClass('icon-add');
$this->assertEquals('icon-add', $col->getIconClass());
$this->assertTrue($col->hasIconClass());
}

public function testIconLink ()
{
$col = new Icon();

$this->assertFalse($col->hasIconLink());

$col->setIconLink('/images/21/add.png');
$this->assertEquals('/images/21/add.png', $col->getIconLink());
$this->assertTrue($col->hasIconLink());
}

public function testTitle ()
{
$col = new Icon();

$this->assertFalse($col->hasTitle());
$this->assertEquals('', $col->getTitle());

$col->setTitle('blubb');
$this->assertEquals('blubb', $col->getTitle());
$this->assertTrue($col->hasTitle());
}
}
22 changes: 22 additions & 0 deletions tests/ZfcDatagridTest/Column/ImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace ZfcDatagridTest\Column;

use PHPUnit_Framework_TestCase;
use ZfcDatagrid\Column\Image;

/**
* @group Column
* @covers ZfcDatagrid\Column\Image
*/
class ImageTest extends PHPUnit_Framework_TestCase
{

public function testConstruct ()
{
$col = new Image();

$this->assertEquals('image', $col->getUniqueId());
$this->assertFalse($col->isUserSortEnabled());
$this->assertFalse($col->isUserFilterEnabled());
}
}
Loading

0 comments on commit ebfc7a8

Please sign in to comment.