Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Given /^I should see a table with:$/
- */
- public function iShouldSeeTableWith(TableNode $expectedTable)
- {
- $expectedArray = $expectedTable->getColumnsHash();
- $currentArray = [];
- $tables = $this->getSession()->getPage()->findAll('css', 'table');
- /** @var NodeElement $table */
- foreach ($tables as $table) {
- $headers = null;
- $numHeaders = null;
- foreach ($table->findAll('css', 'tr') as $tableRow) {
- if (!count($columns = $tableRow->findAll('css', 'td'))) {
- $columns = $tableRow->findAll('css', 'th');
- }
- array_walk($columns, function (NodeElement &$column) {
- $column = $this->normaliseDataToCompare($column->getHtml());
- });
- if (null === $headers) {
- $headers = $columns;
- $numHeaders = count($headers);
- continue;
- }
- if (count($columns) === $numHeaders) {
- $currentArray[] = array_combine($headers, $columns);
- }
- }
- }
- foreach ($expectedArray as $row) {
- $found = false;
- foreach ($currentArray as $key => $currentRow) {
- if (0 === count(array_diff($row, $currentRow))) {
- $found = true;
- // remove this row so we can find duplicated entries
- unset($currentArray[$key]);
- break;
- }
- }
- assert::assertTrue($found, sprintf('Row "%s" was not found', implode(', ', $row)));
- }
- }
Add Comment
Please, Sign In to add comment