mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-05 23:27:04 +00:00
Media: Add new functions to return the previous/next attachment links.
New functions: * get_adjacent_image_link() * get_next_image_link() * get_previous_image_link() Fixes #45708. Props flixos90, DrewAPicture, mor10, antpb, hellofromTonya, whyisjake. git-svn-id: https://develop.svn.wordpress.org/trunk@51122 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/testcase-adjacent-image-link.php';
|
||||
|
||||
/**
|
||||
* @group media
|
||||
* @covers ::previous_image_link
|
||||
*/
|
||||
class Tests_Media_PreviousImageLink extends WP_Test_Adjacent_Image_Link_TestCase {
|
||||
protected $default_args = array(
|
||||
'size' => 'thumbnail',
|
||||
'text' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* @ticket 45708
|
||||
*
|
||||
* @dataProvider data_previous_image_link
|
||||
*/
|
||||
function test_previous_image_link( $current_attachment_index, $expected_attachment_index = 0, $expected, array $args = array() ) {
|
||||
list( $expected, $args ) = $this->setup_test_scenario( $current_attachment_index, $expected_attachment_index, $expected, $args );
|
||||
|
||||
$this->expectOutputString( $expected );
|
||||
$this->assertNull( previous_image_link( ...$args ) );
|
||||
}
|
||||
|
||||
public function data_previous_image_link() {
|
||||
return array(
|
||||
// Happy paths.
|
||||
'when has previous link' => array(
|
||||
'current_attachment_index' => 3,
|
||||
'expected_attachment_index' => 2,
|
||||
'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'><img width="1" height="1" src="http://example.org/wp-content/uploads/image2.jpg" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" /></a>',
|
||||
),
|
||||
'with text when has previous link' => array(
|
||||
'current_attachment_index' => 3,
|
||||
'expected_attachment_index' => 2,
|
||||
'expected' => '<a href=\'http://example.org/?attachment_id=%%ID%%\'>Some text</a>',
|
||||
'args' => array( 'text' => 'Some text' ),
|
||||
),
|
||||
|
||||
// Unhappy paths.
|
||||
'when no previous link' => array(
|
||||
'current_attachment_index' => 1,
|
||||
'expected_attachment_index' => 0,
|
||||
'expected' => '',
|
||||
),
|
||||
'with text when no previous link' => array(
|
||||
'current_attachment_index' => 1,
|
||||
'expected_attachment_index' => 0,
|
||||
'expected' => '',
|
||||
'args' => array( 'text' => 'Some text' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user