Skip to content

Tests added #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/MslsMetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function render_options( $type, $msls_id ): string {
*
* @return string
*/
public function render_option( str $post_id, $msls_id ) {
public function render_option( $post_id, $msls_id ) {
return sprintf(
'<option value="%s" %s>%s</option>',
$post_id,
Expand Down
23 changes: 19 additions & 4 deletions tests/phpunit/TestMslsTaxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace lloc\MslsTests;

use Brain\Monkey\Functions;
use lloc\Msls\MslsFields;
use lloc\Msls\MslsOptions;
use lloc\Msls\MslsTaxonomy;

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

Functions\expect( 'msls_options' )->zeroOrMoreTimes()->andReturn( $options );

Functions\expect( 'apply_filters' )->atLeast()->once();

Functions\expect( 'get_taxonomies' )->atLeast()->once()->andReturn( array() );
Functions\expect( 'get_query_var' )->atLeast()->once()->with( 'taxonomy' )->andReturn( 'category' );

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

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

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

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

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

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

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

public function test_get_request(): void {
public function test_get_request_empty(): void {
Functions\expect( 'get_query_var' )->twice()->with( 'taxonomy' )->andReturn( 'category' );
Functions\expect( 'filter_has_var' )->twice()->with( INPUT_GET, MslsFields::FIELD_TAXONOMY )->andReturn( false );

$this->assertEquals( 'category', $this->get_test()->get_request() );
}

public function test_get_request_not_empty(): void {
$taxonomy = 'a_random_taxonomy';

Functions\expect( 'filter_has_var' )->twice()->with( INPUT_GET, MslsFields::FIELD_TAXONOMY )->andReturn( true );
Functions\expect( 'filter_input' )->twice()->with( INPUT_GET, MslsFields::FIELD_TAXONOMY, FILTER_SANITIZE_FULL_SPECIAL_CHARS )->andReturn( $taxonomy );

$this->assertEquals( $taxonomy, $this->get_test()->get_request() );
}
}
Loading