From 5f4247b2d48a09b9478697b35be5a44a927e1f4f Mon Sep 17 00:00:00 2001 From: Brian Moses Hall Date: Tue, 11 Nov 2025 16:10:55 -0500 Subject: [PATCH 1/3] Add some more silly tests to ls --- ls/t/LS/Query/Facets.t | 98 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 ls/t/LS/Query/Facets.t diff --git a/ls/t/LS/Query/Facets.t b/ls/t/LS/Query/Facets.t new file mode 100644 index 000000000..4cf321c4e --- /dev/null +++ b/ls/t/LS/Query/Facets.t @@ -0,0 +1,98 @@ +use strict; +use warnings; + +use Data::Dumper; +use Encode; +use Test::More; + +use lib "$ENV{SDRROOT}/ls/lib"; +use lib "$ENV{SDRROOT}/slip-lib"; +use lib "$ENV{SDRROOT}/mdp-lib"; + +use Auth::Auth; +use Context; +use Database; +use LS::PIFiller::Advanced; +use LS::FacetConfig; +use LS::Query::Facets; +use Utils; + + +### THE MINDLESS SETUP BOILERPLATE +# copied from cgi/ls +my $C = new Context; +my $db_user = $ENV{'MARIADB_USER'} || 'ht_testing'; +my $db = new Database($db_user); + $C->set_object('Database', $db); +my $config = new MdpConfig( + Utils::get_uber_config_path('ls'), + $ENV{SDRROOT} . "/ls/lib/Config/global.conf", + $ENV{SDRROOT} . "/ls/lib/Config/local.conf" + ); +$C->set_object('MdpConfig', $config); +my $AB_test_config_filename = $ENV{SDRROOT} . '/ls/lib/Config/AB_test_config'; +my $AB_test_config = $config = Config::Tiny->read($AB_test_config_filename); +ASSERT($AB_test_config, qq{Error in testing config file $AB_test_config_filename: } . Config::Tiny::errstr); +# 1 disables checking object name +$C->set_object('AB_test_config', $AB_test_config, 1); +my $facet_config = new LS::FacetConfig($C, $ENV{SDRROOT} . "/ls/lib/Config/facetconfig.pl"); +$C->set_object('FacetConfig', $facet_config); +my $auth = new Auth::Auth($C); +$C->set_object('Auth', $auth); + +my $AB = 'A'; + +subtest 'get_Solr_query_string' => sub { + # Mindlessly copied from test/testQueries.pl + my $query_config = { + solr_start_row => 0, + solr_num_rows => 2, + query_type => 'full_text' + }; + subtest 'advanced search' => sub { + subtest 'two terms' => sub { + my $cgi = CGI->new; + $C->set_object('CGI', $cgi); + $cgi->param('adv', '1'); + + $cgi->param('field1', 'ocr'); + $cgi->param('anyall1', 'all'); + $cgi->param('q1', 'search1'); + + $cgi->param('op1', 'AND'); + + $cgi->param('field2', 'author'); + $cgi->param('anyall2', 'all'); + $cgi->param('q2', 'search2'); + + $cgi->param('op2', 'AND'); + my $facets = new LS::Query::Facets($C, '', undef, $query_config); + my $query_string = $facets->get_Solr_query_string($C, $AB); + ok($query_string =~ m/AND\s+_query/, 'result is not parenthesized'); + }; + + subtest 'two terms separated by gap' => sub { + my $cgi = CGI->new; + $C->set_object('CGI', $cgi); + $cgi->param('adv', '1'); + + $cgi->param('field1', 'ocr'); + $cgi->param('anyall1', 'all'); + $cgi->param('q1', 'search1'); + + $cgi->param('op1', 'AND'); + + $cgi->param('field4', 'author'); + $cgi->param('anyall4', 'all'); + $cgi->param('q4', 'search2'); + + $cgi->param('op3', 'AND'); + + my $facets = new LS::Query::Facets($C, '', undef, $query_config); + my $query_string = $facets->get_Solr_query_string($C, $AB); + ok($query_string =~ m/\) AND \(/); + }; + }; +}; + +done_testing; \ No newline at end of file From c47019e2050dde81d0f11c2ad8675cb4e5ad85f6 Mon Sep 17 00:00:00 2001 From: Brian Moses Hall Date: Thu, 13 Nov 2025 12:12:31 -0500 Subject: [PATCH 2/3] - Clean up tests - Run ls tests as part of perl-test --- common/docker/perl.yml | 2 +- docker-compose.yml | 2 +- ls/t/LS/Query/Facets.t | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/common/docker/perl.yml b/common/docker/perl.yml index ec0153d1f..4fb2c2a32 100644 --- a/common/docker/perl.yml +++ b/common/docker/perl.yml @@ -20,4 +20,4 @@ services: mysql-sdr: condition: service_healthy working_dir: "/htapps/babel" - command: "prove -r imgsrv/t mdp-lib/t" + command: "prove -r imgsrv/t ls/t mdp-lib/t" diff --git a/docker-compose.yml b/docker-compose.yml index 2ade5165a..16376ad7a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -76,7 +76,7 @@ services: extends: file: common/docker/perl.yml service: perl - command: "prove -r imgsrv/t mdp-lib/t" + command: "prove -r imgsrv/t ls/t mdp-lib/t" profiles: - testing diff --git a/ls/t/LS/Query/Facets.t b/ls/t/LS/Query/Facets.t index 4cf321c4e..e08a36869 100644 --- a/ls/t/LS/Query/Facets.t +++ b/ls/t/LS/Query/Facets.t @@ -42,6 +42,11 @@ $C->set_object('Auth', $auth); my $AB = 'A'; + +# NOTE: this is an almost completely useless test that illustrates the scaffolding +# we need to run better ones in the future. +# The resulting query strings are complex. I don't really know what to do with them +# beyond poking around with ugly regexes. subtest 'get_Solr_query_string' => sub { # Mindlessly copied from test/testQueries.pl my $query_config = { @@ -54,34 +59,30 @@ subtest 'get_Solr_query_string' => sub { my $cgi = CGI->new; $C->set_object('CGI', $cgi); $cgi->param('adv', '1'); - + $cgi->param('field1', 'ocr'); $cgi->param('anyall1', 'all'); $cgi->param('q1', 'search1'); - - $cgi->param('op1', 'AND'); - + $cgi->param('field2', 'author'); $cgi->param('anyall2', 'all'); $cgi->param('q2', 'search2'); - + $cgi->param('op2', 'AND'); my $facets = new LS::Query::Facets($C, '', undef, $query_config); my $query_string = $facets->get_Solr_query_string($C, $AB); - ok($query_string =~ m/AND\s+_query/, 'result is not parenthesized'); + ok($query_string =~ m/AND\s+_query/, 'result is not parenthesized because q3 and q4 are not present'); }; subtest 'two terms separated by gap' => sub { my $cgi = CGI->new; $C->set_object('CGI', $cgi); $cgi->param('adv', '1'); - + $cgi->param('field1', 'ocr'); $cgi->param('anyall1', 'all'); $cgi->param('q1', 'search1'); - - $cgi->param('op1', 'AND'); - + $cgi->param('field4', 'author'); $cgi->param('anyall4', 'all'); $cgi->param('q4', 'search2'); @@ -90,7 +91,7 @@ subtest 'get_Solr_query_string' => sub { my $facets = new LS::Query::Facets($C, '', undef, $query_config); my $query_string = $facets->get_Solr_query_string($C, $AB); - ok($query_string =~ m/\) AND \(/); + ok($query_string =~ m/\) AND \(/, 'result is parenthesized because `(1 op2 2) op3 (3 op4 4)`'); }; }; }; From 25bd09d5bd0a2a59fbaee3b19ed122a911767b0c Mon Sep 17 00:00:00 2001 From: Brian Moses Hall Date: Fri, 14 Nov 2025 09:52:39 -0500 Subject: [PATCH 3/3] Add newline at end of new test file. --- ls/t/LS/Query/Facets.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ls/t/LS/Query/Facets.t b/ls/t/LS/Query/Facets.t index e08a36869..69870e6ef 100644 --- a/ls/t/LS/Query/Facets.t +++ b/ls/t/LS/Query/Facets.t @@ -96,4 +96,4 @@ subtest 'get_Solr_query_string' => sub { }; }; -done_testing; \ No newline at end of file +done_testing;