LP#1505286: add pgTAP tests
[Evergreen.git] / Open-ILS / src / sql / Pg / t / search_limit_facet_fetch.pg
1 BEGIN;
2
3 SELECT plan(4);
4
5 INSERT INTO biblio.record_entry (id, last_xact_id, marc)
6 VALUES (999999998, 'pgtap', '<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim">
7   <leader>00531nam a2200157 a 4500</leader>
8   <controlfield tag="005">20080729170300.0</controlfield>
9   <controlfield tag="008">      t19981999enka              0 eng  </controlfield>
10   <datafield tag="245" ind1="1" ind2="4">
11     <subfield code="a">test-value</subfield>
12   </datafield>
13   <datafield tag="650" ind1=" " ind2=" ">
14     <subfield code="a">subject 1</subfield>
15   </datafield>
16   <datafield tag="650" ind1=" " ind2=" ">
17     <subfield code="a">subject 2</subfield>
18   </datafield>
19   <datafield tag="650" ind1=" " ind2=" ">
20     <subfield code="a">subject 3</subfield>
21   </datafield>
22   <datafield tag="650" ind1=" " ind2=" ">
23     <subfield code="a">subject 4</subfield>
24   </datafield>
25   <datafield tag="650" ind1=" " ind2=" ">
26     <subfield code="a">subject 5</subfield>
27   </datafield>
28   <datafield tag="650" ind1=" " ind2=" ">
29     <subfield code="a">subject 6</subfield>
30   </datafield>
31   <datafield tag="650" ind1=" " ind2=" ">
32     <subfield code="a">subject 7</subfield>
33   </datafield>
34   <datafield tag="650" ind1=" " ind2=" ">
35     <subfield code="a">subject 8</subfield>
36   </datafield>
37   <datafield tag="650" ind1=" " ind2=" ">
38     <subfield code="a">subject 9</subfield>
39   </datafield>
40   <datafield tag="650" ind1=" " ind2=" ">
41     <subfield code="a">subject 10</subfield>
42   </datafield>
43 </record>');
44
45 -- These tests assume that one subject facet field is defined
46
47 SELECT is(
48     (
49         SELECT COUNT(*) FROM search.facets_for_record_set('{}', '{999999998}')
50     ),
51     10::BIGINT,
52     '10 subject facets retrieved'
53 );
54
55 UPDATE config.global_flag SET value = '5' WHERE name = 'search.max_facets_per_field';
56 SELECT is(
57     (
58         SELECT COUNT(*) FROM search.facets_for_record_set('{}', '{999999998}')
59     ),
60     5::BIGINT,
61     '5 subject facets retrieved after setting limit'
62 );
63
64 SELECT is(
65     (
66         SELECT COUNT(*) FROM (
67             SELECT search.facets_for_metarecord_set('{}', array_accum(metarecord))
68             FROM metabib.metarecord_source_map
69             WHERE source = 999999998
70         ) x
71     ),
72     5::BIGINT,
73     'Works for metarecord sets too'
74 );
75
76 SELECT is(
77     (
78         SELECT COUNT(*) FROM search.facets_for_record_set('{subject}', '{999999998}')
79     ),
80     0::BIGINT,
81     'Zero subject facets retrieved after excluding subject facets'
82 );
83
84 SELECT * FROM finish();
85 ROLLBACK;