diff --git a/tests/phpunit/MslsUnitTestCase.php b/tests/phpunit/MslsUnitTestCase.php
index 1b711bc4..984a92d1 100644
--- a/tests/phpunit/MslsUnitTestCase.php
+++ b/tests/phpunit/MslsUnitTestCase.php
@@ -21,20 +21,22 @@ protected function setUp(): void {
\Mockery::namedMock( 'WooCommerce', \stdClass::class );
- Functions\when( 'esc_html' )->returnArg();
+ Functions\when( '__' )->returnArg();
Functions\when( 'esc_attr' )->returnArg();
+ Functions\when( 'esc_html' )->returnArg();
+ Functions\when( 'esc_html__' )->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();
+ Functions\when( 'wp_kses_allowed_html' )->justReturn( array() );
}
-
protected function tearDown(): void {
restore_error_handler();
- Monkey\tearDown();
\Mockery::close();
+ Monkey\tearDown();
parent::tearDown();
}
diff --git a/tests/phpunit/TestMslsAdmin.php b/tests/phpunit/TestMslsAdmin.php
index 547b6e27..55147243 100644
--- a/tests/phpunit/TestMslsAdmin.php
+++ b/tests/phpunit/TestMslsAdmin.php
@@ -373,7 +373,6 @@ function test_main_section(): void {
$obj = $this->get_sut();
Functions\expect( 'add_settings_field' )->times( 12 )->andReturnFirstArg();
- Functions\expect( 'esc_html__' )->times( 12 )->andReturnFirstArg();
$this->assertEquals( 12, $obj->main_section() );
}
@@ -382,7 +381,6 @@ function test_advanced_section(): void {
$obj = $this->get_sut();
Functions\expect( 'add_settings_field' )->times( 5 )->andReturnFirstArg();
- Functions\expect( 'esc_html__' )->times( 5 )->andReturnFirstArg();
$this->assertEquals( 5, $obj->advanced_section() );
}
diff --git a/tests/phpunit/TestMslsLink.php b/tests/phpunit/TestMslsLink.php
index 99bbe959..984cae66 100644
--- a/tests/phpunit/TestMslsLink.php
+++ b/tests/phpunit/TestMslsLink.php
@@ -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() );
}
diff --git a/tests/phpunit/TestMslsLinkImageOnly.php b/tests/phpunit/TestMslsLinkImageOnly.php
index f32f69ec..154777da 100644
--- a/tests/phpunit/TestMslsLinkImageOnly.php
+++ b/tests/phpunit/TestMslsLinkImageOnly.php
@@ -8,8 +8,6 @@
class TestMslsLinkImageOnly extends MslsUnitTestCase {
public function test_get_description_method(): void {
- Functions\when( '__' )->returnArg();
-
$this->assertIsSTring( MslsLinkImageOnly::get_description() );
}
}
diff --git a/tests/phpunit/TestMslsLinkTextImage.php b/tests/phpunit/TestMslsLinkTextImage.php
index 87cf961a..7719abf1 100644
--- a/tests/phpunit/TestMslsLinkTextImage.php
+++ b/tests/phpunit/TestMslsLinkTextImage.php
@@ -8,8 +8,6 @@
class TestMslsLinkTextImage extends MslsUnitTestCase {
public function test_get_description_method(): void {
- Functions\when( '__' )->returnArg();
-
$this->assertIsSTring( MslsLinkTextImage::get_description() );
}
}
diff --git a/tests/phpunit/TestMslsLinkTextOnly.php b/tests/phpunit/TestMslsLinkTextOnly.php
index 8a010ef1..72757b11 100644
--- a/tests/phpunit/TestMslsLinkTextOnly.php
+++ b/tests/phpunit/TestMslsLinkTextOnly.php
@@ -8,8 +8,6 @@
class TestMslsLinkTextOnly extends MslsUnitTestCase {
public function test_get_description_method(): void {
- Functions\when( '__' )->returnArg();
-
$this->assertIsSTring( MslsLinkTextOnly::get_description() );
}
}
diff --git a/tests/phpunit/TestMslsMetaBox.php b/tests/phpunit/TestMslsMetaBox.php
index 9b81955d..b14306e7 100644
--- a/tests/phpunit/TestMslsMetaBox.php
+++ b/tests/phpunit/TestMslsMetaBox.php
@@ -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' );
@@ -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();
diff --git a/tests/phpunit/TestMslsPostTag.php b/tests/phpunit/TestMslsPostTag.php
index 597ba8ef..c0598d74 100644
--- a/tests/phpunit/TestMslsPostTag.php
+++ b/tests/phpunit/TestMslsPostTag.php
@@ -7,6 +7,7 @@
use lloc\Msls\MslsBlog;
use lloc\Msls\MslsBlogCollection;
use lloc\Msls\MslsOptions;
+use lloc\Msls\MslsOptionsTax;
use lloc\Msls\MslsPostTag;
use lloc\Msls\MslsTaxonomy;
@@ -15,7 +16,7 @@ class TestMslsPostTag extends MslsUnitTestCase {
protected function setUp(): void {
parent::setUp();
- Functions\when( 'get_option' )->justReturn( array() );
+ Functions\when( 'get_option' )->justReturn( array( 'de_DE' => 42 ) );
Functions\expect( 'is_admin' )->andReturn( true );
Functions\expect( 'get_post_types' )->andReturn( array( 'post', 'page' ) );
@@ -31,7 +32,13 @@ protected function setUp(): void {
$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get' )->andReturn( $blogs );
-
+ $collection->shouldReceive( 'has_current_blog' )->andReturnTrue();
+ $collection->shouldReceive( 'get_current_blog' )->andReturn( $blogs[0] );
+ $collection->shouldReceive( 'get_blog_id' )->andReturnUsing(
+ function ( $language ) {
+ return $language === 'de_DE' ? 1 : null;
+ }
+ );
$this->test = new MslsPostTag( $options, $collection );
}
@@ -83,6 +90,9 @@ public function test_edit_input(): void {
$taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post' );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( array( 'taxonomy', 'post_tag' ) );
+ $term = \Mockery::mock( \WP_Term::class );
+ $term->name = 'test-term-name';
+
Functions\expect( 'msls_content_types' )->atLeast()->once()->andReturn( $taxonomy );
Functions\expect( 'get_queried_object_id' )->atLeast()->once()->andReturn( 42 );
Functions\expect( 'is_woocommerce' )->atLeast()->once()->andReturn( false );
@@ -91,6 +101,8 @@ public function test_edit_input(): void {
Functions\expect( 'add_query_arg' )->atLeast()->once()->andReturn( 'added_query_arg' );
Functions\expect( 'get_current_blog_id' )->atLeast()->once()->andReturn( 23 );
Functions\expect( 'get_admin_url' )->atLeast()->once()->andReturn( '/wp-admin/edit-tags.php' );
+ Functions\expect( 'get_term' )->atLeast()->once()->andReturn( $term );
+ Functions\expect( 'get_edit_term_link' )->atLeast()->once()->andReturn( 'edit_term_link' );
$output = '
@@ -100,11 +112,11 @@ public function test_edit_input(): void {
|
-
+
|
-
-
+
+
|
@@ -117,13 +129,10 @@ public function test_edit_input(): void {
|
';
$this->expectOutputString( $output );
-
- $tag = \Mockery::mock( \WP_Term::class );
-
- $this->test->edit_input( $tag, 'test' );
+ $this->test->edit_input( $term, 'test' );
// second call should not output anything
- $this->test->edit_input( $tag, 'test' );
+ $this->test->edit_input( $term, 'test' );
}
public function test_add_input(): void {
@@ -140,6 +149,7 @@ public function test_add_input(): void {
Functions\expect( 'add_query_arg' )->atLeast()->once()->andReturn( 'added_query_arg' );
Functions\expect( 'get_current_blog_id' )->atLeast()->once()->andReturn( 23 );
Functions\expect( 'get_admin_url' )->atLeast()->once()->andReturn( '/wp-admin/edit-tags.php' );
+ Functions\expect( 'get_term' )->atLeast()->once()->andReturnNull();
$output = '