Skip to content

Commit 68bee27

Browse files
authored
Improve Mink test types; remove unnecessary assertions. (vufind-org#5006)
1 parent b3e3713 commit 68bee27

8 files changed

Lines changed: 132 additions & 126 deletions

File tree

module/VuFind/src/VuFindTest/Integration/MinkTestCase.php

Lines changed: 90 additions & 85 deletions
Large diffs are not rendered by default.

module/VuFind/tests/integration-tests/src/VuFindTest/Mink/LibraryCardsTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
namespace VuFindTest\Mink;
3131

3232
use Behat\Mink\Element\Element;
33+
use Behat\Mink\Element\NodeElement;
3334

3435
/**
3536
* Mink library card actions test class.
@@ -145,7 +146,7 @@ public function testAddCards(): void
145146
$this->fillInLibraryCardForm($page, 'card 1', 'catuser1', 'bad');
146147
$this->clickCss($page, '.form-edit-card .btn.btn-primary');
147148
$this->waitForPageLoad($page);
148-
$this->assertEquals(
149+
$this->assertSame(
149150
'Invalid login -- please try again.',
150151
$this->findCssAndGetText($page, '.alert-danger')
151152
);
@@ -154,7 +155,7 @@ public function testAddCards(): void
154155
$this->fillInLibraryCardForm($page, 'card 1', 'catuser1', 'catpass1');
155156
$this->clickCss($page, '.form-edit-card .btn.btn-primary');
156157
$this->waitForPageLoad($page);
157-
$this->assertEquals(
158+
$this->assertSame(
158159
'card 1',
159160
$this->findCssAndGetText($page, 'tr:nth-child(2) td')
160161
);
@@ -165,7 +166,7 @@ public function testAddCards(): void
165166
$this->fillInLibraryCardForm($page, 'card 2', 'catuser2', 'catpass2');
166167
$this->clickCss($page, '.form-edit-card .btn.btn-primary');
167168
$this->waitForPageLoad($page);
168-
$this->assertEquals(
169+
$this->assertSame(
169170
'card 2',
170171
$this->findCssAndGetText($page, 'tr:nth-child(3) td')
171172
);
@@ -185,7 +186,7 @@ public function testAllowUserLoginDisablesButton()
185186
$this->fillInLoginForm($page, 'username1', 'test', false);
186187
$this->submitLoginForm($page, false);
187188
$this->waitForPageLoad($page);
188-
$this->assertEquals('Library Cards', $this->findCssAndGetText($page, 'h2'));
189+
$this->assertSame('Library Cards', $this->findCssAndGetText($page, 'h2'));
189190
$this->unfindCss($page, '.add-card span.icon-link__label');
190191
}
191192

@@ -213,7 +214,7 @@ public function testSwitchingCards(): void
213214
$this->assertEquals('card 2', $secondCard->getText());
214215

215216
// Check that the appropriate username is reflected in the output:
216-
$this->assertEquals(
217+
$this->assertSame(
217218
'Lib-catuser1',
218219
$this->findCssAndGetText($page, '.catalog-profile tr:nth-child(1) td:nth-child(2)')
219220
);
@@ -224,7 +225,7 @@ public function testSwitchingCards(): void
224225
$this->waitForPageLoad($page);
225226

226227
// Check that the appropriate username is reflected in the output:
227-
$this->assertEquals(
228+
$this->assertSame(
228229
'Lib-catuser2',
229230
$this->findCssAndGetText($page, '.catalog-profile tr:nth-child(1) td:nth-child(2)')
230231
);
@@ -246,7 +247,7 @@ public function testCardsDisabledByDefault(): void
246247
$this->submitLoginForm($page, false);
247248
$this->waitForPageLoad($page);
248249
// Confirm that we are on the profile page with no cards showing:
249-
$this->assertEquals('Your Profile', $this->findCssAndGetText($page, 'h2'));
250+
$this->assertSame('Your Profile', $this->findCssAndGetText($page, 'h2'));
250251
$this->unFindCss($page, '#library_card');
251252
}
252253

@@ -272,7 +273,7 @@ public function testAddingDuplicateCardUsername(): void
272273
$this->clickCss($page, '.form-edit-card .btn.btn-primary');
273274
$this->waitForPageLoad($page);
274275

275-
$this->assertEquals(
276+
$this->assertSame(
276277
'Username is already in use in another library card',
277278
$this->findCssAndGetText($page, '.alert-danger')
278279
);
@@ -299,7 +300,7 @@ public function testEditingCard(): void
299300
$this->findCssAndSetValue($page, '[name="card_name"]', 'Edited Card');
300301
$this->clickCss($page, '.form-edit-card .btn.btn-primary');
301302
$this->waitForPageLoad($page);
302-
$this->assertEquals(
303+
$this->assertSame(
303304
'Edited Card',
304305
$this->findCssAndGetText($page, 'tr:nth-child(2) td')
305306
);
@@ -329,19 +330,20 @@ public function testDeletingCard(): void
329330

330331
// Click the delete button
331332
$button = $this->findCss($page, 'tr:nth-child(3)')->findLink('Delete');
333+
$this->assertInstanceOf(NodeElement::class, $button);
332334
$button->click();
333335
$this->waitForPageLoad($page);
334336
$this->clickCss($page, $this->firstOpenDropdownMenuItemSelector);
335337
$this->waitForPageLoad($page);
336338

337339
// Check for success message
338-
$this->assertEquals(
340+
$this->assertSame(
339341
'Library Card Deleted',
340342
$this->findCssAndGetText($page, '.alert-success')
341343
);
342344

343345
// Check that the deleted card is now gone, but the other card still exists.
344-
$this->assertEquals(
346+
$this->assertSame(
345347
'Edited Card',
346348
$this->findCssAndGetText($page, 'tr:nth-child(2) td')
347349
);

module/VuFind/tests/integration-tests/src/VuFindTest/Mink/OAuth2Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public function testOAuth2InvalidClient(): void
483483
);
484484
$page = $session->getPage();
485485

486-
$this->assertEquals(
486+
$this->assertSame(
487487
'An error has occurred',
488488
$this->findCssAndGetText($page, '.alert-danger p')
489489
);
@@ -644,7 +644,7 @@ protected function restoreOpenSSLKeyPair(): void
644644
*
645645
* @return void
646646
*/
647-
protected function restoreConfigs()
647+
protected function restoreConfigs(): void
648648
{
649649
parent::restoreConfigs();
650650
if ($this->opensslKeyPairCreated) {

module/VuFind/tests/integration-tests/src/VuFindTest/Mink/PasswordAccessTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function testLogin(bool $hashedPassword): void
109109
$this->findCssAndSetValue($page, '#login_PasswordAccess_password', 'bad');
110110
$this->clickCss($page, '.modal-content input[type="submit"]');
111111
$this->waitForPageLoad($page);
112-
$this->assertEquals(
112+
$this->assertSame(
113113
'Invalid login -- please try again.',
114114
$this->findCssAndGetText($page, '.modal-content .alert-danger')
115115
);
@@ -146,7 +146,7 @@ public function testLoginWithMissingConfiguration(): void
146146
$this->findCssAndSetValue($page, '#login_PasswordAccess_password', 'bad');
147147
$this->clickCss($page, '.modal-content input[type="submit"]');
148148
$this->waitForPageLoad($page);
149-
$this->assertEquals(
149+
$this->assertSame(
150150
'Invalid login -- please try again.',
151151
$this->findCssAndGetText($page, '.modal-content .alert-danger')
152152
);
@@ -155,7 +155,7 @@ public function testLoginWithMissingConfiguration(): void
155155
$this->findCssAndSetValue($page, '#login_PasswordAccess_password', 'password');
156156
$this->clickCss($page, '.modal-content input[type="submit"]');
157157
$this->waitForPageLoad($page);
158-
$this->assertEquals(
158+
$this->assertSame(
159159
'Invalid login -- please try again.',
160160
$this->findCssAndGetText($page, '.modal-content .alert-danger')
161161
);
@@ -174,7 +174,7 @@ protected function logoutAndAssertSuccess(Element $page): void
174174
$this->clickCss($page, '.logoutOptions a.logout');
175175

176176
// Check that login link is back
177-
$this->assertNotEmpty($this->findCss($page, '#loginOptions a'));
177+
$this->findCss($page, '#loginOptions a');
178178
}
179179

180180
/**

module/VuFind/tests/integration-tests/src/VuFindTest/Mink/PrivateUserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function testLoginDoesNotAddUserToDatabase(): void
150150
// Log out
151151
$this->clickCss($page, '.logoutOptions a.logout');
152152
// Check that login link is back
153-
$this->assertNotEmpty($this->findCss($page, '#loginOptions a'));
153+
$this->findCss($page, '#loginOptions a');
154154
// Assert that nothing was added to the user database:
155155
static::failIfDataExists('User data should not have been created in private user mode.');
156156
}

module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SavedSearchesTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
namespace VuFindTest\Mink;
3131

3232
use Behat\Mink\Element\Element;
33+
use Behat\Mink\Element\NodeElement;
3334

3435
/**
3536
* Mink saved searches test class.
@@ -95,7 +96,7 @@ public function testSaveSearch(): void
9596
$this->fillInAccountForm($page);
9697
$this->clickCss($page, 'input.btn.btn-primary');
9798

98-
$this->assertEquals(
99+
$this->assertSame(
99100
'Search saved successfully.',
100101
$this->findCssAndGetText($page, '.alert.alert-success')
101102
);
@@ -181,7 +182,7 @@ public function testSearchHistory(): void
181182
$this->hasElementsMatchingText($page, 'a', 'log in')
182183
);
183184
$this->waitForPageLoad($page);
184-
$this->assertNull($page->findLink('test'));
185+
$this->assertNotInstanceOf(NodeElement::class, $page->findLink('test'));
185186

186187
// Now log in and see if our saved search shows up (without making the
187188
// unsaved search go away):
@@ -210,7 +211,7 @@ public function testSearchHistory(): void
210211
// but saved search is still present:
211212
$this->findAndAssertLink($page, 'Purge unsaved searches')->click();
212213
$this->waitForPageLoad($page);
213-
$this->assertNull($page->findLink('foo \ bar'));
214+
$this->assertNotInstanceOf(NodeElement::class, $page->findLink('foo \ bar'));
214215
$this->assertEquals(
215216
'test',
216217
$this->findAndAssertLink($page, 'test')->getText()
@@ -332,7 +333,7 @@ public function testNotificationSettings(): void
332333
// At this point, our journals search should be in the unsaved list; let's
333334
// set it up for alerts and confirm that this auto-saves it.
334335
$select = $this->findCss($page, '#recent-searches ' . $scheduleSelector);
335-
$select->selectOption(7);
336+
$select->selectOption('7');
336337
$this->waitForPageLoad($page);
337338
$this->assertCount(
338339
2,
@@ -378,12 +379,12 @@ public function testNotificationsInSearchToolbar()
378379
// We should now be on a page with a schedule selector; let's pick something:
379380
$scheduleSelector = 'select[name="schedule"]';
380381
$select = $this->findCss($page, $scheduleSelector);
381-
$select->selectOption(7);
382+
$select->selectOption('7');
382383
$this->waitForPageLoad($page);
383384

384385
// Let's confirm that if we repeat the search, the alert will now be set:
385386
$page = $this->performSearch('employment');
386-
$this->assertEquals('Alert schedule: Weekly', $this->findCssAndGetText($page, '.searchtools .manageSchedule'));
387+
$this->assertSame('Alert schedule: Weekly', $this->findCssAndGetText($page, '.searchtools .manageSchedule'));
387388
}
388389

389390
/**
@@ -449,7 +450,7 @@ public function testNotificationsInSearchHistoryDeduplication()
449450

450451
// Let's set up our search for alerts and make sure it's handled correctly:
451452
$select = $this->findCss($page, '#recent-searches ' . $scheduleSelector);
452-
$select->selectOption(1);
453+
$select->selectOption('1');
453454
$this->waitForPageLoad($page);
454455

455456
// We should now be prompted to log in:

module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchFacetsTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected function facetListProcedure(
189189
$this->assertFullListFacetCount($page, 'count', $limit * 2, $exclusionActive);
190190

191191
$excludeControl = $exclusionActive ? 'Exclude matching results ' : '';
192-
$this->assertEquals(
192+
$this->assertSame(
193193
'Weird IDs 9 results 9 ' . $excludeControl
194194
. 'Fiction 7 results 7 ' . $excludeControl
195195
. 'The Study Of P|pes 1 results 1 ' . $excludeControl
@@ -225,7 +225,7 @@ protected function facetListProcedure(
225225
$this->clickCss($page, '#modal #facet-list-index .js-facet-next-page');
226226
$this->waitForPageLoad($page);
227227
$this->assertFullListFacetCount($page, 'index', $limit * 2, $exclusionActive);
228-
$this->assertEquals(
228+
$this->assertSame(
229229
'Fiction 7 results 7 ' . $excludeControl
230230
. 'The Study Of P|pes 1 results 1 ' . $excludeControl
231231
. 'The Study and Scor_ng of Dots.and-Dashes:Colons 1 results 1 ' . $excludeControl
@@ -482,7 +482,7 @@ function () use ($page) {
482482
// now clear the filter
483483
$this->clickCss($page, '#modal button[type="reset"]');
484484
$this->waitForPageLoad($page);
485-
$this->assertEquals(
485+
$this->assertSame(
486486
'Weird IDs 9 results 9 '
487487
. 'Fiction 7 results 7 '
488488
. 'The Study Of P|pes 1 results 1 '
@@ -689,7 +689,7 @@ public function testFilteredLightboxPagination(): void
689689
$this->waitForPageLoad($page);
690690
$items = $page->findAll('css', '#modal #facet-list-count .js-facet-item');
691691
$this->assertCount($limit * 2 - 1, $items);
692-
$this->assertEquals(
692+
$this->assertSame(
693693
'Weird IDs 9 results 9 '
694694
. 'The Study Of P|pes 1 results 1 '
695695
. 'The Study and Scor_ng of Dots.and-Dashes:Colons 1 results 1 '
@@ -1348,8 +1348,7 @@ public function testCheckboxFacets(bool $deferred, bool $counts): void
13481348

13491349
// format:Book is also a normal facet, but count should still be empty unless enabled:
13501350
$filter = $this->findCss($page, '.checkbox-filter');
1351-
$this->assertNotNull($filter);
1352-
$this->assertEquals('Books', $this->findCssAndGetText($filter->getParent(), '.icon-link__label'));
1351+
$this->assertSame('Books', $this->findCssAndGetText($filter->getParent(), '.icon-link__label'));
13531352
$this->assertEqualsWithTimeout(
13541353
$counts ? '9' : '',
13551354
function () use ($filter) {
@@ -1359,8 +1358,7 @@ function () use ($filter) {
13591358

13601359
// illustrated:Illustrated is only a checkbox facet:
13611360
$filter2 = $this->findCss($page, '.checkbox-filter', null, 1);
1362-
$this->assertNotNull($filter2);
1363-
$this->assertEquals('Illustrated', $this->findCssAndGetText($filter2->getParent(), '.icon-link__label'));
1361+
$this->assertSame('Illustrated', $this->findCssAndGetText($filter2->getParent(), '.icon-link__label'));
13641362
$illustratedCount = $this->findCssAndGetText($filter2->getParent(), '.avail-count');
13651363
$this->assertEquals($counts ? '2' : '', $illustratedCount);
13661364

@@ -1504,11 +1502,11 @@ protected function assertFilterIsStillThere(Element $page): void
15041502
/**
15051503
* Assert that the "reset filters" button is present.
15061504
*
1507-
* @param \Behat\Mink\Element\Element $page Mink page object
1505+
* @param Element $page Mink page object
15081506
*
15091507
* @return void
15101508
*/
1511-
protected function assertResetFiltersButton($page)
1509+
protected function assertResetFiltersButton(Element $page): void
15121510
{
15131511
$reset = $page->findAll('css', '.reset-filters-btn');
15141512
// The toggle bar has its own reset button, so we should have 2:
@@ -1593,7 +1591,7 @@ public function testMultiSelectOnAdvancedSearch(bool $changeLanguage, bool $incl
15931591

15941592
// A past bug would cause search terms to get duplicated after facets
15951593
// were applied; make sure the search remains as expected!
1596-
$this->assertEquals(
1594+
$this->assertSame(
15971595
'(All Fields:test AND All Fields:history)',
15981596
$this->findCssAndGetText($page, '.adv_search_terms strong')
15991597
);
@@ -1692,7 +1690,7 @@ public function testMultiFacetsSelectionAlways(): void
16921690
$page = $this->performSearch('building:weird_ids.mrc OR building:journals.mrc');
16931691
$sidebar = $this->findCss($page, '.sidebar');
16941692
$this->assertFalse($this->findCss($sidebar, '.js-user-selection-multi-filters')->isVisible());
1695-
$this->assertNotNull($sidebar->find('css', '.js-apply-multi-facets-selection'));
1693+
$this->findCss($sidebar, '.js-apply-multi-facets-selection');
16961694
}
16971695

16981696
/**

module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SsoTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function testLightboxLogin(): void
128128
$this->clickCss($page, '.record-nav .save-record');
129129

130130
// Login in lightbox
131-
$this->assertEquals('Institutional Login', $this->findCssAndGetText($page, '.modal-body .btn.btn-link'));
131+
$this->assertSame('Institutional Login', $this->findCssAndGetText($page, '.modal-body .btn.btn-link'));
132132
$this->clickCss($page, '.modal-body .btn.btn-link');
133133

134134
// Check if save form is in lightbox
@@ -139,7 +139,7 @@ public function testLightboxLogin(): void
139139
$this->closeLightbox($page);
140140

141141
// Check that we are still on the record page
142-
$this->assertEquals(
142+
$this->assertSame(
143143
'Journal of rational emotive therapy : the journal of the Institute for Rational-Emotive Therapy.',
144144
$this->findCssAndGetText($page, '.record .media-body h1')
145145
);
@@ -191,7 +191,7 @@ public function testExternalLogout(): void
191191

192192
// Check that login link is back:
193193
$session->reload();
194-
$this->assertNotEmpty($this->findCss($page, '#loginOptions a'));
194+
$this->findCss($page, '#loginOptions a');
195195
}
196196

197197
/**
@@ -208,7 +208,7 @@ protected function logoutAndAssertSuccess(): void
208208
$this->clickCss($page, '.logoutOptions a.logout');
209209

210210
// Check that login link is back
211-
$this->assertNotEmpty($this->findCss($page, '#loginOptions a'));
211+
$this->findCss($page, '#loginOptions a');
212212
}
213213

214214
/**

0 commit comments

Comments
 (0)