gridiron/tests/GridIronTest.php
2021-01-02 22:16:37 -08:00

73 lines
2.9 KiB
PHP

<?php
namespace GridIronTests;
use PHPUnit_Extensions_SeleniumTestCase;
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class GridIronTest extends PHPUnit_Extensions_SeleniumTestCase {
private static $grid = '//div[@id="grid1"]';
private static $rowContainer = '';
private static $caption = '';
private static $header = '';
private static $footer = '';
public static function setUpBeforeClass() {
//phpunit fail! this never gets called
}
public function setUp() {
self::$rowContainer = self::$grid . '//div[contains(@class, "gridiron-row-container")]';
self::$caption = self::$grid . '/div[contains(@class, "gridiron-caption")]';
self::$header = self::$grid . '/div[contains(@class, "gridiron-header")]';
$this->setBrowser('*firefox C:\lib\firefox\firefox.exe');
$this->setBrowserUrl('http://localhost/');
}
private function openAndWaitForData() {
$this->open('http://localhost/gridiron/test.html');
$this->waitForCondition('selenium.browserbot.getCurrentWindow().$("#grid1 .gridiron-data-container .gridiron-row").length > 0;', 2000);
}
public function testCanSelectAndDeselectRow() {
$this->openAndWaitForData();
$this->click(self::$rowContainer . '/div[1]');
$this->assertTrue($this->isElementPresent(self::$rowContainer . '/div[1][contains(@class, "gridiron-selected")]'));
$this->click(self::$rowContainer . '/div[1]');
$this->assertFalse($this->isElementPresent(self::$rowContainer . '/div[1][contains(@class, "gridiron-selected")]'));
}
public function testCaptionTitleIsVisible() {
$this->openAndWaitForData();
$this->assertTrue($this->isElementPresent(self::$caption . '/span[contains(@class, "gridiron-title")]'));
$this->assertEquals('Cities around the world', $this->getText(self::$caption . '/span[contains(@class, "gridiron-title")]'));
}
public function testColumnsAreRenderedCorrectly() {
$this->openAndWaitForData();
$expectedText = array('City', 'Country', 'Region', 'Latitude', 'Longitude');
$this->verifyColumnHeader(1, 'City', true, 145);
$this->verifyColumnHeader(2, 'Country', true, 145);
$this->verifyColumnHeader(3, 'Region', true, 145);
$this->verifyColumnHeader(4, 'Latitude', true, 70);
$this->verifyColumnHeader(5, 'Longitude', false, 70);
}
private function verifyColumnHeader($index, $text, $sortable, $width) {
$xpath = self::$header . '/div[contains(@class, "gridiron-cell")][%s]';
self::assertTrue($this->isElementPresent(sprintf($xpath, $index)));
self::assertEquals($text, $this->getText(sprintf($xpath, $index)));
self::assertContains('width: ' . $width . 'px', $this->getAttribute(sprintf($xpath . '/@style', $index)));
self::assertEquals($sortable, $this->isElementPresent(sprintf($xpath . '/span[contains(@class, "gridiron-sort-indicator")]', $index)));
}
}
?>