From 4c377c71e80d5b122455d6da005a50d3ad72a56b Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Tue, 4 Feb 2025 06:59:50 -0500 Subject: [PATCH 1/2] Trivial: more semantic assertions in test. --- .../VuFindTest/View/Helper/Root/GoogleTagManagerTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/GoogleTagManagerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/GoogleTagManagerTest.php index 8beb44abb99..318261988bd 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/GoogleTagManagerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/GoogleTagManagerTest.php @@ -52,8 +52,8 @@ class GoogleTagManagerTest extends \PHPUnit\Framework\TestCase public function testHeadCode(): void { $output = $this->renderGTMHeadCode('fakeContainerId'); - $this->assertTrue(false !== strstr($output, 'gtm.js')); - $this->assertTrue(false !== strstr($output, 'fakeContainerId')); + $this->assertStringContainsString('gtm.js', $output); + $this->assertStringContainsString('fakeContainerId', $output); } /** @@ -64,8 +64,8 @@ public function testHeadCode(): void public function testBodyCode(): void { $output = $this->renderGTMBodyCode('fakeContainerId'); - $this->assertTrue(false !== strstr($output, 'ns.html')); - $this->assertTrue(false !== strstr($output, 'fakeContainerId')); + $this->assertStringContainsString('ns.html', $output); + $this->assertStringContainsString('fakeContainerId', $output); } /** From 05718cde3c78564ac44cb4a1d1a8ec64bf2a98d8 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Tue, 4 Feb 2025 10:59:59 -0500 Subject: [PATCH 2/2] [VUFIND-1722] Add tests for web index (#4205) --- build.xml | 15 +++ import/raw.properties | 9 ++ import/xsl/raw.xsl | 5 + .../src/VuFindTest/Mink/WebSearchTest.php | 106 ++++++++++++++++++ tests/data/website/solr.xml | 35 ++++++ 5 files changed, 170 insertions(+) create mode 100644 import/raw.properties create mode 100644 import/xsl/raw.xsl create mode 100644 module/VuFind/tests/integration-tests/src/VuFindTest/Mink/WebSearchTest.php create mode 100644 tests/data/website/solr.xml diff --git a/build.xml b/build.xml index 05465ff127d..3133c588eff 100644 --- a/build.xml +++ b/build.xml @@ -654,6 +654,7 @@ + @@ -941,6 +942,20 @@ return [ + + + + + + + + + + + + + + diff --git a/import/raw.properties b/import/raw.properties new file mode 100644 index 00000000000..644e8e2a3b7 --- /dev/null +++ b/import/raw.properties @@ -0,0 +1,9 @@ +; XSLT Import Settings for passing raw XML through to Solr +[General] +; REQUIRED: Name of XSLT file to apply. Path is relative to the import/xsl directory +; of the VuFind installation (or your local override directory). +xslt = raw.xsl + +; XSLT parameters -- any key/value pairs set here will be passed as parameters to +; the XSLT file, allowing local values to be set without modifying XSLT code. +[Parameters] diff --git a/import/xsl/raw.xsl b/import/xsl/raw.xsl new file mode 100644 index 00000000000..d191055c958 --- /dev/null +++ b/import/xsl/raw.xsl @@ -0,0 +1,5 @@ + + + + + diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/WebSearchTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/WebSearchTest.php new file mode 100644 index 00000000000..c4202d34609 --- /dev/null +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/WebSearchTest.php @@ -0,0 +1,106 @@ + + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ + +namespace VuFindTest\Mink; + +use function intval; + +/** + * Mink web search test class. + * + * @category VuFind + * @package Tests + * @author Demian Katz + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +class WebSearchTest extends \VuFindTest\Integration\MinkTestCase +{ + /** + * Data provider for testWebSearch() + * + * @return array[] + */ + public static function webSearchProvider(): array + { + return [ + 'blank search' => ['', 3, '', ['Fact', 'Fantasy', 'Fiction']], + 'search in full text' => ['"second record"', 1, 'second record', ['Fact']], + 'search in description' => ['three', 1, 'three', ['Fantasy']], + ]; + } + + /** + * Test performing a Web search + * + * @param string $query Search query + * @param int $expectedCount Expected search result count + * @param string $expectedFirstHighlight Expected first highlighted text on page + * @param string[] $expectedSubjectFacets Expected subject facet values + * + * @return void + * + * @dataProvider webSearchProvider + */ + public function testWebSearch( + string $query, + int $expectedCount, + string $expectedFirstHighlight, + array $expectedSubjectFacets + ): void { + // Perform the search: + $session = $this->getMinkSession(); + $session->visit($this->getVuFindUrl() . '/Web'); + $page = $session->getPage(); + $this->findCssAndSetValue($page, '#searchForm_lookfor', $query); + $this->findCss($page, '.btn-primary')->click(); + $this->waitForPageLoad($page); + + // Confirm the result count: + $this->assertEquals( + $expectedCount, + intval($this->findCssAndGetText($page, '.js-search-stats strong', index: 1)) + ); + + // Confirm highlighting: + if ($expectedFirstHighlight) { + $this->assertEquals($expectedFirstHighlight, $this->findCssAndGetText($page, '#result0 mark')); + } + + // Confirm facet values: + $subjectText = []; + $subjects = $page->findAll('css', '#side-panel-subject .facet-value'); + foreach ($subjects as $subject) { + $subjectText[] = $subject->getText(); + } + $this->assertEquals($expectedSubjectFacets, $subjectText); + } +} diff --git a/tests/data/website/solr.xml b/tests/data/website/solr.xml new file mode 100644 index 00000000000..06fd8a069be --- /dev/null +++ b/tests/data/website/solr.xml @@ -0,0 +1,35 @@ + + + 001 + This is the content of the first record. + This is the description of record number one. + one first + First Web Page + http://localhost/1 + Test Pages + Fake Link + Fiction + + + 002 + This is the content of the second record. + This is the description of record number two. + two second + Second Web Page + http://localhost/2 + Test Pages + Fake Link + Fact + + + 003 + This is the content of the third record. + This is the description of record number three. + three third + Third Web Page + http://localhost/3 + Test Pages + Fake Link + Fantasy + +