1
+ <?php
2
+ /**
3
+ * Class CSS
4
+ *
5
+ * @package gutenberg-blocks
6
+ */
7
+
8
+ use ThemeIsle \OtterPro \Server \Live_Search_Server ;
9
+ use Yoast \PHPUnitPolyfills \Polyfills \AssertEqualsCanonicalizing ;
10
+ use Yoast \PHPUnitPolyfills \Polyfills \AssertNotEqualsCanonicalizing ;
11
+
12
+ /**
13
+ * Live Search Test Case.
14
+ */
15
+ class TestLiveSearch extends WP_UnitTestCase
16
+ {
17
+ /**
18
+ * Set up the test.
19
+ */
20
+ public function set_up () {
21
+ parent ::set_up ();
22
+
23
+ register_post_type ( 'otter_shop_coupon ' , array (
24
+ 'public ' => false ,
25
+ 'label ' => 'Shop Coupon ' ,
26
+ ) );
27
+
28
+ register_post_type ( 'otter_shop_product ' , array (
29
+ 'public ' => true ,
30
+ 'label ' => 'Shop Product ' ,
31
+ ) );
32
+
33
+ register_post_type ( 'otter_page ' , array (
34
+ 'public ' => true ,
35
+ 'exclude_from_search ' => true ,
36
+ 'label ' => 'Otter Page ' ,
37
+ ) );
38
+ }
39
+
40
+ /**
41
+ * Tear down the test.
42
+ */
43
+ public function tear_dow () {
44
+ unregister_post_type ( 'otter_shop_coupon ' );
45
+ unregister_post_type ( 'otter_shop_product ' );
46
+ unregister_post_type ( 'otter_page ' );
47
+ parent ::tear_down ();
48
+ }
49
+
50
+ /**
51
+ * Test live search prepare query function.
52
+ */
53
+ public function test_live_search_prepare_query () {
54
+ $ live_search = new Live_Search_Server ();
55
+
56
+ $ search_query = $ live_search ->prepare_search_query ( 'test ' , '' );
57
+ $ this ->assertEquals ( 'test ' , $ search_query ['s ' ] );
58
+ $ this ->assertEquals ( '' , $ search_query ['post_type ' ] );
59
+
60
+ $ search_query = $ live_search ->prepare_search_query ( 'test ' , 'otter_shop_product ' );
61
+ $ this ->assertEquals ( 'test ' , $ search_query ['s ' ] );
62
+ $ this ->assertEquals ( array ('otter_shop_product ' ), $ search_query ['post_type ' ] );
63
+
64
+ $ search_query = $ live_search ->prepare_search_query ( 'test ' , 'otter_shop_coupon ' );
65
+ $ this ->assertEquals ( 'test ' , $ search_query ['s ' ] );
66
+ $ this ->assertEquals ( array (), $ search_query ['post_type ' ] ); // Non-public post type are filtered out.
67
+
68
+ $ search_query = $ live_search ->prepare_search_query ( 'test ' , 'otter_page ' );
69
+ $ this ->assertEquals ( 'test ' , $ search_query ['s ' ] );
70
+ $ this ->assertEquals ( array (), $ search_query ['post_type ' ] ); // Exclude from search post type are filtered out.
71
+
72
+ $ search_query = $ live_search ->prepare_search_query ( 'test ' , array ('otter_shop_product ' , 'otter_shop_coupon ' , 'otter_page ' ) );
73
+ $ this ->assertEquals ( 'test ' , $ search_query ['s ' ] );
74
+ $ this ->assertEquals ( array ('otter_shop_product ' ), $ search_query ['post_type ' ] ); // Keep only the public post type.
75
+ }
76
+ }
0 commit comments