Skip to content

Commit

Permalink
Review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Feb 15, 2024
1 parent b111fe7 commit b60f6e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
11 changes: 5 additions & 6 deletions module/VuFind/src/VuFindTest/Feature/AutocompleteTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,19 @@ public function getAndAssertFirstAutocompleteValue(Element $page, string $text):
* For the provided search, assert the first autocomplete value and return the
* associated page element.
*
* @param string $search Search term(s)
* @param string $expected First expected Autocomplete suggestion
* @param ?string $type Search type (null for default)
* @param ?Element $page Existing page to use for searching (will load Search/Home if not provided)
* @param Element $page Page to use for searching
* @param string $search Search term(s)
* @param string $expected First expected Autocomplete suggestion
* @param ?string $type Search type (null for default)
*
* @return NodeElement
*/
protected function assertAutocompleteValueAndReturnItem(
Element $page,
string $search,
string $expected,
?string $type = null,
?Element $page = null,
): NodeElement {
$page ??= $this->getSearchHomePage();
if ($type) {
$this->findCssAndSetValue($page, '#searchForm_type', $type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class AutocompleteTest extends \VuFindTest\Integration\MinkTestCase
public function testBasicAutocomplete(): void
{
$session = $this->getMinkSession();
$acItem = $this->assertAutocompleteValueAndReturnItem('fake doi test', 'Fake DOI test 1');
$page = $this->getSearchHomePage($session);
$acItem = $this->assertAutocompleteValueAndReturnItem($page, 'fake doi test', 'Fake DOI test 1');
$acItem->click();
$page = $session->getPage();
$this->waitForPageLoad($page);
$this->assertEquals(
$this->getVuFindUrl() . '/Search/Results?lookfor=%22Fake+DOI+test+1%22&type=AllFields',
Expand All @@ -68,12 +68,13 @@ public function testBasicAutocomplete(): void
public function testBasicAutocompleteQuoteEscaping(): void
{
$session = $this->getMinkSession();
$page = $this->getSearchHomePage($session);
$acItem = $this->assertAutocompleteValueAndReturnItem(
$page,
'millers mechanical',
'Letterhead enclosure: "The Millers Mechanical Battlefield: world\'s greatest exhibition", [1920?].'
);
$acItem->click();
$page = $session->getPage();
$this->waitForPageLoad($page);
$this->assertEquals(
$this->getVuFindUrl() . '/Search/Results?lookfor=%22Letterhead+enclosure%3A+'
Expand All @@ -91,9 +92,9 @@ public function testBasicAutocompleteQuoteEscaping(): void
public function testBasicAutocompleteForNonDefaultField(): void
{
$session = $this->getMinkSession();
$acItem = $this->assertAutocompleteValueAndReturnItem('jsto', 'JSTOR (Organization)', 'Author');
$page = $this->getSearchHomePage($session);
$acItem = $this->assertAutocompleteValueAndReturnItem($page, 'jsto', 'JSTOR (Organization)', 'Author');
$acItem->click();
$page = $session->getPage();
$this->waitForPageLoad($page);
$this->assertEquals(
$this->getVuFindUrl() . '/Search/Results?lookfor=%22JSTOR+%28Organization%29%22&type=Author',
Expand All @@ -114,11 +115,11 @@ public function testMultipleAutocompletesInSingleSession(): void
$page = $this->getSearchHomePage($session);

// First do a search in All Fields
$this->assertAutocompleteValueAndReturnItem('jsto', 'Al Gore', null, $page);
$this->assertAutocompleteValueAndReturnItem($page, 'jsto', 'Al Gore');

// Now repeat the same search in Author, making sure we get the right author match, and not a cached
// All Fields value!
$acItem = $this->assertAutocompleteValueAndReturnItem('jsto', 'JSTOR (Organization)', 'Author', $page);
$acItem = $this->assertAutocompleteValueAndReturnItem($page, 'jsto', 'JSTOR (Organization)', 'Author');
$acItem->click();
$this->waitForPageLoad($page);
$this->assertEquals(
Expand All @@ -138,9 +139,9 @@ public function testDisablingAutocompleteAutosubmit(): void
['searches' => ['Autocomplete' => ['auto_submit' => false]]]
);
$session = $this->getMinkSession();
$acItem = $this->assertAutocompleteValueAndReturnItem('fake doi test', 'Fake DOI test 1');
$page = $this->getSearchHomePage($session);
$acItem = $this->assertAutocompleteValueAndReturnItem($page, 'fake doi test', 'Fake DOI test 1');
$acItem->click();
$page = $session->getPage();
$this->waitForPageLoad($page);
$this->assertEquals(
'"Fake DOI test 1"',
Expand Down Expand Up @@ -183,9 +184,9 @@ public function testAutocompleteInCombinedSearchbox(): void
{
$this->changeConfigs($this->getCombinedSearchHandlersConfigs());
$session = $this->getMinkSession();
$acItem = $this->assertAutocompleteValueAndReturnItem('fake doi test', 'Fake DOI test 1');
$page = $this->getSearchHomePage($session);
$acItem = $this->assertAutocompleteValueAndReturnItem($page, 'fake doi test', 'Fake DOI test 1');
$acItem->click();
$page = $session->getPage();
$this->waitForPageLoad($page);
$this->assertEquals(
$this->getVuFindUrl() . '/Search/Results?lookfor=%22Fake+DOI+test+1%22&type=AllFields',
Expand All @@ -202,9 +203,9 @@ public function testAuthorAutocompleteInCombinedSearchbox(): void
{
$this->changeConfigs($this->getCombinedSearchHandlersConfigs());
$session = $this->getMinkSession();
$acItem = $this->assertAutocompleteValueAndReturnItem('jsto', 'JSTOR (Organization)', 'VuFind:Solr|Author');
$page = $this->getSearchHomePage($session);
$acItem = $this->assertAutocompleteValueAndReturnItem($page, 'jsto', 'JSTOR (Organization)', 'VuFind:Solr|Author');
$acItem->click();
$page = $session->getPage();
$this->waitForPageLoad($page);
$this->assertEquals(
$this->getVuFindUrl() . '/Search/Results?lookfor=%22JSTOR+%28Organization%29%22&type=Author',
Expand All @@ -221,13 +222,14 @@ public function testAuthorityAutocompleteInCombinedSearchbox(): void
{
$this->changeConfigs($this->getCombinedSearchHandlersConfigs());
$session = $this->getMinkSession();
$page = $this->getSearchHomePage($session);
$acItem = $this->assertAutocompleteValueAndReturnItem(
$page,
'roy',
'Royal Dublin Society',
'VuFind:SolrAuth|MainHeading'
);
$acItem->click();
$page = $session->getPage();
$this->waitForPageLoad($page);
$this->assertEquals(
$this->getVuFindUrl() . '/Authority/Search?lookfor=%22Royal+Dublin+Society%22&type=MainHeading',
Expand All @@ -246,12 +248,12 @@ public function testAlphaBrowseAutocompleteInCombinedSearchbox(): void
$config['searchbox']['General']['includeAlphaBrowse'] = true;
$this->changeConfigs($config);
$session = $this->getMinkSession();
$page = $this->getSearchHomePage($session);
$vufindUrl = $this->getVuFindUrl();
$basePath = parse_url($vufindUrl, PHP_URL_PATH);
$handler = "External:$basePath/Alphabrowse/Home?source=title&from=";
$acItem = $this->assertAutocompleteValueAndReturnItem('test pu', 'test publication 20001', $handler);
$acItem = $this->assertAutocompleteValueAndReturnItem($page, 'test pu', 'test publication 20001', $handler);
$acItem->click();
$page = $session->getPage();
$this->waitForPageLoad($page);
$this->assertEquals(
$vufindUrl . '/Alphabrowse/Home?source=title&from=test+publication+20001',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public function testTagAutocomplete(): void
{
$session = $this->getMinkSession();
$page = $this->getSearchHomePage($session);
$acItem = $this->assertAutocompleteValueAndReturnItem('fiv', 'five', 'tag', $page);
$acItem = $this->assertAutocompleteValueAndReturnItem($page, 'fiv', 'five', 'tag');
$acItem->click();
$this->waitForPageLoad($page);
$this->assertEquals(
Expand Down

0 comments on commit b60f6e1

Please sign in to comment.