diff --git a/includes/MslsContentFilter.php b/includes/MslsContentFilter.php index e91bf78f..044778d7 100644 --- a/includes/MslsContentFilter.php +++ b/includes/MslsContentFilter.php @@ -4,7 +4,6 @@ class MslsContentFilter { - protected MslsOptions $options; public function __construct( MslsOptions $options ) { diff --git a/includes/MslsOutput.php b/includes/MslsOutput.php index 3ffa3702..accb0ff6 100644 --- a/includes/MslsOutput.php +++ b/includes/MslsOutput.php @@ -132,11 +132,7 @@ public function get_alternate_links() { * @return string */ public function __toString() { - $display = (int) $this->options->display; - $filter = false; - $exists = isset( $this->options->only_with_translation ); - - $arr = $this->get( $display, $filter, $exists ); + $arr = $this->get( $this->options->display, false, isset( $this->options->only_with_translation ) ); if ( empty( $arr ) ) { return apply_filters( 'msls_output_no_translation_found', '' ); } diff --git a/tests/phpunit/TestMslsAdminIcon.php b/tests/phpunit/TestMslsAdminIcon.php index 394555ce..09c75fec 100644 --- a/tests/phpunit/TestMslsAdminIcon.php +++ b/tests/phpunit/TestMslsAdminIcon.php @@ -7,7 +7,7 @@ class TestMslsAdminIcon extends MslsUnitTestCase { - protected string $admin_url = 'https://example.org/wp-admin/'; + protected string $admin_url = 'https://msls.co/wp-admin/'; protected string $lang = 'de_DE'; diff --git a/tests/phpunit/TestMslsAdminIconTaxonomy.php b/tests/phpunit/TestMslsAdminIconTaxonomy.php index d4e86a26..1ed003a0 100644 --- a/tests/phpunit/TestMslsAdminIconTaxonomy.php +++ b/tests/phpunit/TestMslsAdminIconTaxonomy.php @@ -13,7 +13,7 @@ class TestMslsAdminIconTaxonomy extends MslsUnitTestCase { protected function setUp(): void { parent::setUp(); - Functions\expect( 'add_query_arg' )->twice()->andReturn( 'https://example.org/added-args' ); + Functions\expect( 'add_query_arg' )->twice()->andReturn( 'https://msls.co/added-args' ); } public function test_get_img(): void { @@ -30,7 +30,7 @@ public function test_get_img(): void { } public function test_get_edit_new(): void { - $admin_url = 'https://example.org/wp-admin/?new_tag'; + $admin_url = 'https://msls.co/wp-admin/?new_tag'; Functions\expect( 'get_admin_url' )->once()->andReturn( $admin_url ); Functions\expect( 'get_current_blog_id' )->once()->andReturn( 1 ); diff --git a/tests/phpunit/TestMslsBlog.php b/tests/phpunit/TestMslsBlog.php index 707875fb..fabfbdc9 100644 --- a/tests/phpunit/TestMslsBlog.php +++ b/tests/phpunit/TestMslsBlog.php @@ -29,7 +29,7 @@ public function test_get_description(): void { } public function test_get_url_current(): void { - $url = 'https://example.org/'; + $url = 'https://msls.co/'; $option = \Mockery::mock( MslsOptions::class ); $option->shouldReceive( 'get_current_link' )->andReturn( $url ); @@ -43,7 +43,7 @@ public function test_get_url_current(): void { } public function test_get_frontpage(): void { - $url = 'https://example.org/'; + $url = 'https://msls.co/'; $option = \Mockery::mock( MslsOptions::class ); $option->shouldReceive( 'get_permalink' )->once()->andReturn( $url ); @@ -60,7 +60,7 @@ public function test_get_frontpage(): void { } public function test_get_url(): void { - $url = 'https://example.org/'; + $url = 'https://msls.co/'; $option = \Mockery::mock( MslsOptions::class ); $option->shouldReceive( 'get_permalink' )->once()->andReturn( $url ); @@ -86,7 +86,7 @@ public function test_get_alpha2(): void { } public function test_get_title(): void { - Functions\expect( 'add_query_arg' )->once()->andReturn( 'https://example.org/added-args' ); + Functions\expect( 'add_query_arg' )->once()->andReturn( 'https://msls.co/added-args' ); $this->assertEquals( 'Test it_IT', @@ -145,11 +145,11 @@ public function test_get_blavatar_lazy(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); Functions\expect( 'has_site_icon' )->once()->andReturn( true ); - Functions\expect( 'get_site_icon_url' )->twice()->andReturn( 'https://example.org/icons/abc.png' ); + Functions\expect( 'get_site_icon_url' )->twice()->andReturn( 'https://msls.co/icons/abc.png' ); Functions\expect( 'wp_lazy_loading_enabled' )->once()->andReturn( true ); $this->assertEquals( - '', + '', $this->get_blog()->get_blavatar() ); } @@ -158,11 +158,11 @@ public function test_get_blavatar(): void { Functions\expect( 'switch_to_blog' )->once(); Functions\expect( 'restore_current_blog' )->once(); Functions\expect( 'has_site_icon' )->once()->andReturn( true ); - Functions\expect( 'get_site_icon_url' )->twice()->andReturn( 'https://example.org/icons/abc.png' ); + Functions\expect( 'get_site_icon_url' )->twice()->andReturn( 'https://msls.co/icons/abc.png' ); Functions\expect( 'wp_lazy_loading_enabled' )->once()->andReturn( false ); $this->assertEquals( - '', + '', $this->get_blog()->get_blavatar() ); } diff --git a/tests/phpunit/TestMslsContentFilter.php b/tests/phpunit/TestMslsContentFilter.php index 6c1ac81a..1f445f6e 100644 --- a/tests/phpunit/TestMslsContentFilter.php +++ b/tests/phpunit/TestMslsContentFilter.php @@ -2,6 +2,7 @@ namespace lloc\MslsTests; +use Brain\Monkey\Filters; use Brain\Monkey\Functions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; @@ -44,12 +45,21 @@ public function test_content_filter_one_link() { $collection = \Mockery::mock( MslsBlogCollection::class ); $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array( $blog ) ); - $collection->shouldReceive( 'is_current_blog' )->once()->andReturn( true ); + $collection->shouldReceive( 'is_current_blog' )->once()->andReturn( false ); $options = \Mockery::mock( MslsOptions::class ); $options->shouldReceive( 'is_content_filter' )->andReturn( true ); - $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://lloc.de/wp-content/plugins/msls/flags/de.png' ); + $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); + $post = \Mockery::mock( 'WP_Post' ); + $post->post_status = 'publish'; + $post->post_type = 'post'; + + $post_object = \Mockery::mock( 'WP_Post_Type' ); + $post_object->rewrite['with_front'] = true; + + Functions\expect( 'get_post' )->once()->andReturn( $post ); + Functions\expect( 'get_post_type_object' )->once()->andReturn( $post_object ); Functions\expect( 'is_front_page' )->twice()->andReturn( false ); Functions\expect( 'is_admin' )->once()->andReturn( false ); Functions\expect( 'is_search' )->once()->andReturn( false ); @@ -61,16 +71,128 @@ public function test_content_filter_one_link() { Functions\expect( 'is_author' )->once()->andReturn( false ); Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); - Functions\expect( 'get_option' )->once()->andReturn( array() ); + Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) ); Functions\expect( 'is_singular' )->once()->andReturn( true ); Functions\expect( 'msls_options' )->once()->andReturn( $options ); Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); Functions\expect( 'get_permalink' )->once()->andReturn( 'https://msls.co/testpage/' ); + Functions\expect( 'switch_to_blog' )->once(); + Functions\expect( 'restore_current_blog' )->once(); + + $test = new MslsContentFilter( $options ); + + $content = '

Test>/p>'; + $expected = '

Test>/p>

This post is also available in Deutsch.

'; + $this->assertEquals( $expected, $test->content_filter( $content ) ); + } + + public function test_content_filter_two_links() { + $a = \Mockery::mock( MslsBlog::class ); + $a->shouldReceive( 'get_language' )->once()->andReturn( 'it_IT' ); + $a->shouldReceive( 'get_description' )->once()->andReturn( 'Italiano' ); + + $b = \Mockery::mock( MslsBlog::class ); + $b->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); + $b->shouldReceive( 'get_description' )->once()->andReturn( 'Deutsch' ); + + $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array( $a, $b ) ); + $collection->shouldReceive( 'is_current_blog' )->twice()->andReturn( false ); + + $options = \Mockery::mock( MslsOptions::class ); + $options->shouldReceive( 'is_content_filter' )->andReturn( true ); + $options->shouldReceive( 'get_flag_url' )->twice()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); + + $post = \Mockery::mock( 'WP_Post' ); + $post->post_status = 'publish'; + $post->post_type = 'post'; + + $post_object = \Mockery::mock( 'WP_Post_Type' ); + $post_object->rewrite['with_front'] = true; + + Functions\expect( 'get_post' )->twice()->andReturn( $post ); + Functions\expect( 'get_post_type_object' )->once()->andReturn( $post_object ); + Functions\expect( 'is_front_page' )->twice()->andReturn( false ); + Functions\expect( 'is_admin' )->once()->andReturn( false ); + Functions\expect( 'is_search' )->once()->andReturn( false ); + Functions\expect( 'is_404' )->once()->andReturn( false ); + Functions\expect( 'is_category' )->once()->andReturn( false ); + Functions\expect( 'is_tag' )->once()->andReturn( false ); + Functions\expect( 'is_tax' )->once()->andReturn( false ); + Functions\expect( 'is_date' )->once()->andReturn( false ); + Functions\expect( 'is_author' )->once()->andReturn( false ); + Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); + Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); + Functions\expect( 'get_option' )->once()->andReturn( + array( + 'de_DE' => 42, + 'it_IT' => 17, + ) + ); + Functions\expect( 'is_singular' )->once()->andReturn( true ); + Functions\expect( 'msls_options' )->once()->andReturn( $options ); + Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); + Functions\expect( 'get_permalink' )->twice()->andReturn( 'https://msls.co/de/testpage/' ); + Functions\expect( 'switch_to_blog' )->twice(); + Functions\expect( 'restore_current_blog' )->twice(); $test = new MslsContentFilter( $options ); $content = '

Test>/p>'; - $expected = '

Test>/p>

This post is also available in Deutsch.

'; + $expected = '

Test>/p>

This post is also available in Italiano and Deutsch.

'; + $this->assertEquals( $expected, $test->content_filter( $content ) ); + } + + public function test_content_filter_with_filter() { + $blog = \Mockery::mock( MslsBlog::class ); + $blog->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); + $blog->shouldReceive( 'get_description' )->once()->andReturn( 'Deutsch' ); + + $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array( $blog ) ); + $collection->shouldReceive( 'is_current_blog' )->once()->andReturn( false ); + + $options = \Mockery::mock( MslsOptions::class ); + $options->shouldReceive( 'is_content_filter' )->andReturn( true ); + $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); + + $post = \Mockery::mock( 'WP_Post' ); + $post->post_status = 'publish'; + $post->post_type = 'post'; + + $post_object = \Mockery::mock( 'WP_Post_Type' ); + $post_object->rewrite['with_front'] = true; + + Functions\expect( 'get_post' )->once()->andReturn( $post ); + Functions\expect( 'get_post_type_object' )->once()->andReturn( $post_object ); + Functions\expect( 'is_front_page' )->twice()->andReturn( false ); + Functions\expect( 'is_admin' )->once()->andReturn( false ); + Functions\expect( 'is_search' )->once()->andReturn( false ); + Functions\expect( 'is_404' )->once()->andReturn( false ); + Functions\expect( 'is_category' )->once()->andReturn( false ); + Functions\expect( 'is_tag' )->once()->andReturn( false ); + Functions\expect( 'is_tax' )->once()->andReturn( false ); + Functions\expect( 'is_date' )->once()->andReturn( false ); + Functions\expect( 'is_author' )->once()->andReturn( false ); + Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); + Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); + Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) ); + Functions\expect( 'is_singular' )->once()->andReturn( true ); + Functions\expect( 'msls_options' )->once()->andReturn( $options ); + Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); + Functions\expect( 'get_permalink' )->once()->andReturn( 'https://msls.co/testpage/' ); + Functions\expect( 'has_filter' )->once()->with( 'msls_filter_string' )->andReturn( true ); + Functions\expect( 'switch_to_blog' )->once(); + Functions\expect( 'restore_current_blog' )->once(); + + $test = new MslsContentFilter( $options ); + + $content = '

Test>/p>'; + $filter = 'This post is also available in Deutsch.'; + + Filters\expectApplied( 'msls_filter_string' )->once()->andReturn( $filter ); + + $expected = '

Test>/p>

' . $filter . '

'; $this->assertEquals( $expected, $test->content_filter( $content ) ); } } diff --git a/tests/phpunit/TestMslsCustomColumn.php b/tests/phpunit/TestMslsCustomColumn.php index 745a3b46..8ec3ba26 100644 --- a/tests/phpunit/TestMslsCustomColumn.php +++ b/tests/phpunit/TestMslsCustomColumn.php @@ -11,7 +11,7 @@ class TestMslsCustomColumn extends MslsUnitTestCase { public function test_th(): void { - Functions\expect( 'add_query_arg' )->twice()->andReturn( 'https://example.org/added-args' ); + Functions\expect( 'add_query_arg' )->twice()->andReturn( 'https://msls.co/added-args' ); Functions\expect( 'get_the_ID' )->twice()->andReturnValues( array( 1, 2 ) ); Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 2 ) . '/' ); diff --git a/tests/phpunit/TestMslsOptions.php b/tests/phpunit/TestMslsOptions.php index a84fc112..e2770c36 100644 --- a/tests/phpunit/TestMslsOptions.php +++ b/tests/phpunit/TestMslsOptions.php @@ -111,7 +111,7 @@ function test_get_order_method(): void { } function test_get_url_method(): void { - Functions\when( 'plugins_url' )->justReturn( 'https://lloc.de/wp-content/plugins' ); + Functions\when( 'plugins_url' )->justReturn( 'https://msls.co/wp-content/plugins' ); $obj = $this->get_test(); @@ -120,7 +120,7 @@ function test_get_url_method(): void { function test_get_flag_url_method(): void { Functions\when( 'is_admin' )->justReturn( true ); - Functions\when( 'plugins_url' )->justReturn( 'https://lloc.de/wp-content/plugins' ); + Functions\when( 'plugins_url' )->justReturn( 'https://msls.co/wp-content/plugins' ); Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 2 ) . '/' ); $obj = $this->get_test(); diff --git a/tests/phpunit/TestMslsOptionsPost.php b/tests/phpunit/TestMslsOptionsPost.php index c23b33af..a907823e 100644 --- a/tests/phpunit/TestMslsOptionsPost.php +++ b/tests/phpunit/TestMslsOptionsPost.php @@ -50,8 +50,8 @@ public function test_get_postlink_post_is_published(): void { } public function test_get_current_link(): void { - Functions\expect( 'get_permalink' )->once()->andReturn( 'https://example.org/a-post' ); + Functions\expect( 'get_permalink' )->once()->andReturn( 'https://msls.co/a-post' ); - $this->assertEquals( 'https://example.org/a-post', $this->test->get_current_link() ); + $this->assertEquals( 'https://msls.co/a-post', $this->test->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOptionsQuery.php b/tests/phpunit/TestMslsOptionsQuery.php index 57fd345e..fb20fa69 100644 --- a/tests/phpunit/TestMslsOptionsQuery.php +++ b/tests/phpunit/TestMslsOptionsQuery.php @@ -85,7 +85,7 @@ public function test_create_is_null(): void { } public function test_current_get_postlink(): void { - $home_url = 'https://example.org/'; + $home_url = 'https://msls.co/'; Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) ); Functions\expect( 'home_url' )->once()->andReturn( $home_url ); diff --git a/tests/phpunit/TestMslsOptionsQueryAuthor.php b/tests/phpunit/TestMslsOptionsQueryAuthor.php index ab02ee53..7c724562 100644 --- a/tests/phpunit/TestMslsOptionsQueryAuthor.php +++ b/tests/phpunit/TestMslsOptionsQueryAuthor.php @@ -28,8 +28,8 @@ public function test_has_value_false(): void { } public function test_get_current_link_method(): void { - Functions\expect( 'get_author_posts_url' )->once()->andReturn( 'https://example.org/queried-author' ); + Functions\expect( 'get_author_posts_url' )->once()->andReturn( 'https://msls.co/queried-author' ); - $this->assertEquals( 'https://example.org/queried-author', $this->get_test( 42 )->get_current_link() ); + $this->assertEquals( 'https://msls.co/queried-author', $this->get_test( 42 )->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOptionsQueryDay.php b/tests/phpunit/TestMslsOptionsQueryDay.php index b21faec2..232e37ca 100644 --- a/tests/phpunit/TestMslsOptionsQueryDay.php +++ b/tests/phpunit/TestMslsOptionsQueryDay.php @@ -30,8 +30,8 @@ public function test_has_value(): void { } public function test_get_current_link(): void { - Functions\expect( 'get_day_link' )->once()->andReturn( 'https://example.org/queried-day' ); + Functions\expect( 'get_day_link' )->once()->andReturn( 'https://msls.co/queried-day' ); - $this->assertEquals( 'https://example.org/queried-day', $this->get_test( 2015, 07, 02 )->get_current_link() ); + $this->assertEquals( 'https://msls.co/queried-day', $this->get_test( 2015, 07, 02 )->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOptionsQueryMonth.php b/tests/phpunit/TestMslsOptionsQueryMonth.php index 020b98cc..434a16bd 100644 --- a/tests/phpunit/TestMslsOptionsQueryMonth.php +++ b/tests/phpunit/TestMslsOptionsQueryMonth.php @@ -30,8 +30,8 @@ public function test_has_value_false(): void { } public function test_get_current_link(): void { - Functions\expect( 'get_month_link' )->once()->andReturn( 'https://example.org/queried-month' ); + Functions\expect( 'get_month_link' )->once()->andReturn( 'https://msls.co/queried-month' ); - $this->assertEquals( 'https://example.org/queried-month', $this->get_test( 2015, 7 )->get_current_link() ); + $this->assertEquals( 'https://msls.co/queried-month', $this->get_test( 2015, 7 )->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOptionsQueryPostType.php b/tests/phpunit/TestMslsOptionsQueryPostType.php index f9fc270c..2f32ed4e 100644 --- a/tests/phpunit/TestMslsOptionsQueryPostType.php +++ b/tests/phpunit/TestMslsOptionsQueryPostType.php @@ -41,8 +41,8 @@ public function test_has_value_not_existing(): void { } public function test_get_current_link(): void { - Functions\expect( 'get_post_type_archive_link' )->once()->andReturn( 'https://example.org/queried-posttype' ); + Functions\expect( 'get_post_type_archive_link' )->once()->andReturn( 'https://msls.co/queried-posttype' ); - $this->assertEquals( 'https://example.org/queried-posttype', $this->test->get_current_link() ); + $this->assertEquals( 'https://msls.co/queried-posttype', $this->test->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOptionsQueryYear.php b/tests/phpunit/TestMslsOptionsQueryYear.php index f398baa3..0156255b 100644 --- a/tests/phpunit/TestMslsOptionsQueryYear.php +++ b/tests/phpunit/TestMslsOptionsQueryYear.php @@ -30,8 +30,8 @@ public function test_has_value_false(): void { } public function test_get_current_link_method(): void { - Functions\expect( 'get_year_link' )->once()->andReturn( 'https://example.org/queried-year' ); + Functions\expect( 'get_year_link' )->once()->andReturn( 'https://msls.co/queried-year' ); - $this->assertEquals( 'https://example.org/queried-year', $this->get_test( 2015 )->get_current_link() ); + $this->assertEquals( 'https://msls.co/queried-year', $this->get_test( 2015 )->get_current_link() ); } } diff --git a/tests/phpunit/TestMslsOutput.php b/tests/phpunit/TestMslsOutput.php index 5d89dfe7..54013c04 100644 --- a/tests/phpunit/TestMslsOutput.php +++ b/tests/phpunit/TestMslsOutput.php @@ -6,6 +6,7 @@ use Brain\Monkey\Functions; use lloc\Msls\MslsBlog; use lloc\Msls\MslsBlogCollection; +use lloc\Msls\MslsContentFilter; use lloc\Msls\MslsOptions; use lloc\Msls\MslsOptionsPost; use lloc\Msls\MslsOutput; @@ -13,6 +14,8 @@ class TestMslsOutput extends MslsUnitTestCase { protected function setUp(): void { + parent::setUp(); + $options = \Mockery::mock( MslsOptions::class ); $collection = \Mockery::mock( MslsBlogCollection::class ); @@ -62,7 +65,6 @@ public function test_get_alternate_links_two_url() { Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - Functions\expect( 'esc_attr' )->times( 3 )->andReturnFirstArg(); Filters\expectApplied( 'mlsl_output_get_alternate_links_arr' )->once(); @@ -129,17 +131,144 @@ public function test_get_alternate_links_one_url() { Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); Functions\expect( 'get_option' )->once()->andReturn( array() ); - Functions\expect( 'esc_attr' )->twice()->andReturnFirstArg(); Filters\expectApplied( 'mlsl_output_get_alternate_links_default' )->once(); $this->assertEquals( '', $this->test->get_alternate_links() ); } - public function test___toString() { - $this->assertIsSTring( $this->test->__toString() ); - $this->assertIsSTring( strval( $this->test ) ); - $this->assertEquals( $this->test->__toString(), strval( $this->test ) ); + public function test___toString_no_translation() { + $expected = 'Example'; + + Filters\expectApplied( 'msls_output_no_translation_found' )->once()->andReturn( $expected ); + $this->assertEquals( $expected, strval( $this->test ) ); + } + + public function test___toString_output() { + $blog = \Mockery::mock( MslsBlog::class ); + $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); + $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); + + $options = \Mockery::mock( MslsOptions::class ); + $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); + + $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); + $collection->shouldReceive( 'is_current_blog' )->andReturn( false ); + + Functions\expect( 'is_admin' )->once()->andReturn( false ); + Functions\expect( 'is_front_page' )->once()->andReturn( false ); + Functions\expect( 'is_search' )->once()->andReturn( false ); + Functions\expect( 'is_404' )->once()->andReturn( false ); + Functions\expect( 'is_category' )->once()->andReturn( false ); + Functions\expect( 'is_tag' )->once()->andReturn( false ); + Functions\expect( 'is_tax' )->once()->andReturn( false ); + Functions\expect( 'is_date' )->once()->andReturn( false ); + Functions\expect( 'is_author' )->once()->andReturn( false ); + Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); + Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); + Functions\expect( 'get_option' )->once()->andReturn( array() ); + Functions\expect( 'switch_to_blog' )->once(); + Functions\expect( 'restore_current_blog' )->once(); + Functions\expect( 'home_url' )->once()->andReturnFirstArg(); + + $test = new MslsOutput( $options, $collection ); + + $this->assertEquals( 'de_DE Deutsch', strval( $test ) ); + } + + public function test___toString_current_blog() { + $blog = \Mockery::mock( MslsBlog::class ); + $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); + $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); + + $options = \Mockery::mock( MslsOptions::class ); + $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); + + $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); + $collection->shouldReceive( 'is_current_blog' )->andReturn( true ); + + Functions\expect( 'is_admin' )->once()->andReturn( false ); + Functions\expect( 'is_front_page' )->once()->andReturn( false ); + Functions\expect( 'is_search' )->once()->andReturn( false ); + Functions\expect( 'is_404' )->once()->andReturn( false ); + Functions\expect( 'is_category' )->once()->andReturn( false ); + Functions\expect( 'is_tag' )->once()->andReturn( false ); + Functions\expect( 'is_tax' )->once()->andReturn( false ); + Functions\expect( 'is_date' )->once()->andReturn( false ); + Functions\expect( 'is_author' )->once()->andReturn( false ); + Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); + Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); + Functions\expect( 'get_option' )->once()->andReturn( array() ); + Functions\expect( 'get_permalink' )->once()->andReturn( 'https://msls.co/de/testpage/' ); + + $expected = 'de_DE Deutsch'; + + $this->assertEquals( $expected, strval( new MslsOutput( $options, $collection ) ) ); + } + + public function test___toString_filter() { + $blog = \Mockery::mock( MslsBlog::class ); + $blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' ); + $blog->shouldReceive( 'get_description' )->andReturn( 'Deutsch' ); + + $options = \Mockery::mock( MslsOptions::class ); + $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); + + $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); + $collection->shouldReceive( 'is_current_blog' )->andReturn( true ); + + Functions\expect( 'is_admin' )->once()->andReturn( false ); + Functions\expect( 'is_front_page' )->once()->andReturn( false ); + Functions\expect( 'is_search' )->once()->andReturn( false ); + Functions\expect( 'is_404' )->once()->andReturn( false ); + Functions\expect( 'is_category' )->once()->andReturn( false ); + Functions\expect( 'is_tag' )->once()->andReturn( false ); + Functions\expect( 'is_tax' )->once()->andReturn( false ); + Functions\expect( 'is_date' )->once()->andReturn( false ); + Functions\expect( 'is_author' )->once()->andReturn( false ); + Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); + Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); + Functions\expect( 'get_option' )->once()->andReturn( array() ); + Functions\expect( 'get_permalink' )->once()->andReturn( 'https://msls.co/de/testpage/' ); + Functions\expect( 'has_filter' )->once()->with( 'msls_output_get' )->andReturn( true ); + + $expected = ' de_DEDeutsch'; + Filters\expectApplied( 'msls_output_get' )->once()->andReturn( $expected ); + + $this->assertEquals( $expected, strval( new MslsOutput( $options, $collection ) ) ); + } + + public function test_get_not_fulfilled() { + $blog = \Mockery::mock( MslsBlog::class ); + $blog->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); + // $blog->shouldReceive( 'get_description' )->once()->andReturn( 'Deutsch' ); + + $options = \Mockery::mock( MslsOptions::class ); + $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://msls.co/wp-content/plugins/msls/flags/de.png' ); + + $collection = \Mockery::mock( MslsBlogCollection::class ); + $collection->shouldReceive( 'get_filtered' )->andReturn( array( $blog ) ); + $collection->shouldReceive( 'is_current_blog' )->andReturn( false ); + + Functions\expect( 'is_admin' )->once()->andReturn( false ); + Functions\expect( 'is_front_page' )->once()->andReturn( false ); + Functions\expect( 'is_search' )->once()->andReturn( false ); + Functions\expect( 'is_404' )->once()->andReturn( false ); + Functions\expect( 'is_category' )->once()->andReturn( false ); + Functions\expect( 'is_tag' )->once()->andReturn( false ); + Functions\expect( 'is_tax' )->once()->andReturn( false ); + Functions\expect( 'is_date' )->once()->andReturn( false ); + Functions\expect( 'is_author' )->once()->andReturn( false ); + Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); + Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); + Functions\expect( 'get_option' )->once()->andReturn( array() ); + Functions\expect( 'switch_to_blog' )->once(); + Functions\expect( 'restore_current_blog' )->once(); + + $this->assertEquals( array(), ( new MslsOutput( $options, $collection ) )->get( 0, false, true ) ); } public function test_get_tags(): void { diff --git a/tests/phpunit/TestMslsPlugin.php b/tests/phpunit/TestMslsPlugin.php index 34c767cb..d95a70c1 100644 --- a/tests/phpunit/TestMslsPlugin.php +++ b/tests/phpunit/TestMslsPlugin.php @@ -12,7 +12,7 @@ class TestMslsPlugin extends MslsUnitTestCase { function test_admin_menu_without_autocomplete(): void { Functions\expect( 'is_admin_bar_showing' )->once()->andReturnTrue(); Functions\expect( 'wp_enqueue_style' )->twice(); - Functions\expect( 'plugins_url' )->twice()->andReturn( 'https://lloc.de/wp-content/plugins' ); + Functions\expect( 'plugins_url' )->twice()->andReturn( 'https://msls.co/wp-content/plugins' ); $options = \Mockery::mock( MslsOptions::class ); @@ -24,7 +24,7 @@ function test_admin_menu_without_autocomplete(): void { function test_admin_menu_with_autocomplete(): void { Functions\expect( 'is_admin_bar_showing' )->once()->andReturnTrue(); Functions\expect( 'wp_enqueue_style' )->twice(); - Functions\expect( 'plugins_url' )->times( 3 )->andReturn( 'https://lloc.de/wp-content/plugins' ); + Functions\expect( 'plugins_url' )->times( 3 )->andReturn( 'https://msls.co/wp-content/plugins' ); Functions\expect( 'wp_enqueue_script' )->once(); $options = \Mockery::mock( MslsOptions::class );