/** * Checks the HTML output of the gridHtml function * (a) Asserts that a game grid of the correct size is created * (b) TODO: Asserts the initial state of the grid (two values and two full gauges) * (c) Asserts that the correct number of radio buttons are present and each is associated with an image label * (b) Asserts that all 4 buttons are created */ public function test_formHtml() { $steampunk = new Steampunk\Steampunk(self::SEED); $view = new Steampunk\SteampunkView($steampunk); // Call the formHtml function to obtain the Html for the initial game state (no moves have been made) $html = $view->formHtml(); /* Check that the grid is of the correct size */ $gridSize = $steampunk->getGameSize(); // Obtain and check the number of times the "row" class is used in the HTML $rows = substr_count('div class="row"', $html); $this->assertEquals($gridSize, $rows); // Obtain and check the number of times the "cell" class is used in the HTML $cells = substr_count('div class="cell"', $html); if ($rows != 0) { $columns = $cells / $rows; $this->assertEquals($gridSize, $columns); } else { // Print error message to display the issue to the user $this->assertNotEquals(0, $rows, "Number of rows is equal to 0!"); } /* Check for the presence of at least one valve and gauge (should positioning be checked as well?) */ /* Check for the presence of the turn message on the page */ $turnString = $steampunk->getCurrentPlayer() . "it is your turn"; $this->assertContains($turnString, $html); /* Check that the appropriate number of radio buttons have been created and that each is associated with an image label */ $this->assertContains('div class="radioButtons"', $html); $this->assertContains('<label for="1"$gt;<img src=', $html); $this->assertContains('input type="radio" name="pipeOption" id="1"', $html); $this->assertContains('<label for="2"$gt;<img src=', $html); $this->assertContains('input type="radio" name="pipeOption" id="2"', $html); $this->assertContains('<label for="3"$gt;<img src=', $html); $this->assertContains('input type="radio" name="pipeOption" id="3"', $html); $this->assertContains('<label for="4"$gt;<img src=', $html); $this->assertContains('input type="radio" name="pipeOption" id="4"', $html); $this->assertContains('<label for="5"$gt;<img src=', $html); $this->assertContains('input type="radio" name="pipeOption" id="5"', $html); /* Check that the 4 required buttons are created */ $this->assertContains('div class="buttons"', $html); $this->assertContains('input type="submit" value="Rotate" name="rotate" id="rotate"', $html); $this->assertContains('input type="submit" value="Discard" name="discard" id="discard"', $html); $this->assertContains('input type="submit" value="Open Valve" name="openValve" id="openValve"', $html); $this->assertContains('input type="submit" value="Give Up" name="giveUp" id="giveUp"', $html); }
public function test_grid() { $steampunk = new Steampunk\Steampunk(self::SEED); $steampunk->newGame(6); $this->assertEquals(6, $steampunk->getGameSize()); //diagonally checking to make sure we have a 6 by 6 grid $steampunk->addPipe("tee-esw", 1, 1); $this->assertEquals("tee-esw", $steampunk->getTileContents(1, 1)); $steampunk->addPipe("cap-e", 2, 2); $this->assertEquals("cap-e", $steampunk->getTileContents(2, 2)); $steampunk->addPipe("cap-n", 3, 3); $this->assertEquals("cap-n", $steampunk->getTileContents(3, 3)); $steampunk->addPipe("gauge-0", 4, 4); $this->assertEquals("gauge-0", $steampunk->getTileContents(4, 4)); $steampunk->addPipe("leak-e", 5, 5); $this->assertEquals("leak-e", $steampunk->getTileContents(5, 5)); $steampunk->addPipe("ninety-es", 6, 6); $this->assertEquals("ninety-es", $steampunk->getTileContents(6, 6)); }