Guest User

Untitled

a guest
Dec 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /**
  2. * @Given /^I should see a table with:$/
  3. */
  4. public function iShouldSeeTableWith(TableNode $expectedTable)
  5. {
  6. $expectedArray = $expectedTable->getColumnsHash();
  7. $currentArray = [];
  8. $tables = $this->getSession()->getPage()->findAll('css', 'table');
  9. /** @var NodeElement $table */
  10. foreach ($tables as $table) {
  11. $headers = null;
  12. $numHeaders = null;
  13. foreach ($table->findAll('css', 'tr') as $tableRow) {
  14. if (!count($columns = $tableRow->findAll('css', 'td'))) {
  15. $columns = $tableRow->findAll('css', 'th');
  16. }
  17. array_walk($columns, function (NodeElement &$column) {
  18. $column = $this->normaliseDataToCompare($column->getHtml());
  19. });
  20. if (null === $headers) {
  21. $headers = $columns;
  22. $numHeaders = count($headers);
  23. continue;
  24. }
  25.  
  26. if (count($columns) === $numHeaders) {
  27. $currentArray[] = array_combine($headers, $columns);
  28. }
  29. }
  30. }
  31.  
  32. foreach ($expectedArray as $row) {
  33. $found = false;
  34. foreach ($currentArray as $key => $currentRow) {
  35. if (0 === count(array_diff($row, $currentRow))) {
  36. $found = true;
  37. // remove this row so we can find duplicated entries
  38. unset($currentArray[$key]);
  39. break;
  40. }
  41. }
  42. assert::assertTrue($found, sprintf('Row "%s" was not found', implode(', ', $row)));
  43. }
  44. }
Add Comment
Please, Sign In to add comment