|
| 1 | +<?php declare( strict_types=1 ); |
| 2 | + |
| 3 | +namespace lloc\MslsTests; |
| 4 | + |
| 5 | +use Brain\Monkey\Functions; |
| 6 | +use lloc\Msls\MslsBlog; |
| 7 | +use lloc\Msls\MslsBlogCollection; |
| 8 | +use lloc\Msls\MslsContentFilter; |
| 9 | +use lloc\Msls\MslsOptions; |
| 10 | + |
| 11 | +use lloc\Msls\MslsPlugin; |
| 12 | + |
| 13 | +class TestMslsContentFilter extends MslsUnitTestCase { |
| 14 | + |
| 15 | + protected function provide_content_filter_data(): array { |
| 16 | + return array( |
| 17 | + array( 'Test', 'Test', true, false, false ), |
| 18 | + array( 'Test', 'Test', false, false, false ), |
| 19 | + array( 'Test', 'Test', false, true, false ), |
| 20 | + array( 'Test', 'Test', false, false, true ), |
| 21 | + array( 'Test', 'Test', true, true, true ), |
| 22 | + ); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * @dataProvider provide_content_filter_data |
| 27 | + */ |
| 28 | + public function test_content_filter_empty( string $content, string $expected, bool $is_front_page, bool $is_singular, bool $is_content_filter ) { |
| 29 | + Functions\when( 'is_front_page' )->justReturn( $is_front_page ); |
| 30 | + Functions\when( 'is_singular' )->justReturn( $is_singular ); |
| 31 | + |
| 32 | + $options = \Mockery::mock( MslsOptions::class ); |
| 33 | + $options->shouldReceive( 'is_content_filter' )->andReturn( $is_content_filter ); |
| 34 | + |
| 35 | + $test = new MslsContentFilter( $options ); |
| 36 | + |
| 37 | + $this->assertEquals( $expected, $test->content_filter( $content ) ); |
| 38 | + } |
| 39 | + |
| 40 | + public function test_content_filter_one_link() { |
| 41 | + $blog = \Mockery::mock( MslsBlog::class ); |
| 42 | + $blog->shouldReceive( 'get_language' )->once()->andReturn( 'de_DE' ); |
| 43 | + $blog->shouldReceive( 'get_description' )->once()->andReturn( 'Deutsch' ); |
| 44 | + |
| 45 | + $collection = \Mockery::mock( MslsBlogCollection::class ); |
| 46 | + $collection->shouldReceive( 'get_filtered' )->once()->andReturn( array( $blog ) ); |
| 47 | + $collection->shouldReceive( 'is_current_blog' )->once()->andReturn( true ); |
| 48 | + |
| 49 | + $options = \Mockery::mock( MslsOptions::class ); |
| 50 | + $options->shouldReceive( 'is_content_filter' )->andReturn( true ); |
| 51 | + $options->shouldReceive( 'get_flag_url' )->once()->andReturn( 'https://lloc.de/wp-content/plugins/msls/flags/de.png' ); |
| 52 | + |
| 53 | + Functions\expect( 'is_front_page' )->twice()->andReturn( false ); |
| 54 | + Functions\expect( 'is_admin' )->once()->andReturn( false ); |
| 55 | + Functions\expect( 'is_search' )->once()->andReturn( false ); |
| 56 | + Functions\expect( 'is_404' )->once()->andReturn( false ); |
| 57 | + Functions\expect( 'is_category' )->once()->andReturn( false ); |
| 58 | + Functions\expect( 'is_tag' )->once()->andReturn( false ); |
| 59 | + Functions\expect( 'is_tax' )->once()->andReturn( false ); |
| 60 | + Functions\expect( 'is_date' )->once()->andReturn( false ); |
| 61 | + Functions\expect( 'is_author' )->once()->andReturn( false ); |
| 62 | + Functions\expect( 'is_post_type_archive' )->once()->andReturn( false ); |
| 63 | + Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 ); |
| 64 | + Functions\expect( 'get_option' )->once()->andReturn( array() ); |
| 65 | + Functions\expect( 'is_singular' )->once()->andReturn( true ); |
| 66 | + Functions\expect( 'msls_options' )->once()->andReturn( $options ); |
| 67 | + Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection ); |
| 68 | + Functions\expect( 'get_permalink' )->once()->andReturn( 'https://msls.co/testpage/' ); |
| 69 | + |
| 70 | + $test = new MslsContentFilter( $options ); |
| 71 | + |
| 72 | + $content = '<p>Test>/p>'; |
| 73 | + $expected = '<p>Test>/p><p id="msls">This post is also available in <a href="https://msls.co/testpage/" title="Deutsch" class="current_language">Deutsch</a>.</p>'; |
| 74 | + $this->assertEquals( $expected, $test->content_filter( $content ) ); |
| 75 | + } |
| 76 | +} |
0 commit comments