Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests added #391

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ) );
}
}
Loading