Skip to content

Commit f302e85

Browse files
authored
Merge pull request #331 from lloc/refactoring-version-2-8
Tests added
2 parents d886d73 + e838916 commit f302e85

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

includes/MslsMetaBox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function render_options( $type, $msls_id ): string {
270270
*
271271
* @return string
272272
*/
273-
public function render_option( str $post_id, $msls_id ) {
273+
public function render_option( $post_id, $msls_id ) {
274274
return sprintf(
275275
'<option value="%s" %s>%s</option>',
276276
$post_id,

tests/phpunit/TestMslsTaxonomy.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace lloc\MslsTests;
44

55
use Brain\Monkey\Functions;
6+
use lloc\Msls\MslsFields;
67
use lloc\Msls\MslsOptions;
78
use lloc\Msls\MslsTaxonomy;
89

@@ -20,11 +21,8 @@ public function get_test( bool $exluded = false ): MslsTaxonomy {
2021
$options->shouldReceive( 'is_excluded' )->andReturn( $exluded );
2122

2223
Functions\expect( 'msls_options' )->zeroOrMoreTimes()->andReturn( $options );
23-
2424
Functions\expect( 'apply_filters' )->atLeast()->once();
25-
2625
Functions\expect( 'get_taxonomies' )->atLeast()->once()->andReturn( array() );
27-
Functions\expect( 'get_query_var' )->atLeast()->once()->with( 'taxonomy' )->andReturn( 'category' );
2826

2927
return new MslsTaxonomy();
3028
}
@@ -37,27 +35,44 @@ public function test_acl_request_included(): void {
3735

3836
Functions\when( 'get_taxonomy' )->justReturn( $taxonomy );
3937
Functions\when( 'current_user_can' )->justReturn( true );
38+
Functions\expect( 'get_query_var' )->twice()->with( 'taxonomy' )->andReturn( 'category' );
4039

4140
$this->assertEquals( 'category', $this->get_test()->acl_request() );
4241
}
4342

4443
public function test_acl_request_excluded(): void {
44+
Functions\expect( 'get_query_var' )->once()->with( 'taxonomy' )->andReturn( 'category' );
4545
$this->assertEquals( '', $this->get_test( true )->acl_request() );
4646
}
4747

4848
public function test_get_post_type(): void {
49+
Functions\expect( 'get_query_var' )->once()->with( 'taxonomy' )->andReturn( 'category' );
4950
$this->assertEquals( '', $this->get_test()->get_post_type() );
5051
}
5152

5253
public function test_is_post_type(): void {
54+
Functions\expect( 'get_query_var' )->once()->with( 'taxonomy' )->andReturn( 'category' );
5355
$this->assertFalse( $this->get_test()->is_post_type() );
5456
}
5557

5658
public function test_is_taxonomy(): void {
59+
Functions\expect( 'get_query_var' )->once()->with( 'taxonomy' )->andReturn( 'category' );
5760
$this->assertTrue( $this->get_test()->is_taxonomy() );
5861
}
5962

60-
public function test_get_request(): void {
63+
public function test_get_request_empty(): void {
64+
Functions\expect( 'get_query_var' )->twice()->with( 'taxonomy' )->andReturn( 'category' );
65+
Functions\expect( 'filter_has_var' )->twice()->with( INPUT_GET, MslsFields::FIELD_TAXONOMY )->andReturn( false );
66+
6167
$this->assertEquals( 'category', $this->get_test()->get_request() );
6268
}
69+
70+
public function test_get_request_not_empty(): void {
71+
$taxonomy = 'a_random_taxonomy';
72+
73+
Functions\expect( 'filter_has_var' )->twice()->with( INPUT_GET, MslsFields::FIELD_TAXONOMY )->andReturn( true );
74+
Functions\expect( 'filter_input' )->twice()->with( INPUT_GET, MslsFields::FIELD_TAXONOMY, FILTER_SANITIZE_FULL_SPECIAL_CHARS )->andReturn( $taxonomy );
75+
76+
$this->assertEquals( $taxonomy, $this->get_test()->get_request() );
77+
}
6378
}

0 commit comments

Comments
 (0)