|
11 | 11 | */
|
12 | 12 | class TestMslsOptionsTax extends MslsUnitTestCase {
|
13 | 13 |
|
| 14 | + protected $woo; |
| 15 | + |
14 | 16 | protected function setUp(): void {
|
15 | 17 | parent::setUp();
|
16 | 18 |
|
17 |
| - Functions\expect( 'get_option' )->once()->andReturn( array() ); |
| 19 | + Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) ); |
18 | 20 |
|
19 | 21 | $this->test = new MslsOptionsTax( 0 );
|
20 | 22 | }
|
21 | 23 |
|
22 | 24 | public function test_get_tax_query(): void {
|
23 |
| - $this->assertIsString( $this->test->get_tax_query() ); |
| 25 | + Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); |
| 26 | + |
| 27 | + $this->assertEquals( '', $this->test->get_tax_query() ); |
| 28 | + } |
| 29 | + |
| 30 | + public function test_get_tax_query_woo(): void { |
| 31 | + global $wp_query; |
| 32 | + |
| 33 | + $expected = 'taxonomy_query_string_1'; |
| 34 | + $wp_query = (object) array( |
| 35 | + 'tax_query' => (object) array( |
| 36 | + 'queries' => array( |
| 37 | + 1 => array( 'taxonomy' => $expected ), |
| 38 | + ), |
| 39 | + ), |
| 40 | + ); |
| 41 | + |
| 42 | + Functions\expect( 'is_woocommerce' )->once()->andReturn( true ); |
| 43 | + |
| 44 | + $this->assertEquals( $expected, $this->test->get_tax_query( array() ) ); |
| 45 | + } |
| 46 | + |
| 47 | + public function test_get_tax_query_set(): void { |
| 48 | + global $wp_query; |
| 49 | + |
| 50 | + $expected = 'taxonomy_query_string_0'; |
| 51 | + $wp_query = (object) array( |
| 52 | + 'tax_query' => (object) array( |
| 53 | + 'queries' => array( |
| 54 | + 0 => array( 'taxonomy' => $expected ), |
| 55 | + ), |
| 56 | + ), |
| 57 | + ); |
| 58 | + |
| 59 | + Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); |
| 60 | + |
| 61 | + $this->assertEquals( $expected, $this->test->get_tax_query( array() ) ); |
24 | 62 | }
|
25 | 63 |
|
26 | 64 | public function test_get_postlink(): void {
|
27 |
| - $this->assertIsString( $this->test->get_postlink( 'de_DE' ) ); |
| 65 | + Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); |
| 66 | + |
| 67 | + $this->assertEquals( '', $this->test->get_postlink( 'de_DE' ) ); |
| 68 | + } |
| 69 | + |
| 70 | + public function test_get_postlink_empty(): void { |
| 71 | + Functions\expect( 'is_woocommerce' )->never(); |
| 72 | + |
| 73 | + $this->assertEquals( '', $this->test->get_postlink( 'it_IT' ) ); |
28 | 74 | }
|
29 | 75 |
|
30 | 76 | public function test_get_current_link(): void {
|
31 | 77 | $this->assertIsString( $this->test->get_current_link() );
|
32 | 78 | }
|
33 | 79 |
|
34 | 80 | public function test_get_term_link(): void {
|
35 |
| - $this->assertIsString( $this->test->get_term_link( 42 ) ); |
| 81 | + global $wp_query; |
| 82 | + |
| 83 | + $wp_query = (object) array( |
| 84 | + 'tax_query' => (object) array( |
| 85 | + 'queries' => array( |
| 86 | + 0 => array( 'taxonomy' => 'taxonomy_query_string_0' ), |
| 87 | + ), |
| 88 | + ), |
| 89 | + ); |
| 90 | + |
| 91 | + $expected = 'http://example.com/term_link'; |
| 92 | + |
| 93 | + Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); |
| 94 | + Functions\expect( 'get_term_link' )->once()->andReturn( $expected ); |
| 95 | + |
| 96 | + $this->assertEquals( $expected, $this->test->get_term_link( 42 ) ); |
| 97 | + } |
| 98 | + |
| 99 | + public function test_get_term_link_wp_error(): void { |
| 100 | + global $wp_query; |
| 101 | + |
| 102 | + $wp_query = (object) array( |
| 103 | + 'tax_query' => (object) array( |
| 104 | + 'queries' => array( |
| 105 | + 0 => array( 'taxonomy' => 'taxonomy_query_string_0' ), |
| 106 | + ), |
| 107 | + ), |
| 108 | + ); |
| 109 | + |
| 110 | + $wp_error = \Mockery::mock( 'WP_Error' ); |
| 111 | + |
| 112 | + Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); |
| 113 | + Functions\expect( 'get_term_link' )->once()->andReturn( $wp_error ); |
| 114 | + |
| 115 | + $this->assertEquals( '', $this->test->get_term_link( 42 ) ); |
| 116 | + } |
| 117 | + |
| 118 | + public function test_get_term_link_empty(): void { |
| 119 | + Functions\expect( 'is_woocommerce' )->once()->andReturn( false ); |
| 120 | + |
| 121 | + $this->assertEquals( '', $this->test->get_term_link( 42 ) ); |
36 | 122 | }
|
37 | 123 | }
|
0 commit comments