Make WordPress Core


Ignore:
Timestamp:
03/18/2016 08:04:19 PM (9 years ago)
Author:
azaozz
Message:

Media: fix erroneously inserting a rel attribute in get_image_send_to_editor(). Reverts most of [34259] and [34260] and adds a unit test.

Props joemcgill, azaozz.
Fixes #36084.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r37034 r37035  
    15401540        $this->assertSame( $expected, $actual );
    15411541    }
     1542
     1543    /**
     1544     * @ticket 36084
     1545     */
     1546    function test_get_image_send_to_editor_defaults() {
     1547        $id      = self::$large_id;
     1548        $caption = '';
     1549        $title   = 'A test title value.';
     1550        $align   = 'left';
     1551
     1552        // Calculate attachment data (default is medium).
     1553        $attachment = wp_get_attachment_image_src( $id, 'medium' );
     1554
     1555        $html = '<img src="%1$s" alt="" width="%2$d" height="%3$d" class="align%4$s size-medium wp-image-%5$d" />';
     1556        $expected = sprintf( $html, $attachment[0], $attachment[1], $attachment[2], $align, $id );
     1557
     1558        $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) );
     1559
     1560        $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) );
     1561    }
     1562
     1563    /**
     1564     * @ticket 36084
     1565     */
     1566    function test_get_image_send_to_editor_defaults_with_optional_params() {
     1567        $id      = self::$large_id;
     1568        $caption = 'A test caption.';
     1569        $title   = 'A test title value.';
     1570        $align   = 'left';
     1571        $url     = get_permalink( $id );
     1572        $rel     = true;
     1573        $size    = 'thumbnail';
     1574        $alt     = 'An example alt value.';
     1575
     1576        // Calculate attachment data.
     1577        $attachment = wp_get_attachment_image_src( $id, $size );
     1578
     1579        $html = '<a href="%1$s" rel="%2$s"><img src="%3$s" alt="%4$s" width="%5$d" height="%6$d" class="size-%8$s wp-image-%9$d" /></a>';
     1580        $html = '[caption id="attachment_%9$d" align="align%7$s" width="%5$d"]' . $html . ' %10$s[/caption]';
     1581
     1582        $expected = sprintf( $html, $url, 'attachment wp-att-' . $id, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id, $caption );
     1583
     1584        $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
     1585    }
     1586
     1587    /**
     1588     * @ticket 36084
     1589     */
     1590    function test_get_image_send_to_editor_defaults_no_caption_no_rel() {
     1591        $id      = self::$large_id;
     1592        $caption = '';
     1593        $title   = 'A test title value.';
     1594        $align   = 'left';
     1595        $url     = get_permalink( $id );
     1596        $rel     = '';
     1597        $size    = 'thumbnail';
     1598        $alt     = 'An example alt value.';
     1599
     1600        // Calculate attachment data.
     1601        $attachment = wp_get_attachment_image_src( $id, $size );
     1602
     1603        $html = '<a href="%1$s"><img src="%2$s" alt="%3$s" width="%4$d" height="%5$d" class="align%6$s size-%7$s wp-image-%8$d" /></a>';
     1604
     1605        $expected = sprintf( $html, $url, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id );
     1606
     1607        $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
     1608    }
    15421609}
Note: See TracChangeset for help on using the changeset viewer.