Skip to content

Commit

Permalink
Merge pull request #7 from LoversOfBehat/fix-incomplete-matches
Browse files Browse the repository at this point in the history
Fix matching of tables that contain partially duplicated data
  • Loading branch information
pfrenssen authored Jun 27, 2018
2 parents b291e9e + eafe80d commit 89b48b3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ default:
'Population data': 'table.countries'
'Employees': '.employees > table'
'Mad spanner': '.madspans'
'User roles': '.roles'
15 changes: 14 additions & 1 deletion features/tables.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Inspecting HTML tables
Scenario: Check if any table on the page matches certain characteristics
Given I am on the homepage
Then I should see a table
And I should see 5 tables
And I should see 6 tables

And I should see a table with 2 columns
And I should see a table with 3 columns
Expand Down Expand Up @@ -147,3 +147,16 @@ Feature: Inspecting HTML tables
| | | 3C | | | |
| 4A | 4B | | 4D | | |
| 5A | | 5C | | | |

# The sixth table contains cells with the same content in different rows.
And I should see the "User roles" table
And the "User roles" table should have 3 columns
And the "User roles" table should have 7 rows
And the "User roles" table should contain the following columns:
| Group | Username | Role |
| Engineering | Najib Randall | administrator |
| Support | Victor Otto | administrator |
| Engineering | Melor Vescovi | moderator |
| Engineering | Panteleimon Kita | moderator |
| Support | Victor Otto | moderator |
| Support | Melissa Kevorkian | moderator |
41 changes: 41 additions & 0 deletions fixtures/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,46 @@
<td colspan="3">5C</td>
</tr>
</table>
<table class="roles">
<thead>
<tr>
<th>Group</th>
<th>Username</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<tr>
<td>Engineering</td>
<td>Najib Randall</td>
<td>administrator</td>
</tr>
<tr>
<td>Support</td>
<td>Victor Otto</td>
<td>administrator</td>
</tr>
<tr>
<td>Engineering</td>
<td>Melor Vescovi</td>
<td>moderator</td>
</tr>
<tr>
<td>Support</td>
<td>Victor Otto</td>
<td>moderator</td>
</tr>
<tr>
<td>Engineering</td>
<td>Panteleimon Kita</td>
<td>moderator</td>
</tr>
<tr>
<td>Support</td>
<td>Melissa Kevorkian</td>
<td>moderator</td>
</tr>
</tbody>
</table>
</body>
</html>
3 changes: 2 additions & 1 deletion src/AssertArraySubset.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private function arrayIntersectRecursive(array $array, array $subset): array
}
}

return $intersect;
// Only return the result if it fully matches the subset.
return count($subset) == count($intersect) ? $intersect : [];
}
}

0 comments on commit 89b48b3

Please sign in to comment.