|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace lloc\MslsTests\ContentImport; |
| 4 | + |
| 5 | +use lloc\Msls\ContentImport\AttachmentPathFinder; |
| 6 | +use lloc\MslsTests\MslsUnitTestCase; |
| 7 | +use Brain\Monkey\Functions; |
| 8 | + |
| 9 | +class TestAttachmentPathFinder extends MslsUnitTestCase { |
| 10 | + |
| 11 | + public function setUp(): void { |
| 12 | + parent::setUp(); |
| 13 | + |
| 14 | + $this->test = new AttachmentPathFinder(); |
| 15 | + } |
| 16 | + |
| 17 | + public function dataprovider_filter_srcset() { |
| 18 | + $image_src = 'http://example.com/image.jpg'; |
| 19 | + $msls_imported = array( |
| 20 | + 'blog' => 1, |
| 21 | + 'post' => 1, |
| 22 | + ); |
| 23 | + $source_post = (object) array( 'guid' => 'http://example.com/image.jpg' ); |
| 24 | + |
| 25 | + return array( |
| 26 | + array( array(), $image_src, 0, array() ), |
| 27 | + array( array(), $image_src, '', array() ), |
| 28 | + array( array(), $image_src, null, array() ), |
| 29 | + array( array(), $image_src, 1, array(), null, 1, 1 ), |
| 30 | + array( array(), $image_src, 1, array(), array( 'random' => 'item' ), 1, 1 ), |
| 31 | + array( array( array( 'url' => $image_src ) ), $image_src, 1, array( array( 'url' => $image_src ) ), $msls_imported, 1, 0, 1 ), |
| 32 | + array( array( array( 'url' => $image_src ) ), $image_src, 1, array( array( 'url' => $image_src ) ), $msls_imported, 1, 0, 1, $source_post ), |
| 33 | + array( array( array( 'url' => 'http://example.com/image-300x300.jpg' ) ), $image_src, 1, array( array( 'url' => 'http://example.com/image-300x300.jpg' ) ), $msls_imported, 1, 0, 1, $source_post ), |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @dataProvider dataprovider_filter_srcset |
| 39 | + */ |
| 40 | + public function test_filter_srcset( $source, $imageSrc, $attachmentId, $expected, $msls_imported = null, $times_gpm = 0, $time_dpm = 0, $times_gbp = 0, $blog_post = false ) { |
| 41 | + Functions\expect( 'get_post_meta' )->times( $times_gpm )->andReturn( $msls_imported ); |
| 42 | + Functions\expect( 'delete_post_meta' )->times( $time_dpm ); |
| 43 | + Functions\expect( 'get_blog_post' )->times( $times_gbp )->andReturn( $blog_post ); |
| 44 | + |
| 45 | + $this->assertEquals( $expected, $this->test->filter_srcset( $source, null, $imageSrc, null, $attachmentId ) ); |
| 46 | + } |
| 47 | +} |
0 commit comments