Skip to content

Commit

Permalink
Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc committed Oct 3, 2024
1 parent b9d7a63 commit 218ecea
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion includes/MslsMetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function render_option( int $post_id, ?int $msls_id ): string {
return wp_kses(
sprintf(
'<option value="%d" %s>%s</option>',
esc_attr( $post_id ),
esc_attr( strval( $post_id ) ),
selected( $post_id, $msls_id, false ),
get_the_title( $post_id )
),
Expand Down
10 changes: 9 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
bootstrap="tests/phpunit/bootstrap.php"
backupGlobals="true"
colors="true"
testdox="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
cacheDirectory=".phpunit.cache">
displayDetailsOnPhpunitDeprecations="true"
cacheDirectory=".phpunit.cache"
>
<php>
<const name="MSLS_PLUGIN_PATH" value="multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
<const name="MSLS_PLUGIN__FILE__" value="/var/www/html/wp-content/plugins/multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/ContentImport/TestAttachmentPathFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,33 @@ public function test_filter_srcset( $source, $imageSrc, $attachmentId, $expected

$this->assertEquals( $expected, $this->test->filter_srcset( $source, null, $imageSrc, null, $attachmentId ) );
}

public static function dataprovider_filter_attachement_url(): array {
$generic_obj = (object) array( 'guid' => 'http://example.com/image.jpg' );

$post_mock = \Mockery::mock( '\WP_Post' );
$post_mock->guid = 'http://example.com/image.jpg';

return array(
array( 'http://example.com/image.jpg', $generic_obj, 42 ),
array( 'http://example.com/image.jpg', $generic_obj, 0 ),
array( 'http://example.com/image.jpg', $post_mock, 42 ),
);
}

/**
* @dataProvider dataprovider_filter_attachement_url
*/
public function test_filter_attachment_url( string $image_src, $source_post, int $attachment_id ): void {
$msls_imported = array(
'blog' => 1,
'post' => 1,
);

Functions\expect( 'get_post_meta' )->zeroOrMoreTimes()->andReturn( $msls_imported );
Functions\expect( 'delete_post_meta' )->zeroOrMoreTimes();
Functions\expect( 'get_blog_post' )->zeroOrMoreTimes()->andReturn( $source_post );

$this->assertEquals( $source_post->guid, $this->test->filter_attachment_url( $image_src, $attachment_id ) );
}
}

0 comments on commit 218ecea

Please sign in to comment.