Skip to content

Commit

Permalink
Tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc committed Sep 24, 2024
1 parent c2283a2 commit d0e8a44
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 26 deletions.
3 changes: 2 additions & 1 deletion includes/MslsAdminIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class MslsAdminIcon {
* @param string $type
*/
public function __construct( ?string $type = null ) {
$this->type = esc_attr( $type );
$this->type = $type;

$this->set_path();
}

Expand Down
7 changes: 3 additions & 4 deletions tests/phpunit/MslsUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ protected function setUp(): void {

\Mockery::namedMock( 'WooCommerce', \stdClass::class );

Functions\when( '__' )->returnArg();
Functions\when( 'esc_attr' )->returnArg();
Functions\when( 'esc_html' )->returnArg();
Functions\when( 'esc_html__' )->returnArg();
Functions\when( 'esc_attr' )->returnArg();
Functions\when( 'esc_url' )->returnArg();
Functions\when( '__' )->returnArg();
Functions\when( 'wp_kses' )->returnArg();
Functions\when( 'wp_kses_post' )->returnArg();
Functions\when( 'sanitize_text_field' )->returnArg();
}


protected function tearDown(): void {
restore_error_handler();

Monkey\tearDown();
\Mockery::close();
Monkey\tearDown();

parent::tearDown();
}
Expand Down
4 changes: 0 additions & 4 deletions tests/phpunit/TestMslsLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ public function test_get_types(): void {
}

public function test_get_description(): void {
Functions\when( '__' )->returnArg();

$this->assertEquals( 'Flag and description', MslsLink::get_description() );
}

public function test_get_types_description(): void {
Functions\when( '__' )->returnArg();

$this->assertCount( 4, MslsLink::get_types_description() );
}

Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/TestMslsLinkImageOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
class TestMslsLinkImageOnly extends MslsUnitTestCase {

public function test_get_description_method(): void {
Functions\when( '__' )->returnArg();

$this->assertIsSTring( MslsLinkImageOnly::get_description() );
}
}
2 changes: 0 additions & 2 deletions tests/phpunit/TestMslsLinkTextImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
class TestMslsLinkTextImage extends MslsUnitTestCase {

public function test_get_description_method(): void {
Functions\when( '__' )->returnArg();

$this->assertIsSTring( MslsLinkTextImage::get_description() );
}
}
2 changes: 0 additions & 2 deletions tests/phpunit/TestMslsLinkTextOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
class TestMslsLinkTextOnly extends MslsUnitTestCase {

public function test_get_description_method(): void {
Functions\when( '__' )->returnArg();

$this->assertIsSTring( MslsLinkTextOnly::get_description() );
}
}
9 changes: 2 additions & 7 deletions tests/phpunit/TestMslsMetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
class TestMslsMetaBox extends MslsUnitTestCase {

protected function setUp(): void {
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 2 ) . '/' );
parent::setUp();

Functions\when( 'esc_attr' )->returnArg();
Functions\when( 'esc_html' )->returnArg();
Functions\when( 'esc_url' )->returnArg();
Functions\when( 'wp_kses' )->returnArg();
Functions\when( '__' )->returnArg();
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 2 ) . '/' );

$blog = \Mockery::mock( MslsBlog::class );
$blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' );
Expand Down Expand Up @@ -69,7 +65,6 @@ public function test_suggest(): void {
Functions\expect( 'filter_input' )->once()->with( INPUT_POST, MslsFields::FIELD_S, FILTER_SANITIZE_FULL_SPECIAL_CHARS )->andReturn( 17 );
Functions\expect( 'get_post_stati' )->once()->andReturn( array( 'pending', 'draft', 'future' ) );
Functions\expect( 'get_the_title' )->once()->andReturn( 'Test' );
Functions\expect( 'sanitize_text_field' )->times( 2 )->andReturnFirstArg();
Functions\expect( 'get_posts' )->once()->andReturn( array( $post ) );
Functions\expect( 'switch_to_blog' )->once();
Functions\expect( 'restore_current_blog' )->once();
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/TestMslsSqlCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class TestMslsSqlCacher extends MslsUnitTestCase {

protected function setUp(): void {
parent::setUp();

$wpdb = \Mockery::mock( \WPDB::class );

$wpdb->shouldReceive( 'prepare' )->andReturn( '' );
Expand All @@ -19,8 +21,6 @@ protected function setUp(): void {
public function test_create(): void {
global $wpdb;

Functions\expect( 'esc_attr' )->atLeast()->once()->andReturnFirstArg();

$wpdb = \Mockery::mock( \WPDB::class );

$this->assertInstanceOf( MslsSqlCacher::class, MslsSqlCacher::create( 'MslsSqlCacherTest', '' ) );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/WP_Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct( $id_base, $name, $widget_options = array(), $contro
* @return string ID attribute for `$field_name`.
*/
public function get_field_id( string $field_name ) {
return sprintf( 'field-id-%s', esc_attr( $field_name ) );
return sprintf( 'field-id-%s', $field_name );
}

/**
Expand All @@ -39,6 +39,6 @@ public function get_field_id( string $field_name ) {
* @return string Name attribute for `$field_name`.
*/
public function get_field_name( $field_name ) {
return sprintf( 'field-name-%s', esc_attr( $field_name ) );
return sprintf( 'field-name-%s', $field_name );
}
}

0 comments on commit d0e8a44

Please sign in to comment.