* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} namespace Tests\Icinga\Web\Widget; require_once('../../library/Icinga/Web/Widget/Widget.php'); require_once('../../library/Icinga/Web/Widget/Tab.php'); require_once('../../library/Icinga/Web/Widget/Tabs.php'); require_once('../../library/Icinga/Web/Url.php'); require_once('library/Icinga/Web/ViewMock.php'); require_once('Zend/View/Abstract.php'); use Icinga\Web\View; use Icinga\Web\Url; use Icinga\Web\Widget\Tabs; use Tests\Icinga\Web\ViewMock; use \Zend_View_Abstract; use \PHPUnit_Framework_TestCase; /** * Test rendering of tabs and corretct tab management * */ class TabsTest extends PHPUnit_Framework_TestCase { /** * Test adding tabs and asserting for correct count * */ public function testAddTabs() { $tabs = new Tabs(); $this->assertEquals(0, $tabs->count(), 'Asserting a tab bar starting with no items'); $tabs->add('tab1', array('title' => 'Tab 1')); $tabs->add('tab2', array('title' => 'Tab 2')); $this->assertEquals(2, $tabs->count(), 'Asserting a tab bar containing 2 items after being added'); $this->assertTrue( $tabs->has('tab1'), 'Asserting the tab bar to determine the existence of added tabs correctly (tab1)' ); $this->assertTrue( $tabs->has('tab2'), 'Asserting the tab bar to determine the existence of added tabs correctly (tab2)' ); } /** * Test rendering of tabs when no dropdown is requested * */ public function testRenderTabsWithoutDropdown() { $tabs = new Tabs(); $tabs->add('tab1', array('title' => 'Tab 1')); $tabs->add('tab2', array('title' => 'Tab 2')); $html = $tabs->render(new ViewMock()); $this->assertContains('
  • Tab 1
  • ', $html, 'Asserting tab 1 being rendered correctly' . $html); $this->assertContains('
  • Tab 2
  • ', $html, 'Asserting tab 2 being rendered correctly' . $html); $this->assertNotContains('class="dropdown ', 'Asserting the dropdown to not be rendered' . $html); } /** * Test rendering of tabs when dropdown is requested * */ public function testRenderDropdown() { $tabs = new Tabs(); $tabs->add('tab1', array('title' => 'Tab 1')); $tabs->addAsDropdown('tab2', array('title' => 'Tab 2')); $html = $tabs->render(new ViewMock()); $this->assertContains('
  • Tab 1
  • ', $html, 'Asserting tab 1 being rendered correctly ' . $html); $this->assertContains('
  • Tab 2
  • ', $html, 'Asserting tab 2 being rendered correctly ' . $html); $this->assertContains('class="dropdown ', 'Asserting the dropdown to be rendered, got ' . $html); } }