Make WordPress Core

Ticket #36084: 36084.3.diff

File 36084.3.diff, 3.9 KB (added by joemcgill, 9 years ago)
  • src/wp-admin/includes/media.php

    diff --git src/wp-admin/includes/media.php src/wp-admin/includes/media.php
    index 2f7e585..743608d 100644
    function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $re 
    121121
    122122        $html = get_image_tag($id, $alt, '', $align, $size);
    123123
    124         if ( ! $rel ) {
    125                 $rel = ' rel="attachment wp-att-' . esc_attr( $id ) . '"';
    126         } else {
    127                 $rel = ' rel="' . esc_attr( $rel ) . '"';
    128         }
     124        $rel = $rel ? ' rel="' . esc_attr( $rel ) . '"' :  '';
    129125
    130126        if ( $url )
    131127                $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>";
    function image_media_send_to_editor($html, $attachment_id, $attachment) { 
    11661162                $align = !empty($attachment['align']) ? $attachment['align'] : 'none';
    11671163                $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
    11681164                $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
    1169                 $rel = ( $url == get_attachment_link($attachment_id) );
     1165                $rel = '';
     1166                if ( strpos( $url, 'attachment_id') || $url == get_attachment_link($attachment_id) ) {
     1167                        $rel = 'attachment wp-att-' . $id;
     1168                }
    11701169
    11711170                return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
    11721171        }
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index 5b68f32..56ce8fc 100644
    EOF; 
    14811481
    14821482                $this->assertSame( $expected, $actual );
    14831483        }
     1484
     1485        /**
     1486         * @ticket 36084
     1487         */
     1488        function test_get_image_send_to_editor_defaults() {
     1489                $id      = self::$large_id;
     1490                $caption = '';
     1491                $title   = 'A test title value.';
     1492                $align   = 'left';
     1493
     1494                // Calculate attachment data (default is medium).
     1495                $attachment = wp_get_attachment_image_src( $id, 'medium' );
     1496
     1497                $html = '<img src="%1$s" alt="" width="%2$d" height="%3$d" class="align%4$s size-medium wp-image-%5$d" />';
     1498                $expected = sprintf( $html, $attachment[0], $attachment[1], $attachment[2], $align, $id );
     1499
     1500                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) );
     1501
     1502                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align ) );
     1503        }
     1504
     1505        /**
     1506         * @ticket 36084
     1507         */
     1508        function test_get_image_send_to_editor_defaults_with_optional_params() {
     1509                $id      = self::$large_id;
     1510                $caption = 'A test caption.';
     1511                $title   = 'A test title value.';
     1512                $align   = 'left';
     1513                $url     = get_permalink( $id );
     1514                $rel     = 'nofollow';
     1515                $size    = 'thumbnail';
     1516                $alt     = 'An example alt value.';
     1517
     1518                // Calculate attachment data.
     1519                $attachment = wp_get_attachment_image_src( $id, $size );
     1520
     1521                $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>';
     1522                $html = '[caption id="attachment_%9$d" align="align%7$s" width="%5$d"]' . $html . ' %10$s[/caption]';
     1523
     1524                $expected = sprintf( $html, $url, $rel, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id, $caption );
     1525
     1526                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
     1527        }
     1528
     1529        /**
     1530         * @ticket 36084
     1531         */
     1532        function test_get_image_send_to_editor_defaults_no_caption_no_rel() {
     1533                $id      = self::$large_id;
     1534                $caption = '';
     1535                $title   = 'A test title value.';
     1536                $align   = 'left';
     1537                $url     = get_permalink( $id );
     1538                $rel     = '';
     1539                $size    = 'thumbnail';
     1540                $alt     = 'An example alt value.';
     1541
     1542                // Calculate attachment data.
     1543                $attachment = wp_get_attachment_image_src( $id, $size );
     1544
     1545                $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>';
     1546
     1547                $expected = sprintf( $html, $url, $attachment[0], $alt, $attachment[1], $attachment[2], $align, $size, $id );
     1548
     1549                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
     1550        }
    14841551}