Make WordPress Core

Changeset 55471


Ignore:
Timestamp:
03/07/2023 05:46:16 AM (17 months ago)
Author:
peterwilsoncc
Message:

Build/Tests Tools: Add unit tests for Gallery blocks.

Introduces unit tests for the following blocks

  • Gallery block with caption
  • Gallery block, deprecations 1 thru 7

Updates the unit tests for the following blocks to match the counterparts stored in the Gutenberg repository:

  • Gallery block
  • Gallery block with columns

Modifies Tests_Blocks_Render::test_do_block_output() to ignore white space at the end of lines to account for whitespace equivalence in HTML.

Props peterwilsoncc, isabel_brison, gziolo.
Fixes #55571.

Location:
trunk/tests/phpunit
Files:
40 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery.html

    r53261 r55471  
    11<!-- wp:gallery {"linkTo":"none","className":"columns-2"} -->
    2 <figure class="wp-block-gallery has-nested-images columns-default is-cropped columns-2">
    3     <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
     2<figure
     3    class="wp-block-gallery has-nested-images columns-default is-cropped columns-2"
     4>
     5    <!-- wp:image {"id":1421,"sizeSlug":"large","linkDestination":"none"} -->
    46    <figure class="wp-block-image size-large">
    5         <img src="https://cldup.com/uuUqE_dXzy.jpg" alt="Image gallery image" />
     7        <img
     8            src="https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190"
     9            alt="Image gallery image"
     10            class="wp-image-1421"
     11        />
    612    </figure>
    713    <!-- /wp:image -->
    814
    9     <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
     15    <!-- wp:image {"id":1440,"sizeSlug":"large","linkDestination":"none"} -->
    1016    <figure class="wp-block-image size-large">
    11         <img src="http://google.com/hi.png" alt="Image gallery image" />
     17        <img
     18            src="https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580"
     19            alt="Image gallery image"
     20            class="wp-image-1440"
     21        />
    1222    </figure>
    1323    <!-- /wp:image -->
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery.json

    r53261 r55471  
    2020                "isValid": true,
    2121                "attributes": {
    22                     "url": "https://cldup.com/uuUqE_dXzy.jpg",
     22                    "url": "https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190",
    2323                    "alt": "Image gallery image",
    2424                    "caption": "",
     25                    "id": 1421,
    2526                    "sizeSlug": "large",
    2627                    "linkDestination": "none"
     
    3233                "isValid": true,
    3334                "attributes": {
    34                     "url": "http://google.com/hi.png",
     35                    "url": "https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580",
    3536                    "alt": "Image gallery image",
    3637                    "caption": "",
     38                    "id": 1440,
    3739                    "sizeSlug": "large",
    3840                    "linkDestination": "none"
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery.parsed.json

    r53261 r55471  
    1010                "blockName": "core/image",
    1111                "attrs": {
     12                    "id": 1421,
    1213                    "sizeSlug": "large",
    1314                    "linkDestination": "none"
    1415                },
    1516                "innerBlocks": [],
    16                 "innerHTML": "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img src=\"https://cldup.com/uuUqE_dXzy.jpg\" alt=\"Image gallery image\" />\n\t</figure>\n\t",
     17                "innerHTML": "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img\n\t\t\tsrc=\"https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190\"\n\t\t\talt=\"Image gallery image\"\n\t\t\tclass=\"wp-image-1421\"\n\t\t/>\n\t</figure>\n\t",
    1718                "innerContent": [
    18                     "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img src=\"https://cldup.com/uuUqE_dXzy.jpg\" alt=\"Image gallery image\" />\n\t</figure>\n\t"
     19                    "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img\n\t\t\tsrc=\"https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190\"\n\t\t\talt=\"Image gallery image\"\n\t\t\tclass=\"wp-image-1421\"\n\t\t/>\n\t</figure>\n\t"
    1920                ]
    2021            },
     
    2223                "blockName": "core/image",
    2324                "attrs": {
     25                    "id": 1440,
    2426                    "sizeSlug": "large",
    2527                    "linkDestination": "none"
    2628                },
    2729                "innerBlocks": [],
    28                 "innerHTML": "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img src=\"http://google.com/hi.png\" alt=\"Image gallery image\" />\n\t</figure>\n\t",
     30                "innerHTML": "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img\n\t\t\tsrc=\"https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580\"\n\t\t\talt=\"Image gallery image\"\n\t\t\tclass=\"wp-image-1440\"\n\t\t/>\n\t</figure>\n\t",
    2931                "innerContent": [
    30                     "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img src=\"http://google.com/hi.png\" alt=\"Image gallery image\" />\n\t</figure>\n\t"
     32                    "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img\n\t\t\tsrc=\"https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580\"\n\t\t\talt=\"Image gallery image\"\n\t\t\tclass=\"wp-image-1440\"\n\t\t/>\n\t</figure>\n\t"
    3133                ]
    3234            }
    3335        ],
    34         "innerHTML": "\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped columns-2\">\n\t\n\n\t\n</figure>\n",
     36        "innerHTML": "\n<figure\n\tclass=\"wp-block-gallery has-nested-images columns-default is-cropped columns-2\"\n>\n\t\n\n\t\n</figure>\n",
    3537        "innerContent": [
    36             "\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped columns-2\">\n\t",
     38            "\n<figure\n\tclass=\"wp-block-gallery has-nested-images columns-default is-cropped columns-2\"\n>\n\t",
    3739            null,
    3840            "\n\n\t",
     
    4143        ]
    4244    },
    43     {
    44         "blockName": null,
    45         "attrs": {},
    46         "innerBlocks": [],
    47         "innerHTML": "\n",
    48         "innerContent": [
    49             "\n"
    50         ]
    51     }
     45    {
     46        "blockName": null,
     47        "attrs": {},
     48        "innerBlocks": [],
     49        "innerHTML": "\n",
     50        "innerContent": [ "\n" ]
     51    }
     52
    5253]
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery.serialized.html

    r53261 r55471  
    11<!-- wp:gallery {"linkTo":"none","className":"columns-2"} -->
    2 <figure class="wp-block-gallery has-nested-images columns-default is-cropped columns-2"><!-- wp:image {"sizeSlug":"large","linkDestination":"none"} --><figure class="wp-block-image size-large"><img src="https://cldup.com/uuUqE_dXzy.jpg" alt="Image gallery image" /></figure><!-- /wp:image --><!-- wp:image {"sizeSlug":"large","linkDestination":"none"} --><figure class="wp-block-image size-large"><img src="http://google.com/hi.png" alt="Image gallery image" /></figure><!-- /wp:image --></figure>
     2<figure class="wp-block-gallery has-nested-images columns-default is-cropped columns-2"><!-- wp:image {"id":1421,"sizeSlug":"large","linkDestination":"none"} -->
     3<figure class="wp-block-image size-large"><img src="https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190" alt="Image gallery image" class="wp-image-1421"/></figure>
     4<!-- /wp:image -->
     5
     6<!-- wp:image {"id":1440,"sizeSlug":"large","linkDestination":"none"} -->
     7<figure class="wp-block-image size-large"><img src="https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580" alt="Image gallery image" class="wp-image-1440"/></figure>
     8<!-- /wp:image --></figure>
    39<!-- /wp:gallery -->
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery.server.html

    r55282 r55471  
    11
    2 <figure class="wp-block-gallery has-nested-images columns-default is-cropped columns-2 wp-block-gallery-1 is-layout-flex">
    3    
     2<figure
     3    class="wp-block-gallery has-nested-images columns-default is-cropped columns-2 wp-block-gallery-1 is-layout-flex"
     4>
     5
    46    <figure class="wp-block-image size-large">
    5         <img src="https://cldup.com/uuUqE_dXzy.jpg" alt="Image gallery image" />
     7        <img data-id="1421"
     8            src="https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190"
     9            alt="Image gallery image"
     10            class="wp-image-1421"
     11        />
    612    </figure>
    7    
    813
    9    
     14
     15
    1016    <figure class="wp-block-image size-large">
    11         <img src="http://google.com/hi.png" alt="Image gallery image" />
     17        <img data-id="1440"
     18            src="https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580"
     19            alt="Image gallery image"
     20            class="wp-image-1440"
     21        />
    1222    </figure>
    13    
     23
    1424</figure>
    1525
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.html

    r53261 r55471  
    1 <!-- wp:gallery {"linkTo":"none","className":"columns-1"} -->
    2 <figure class="wp-block-gallery has-nested-images is-cropped columns-1" >
    3     <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
     1<!-- wp:gallery {"columns":1,"linkTo":"none"} -->
     2<figure class="wp-block-gallery has-nested-images columns-1 is-cropped">
     3    <!-- wp:image {"id":1421,"sizeSlug":"large","linkDestination":"none","inheritedAttributes":{"linkDestination":true,"linkTarget":true,"sizeSlug":true}} -->
    44    <figure class="wp-block-image size-large">
    5         <img src="https://cldup.com/uuUqE_dXzy.jpg" alt="Image gallery image" />
     5        <img
     6            src="https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190"
     7            alt="Image gallery image"
     8            class="wp-image-1421"
     9        />
    610    </figure>
    711    <!-- /wp:image -->
    812
    9     <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
     13    <!-- wp:image {"id":1440,"sizeSlug":"large","linkDestination":"none","inheritedAttributes":{"linkDestination":true,"linkTarget":true,"sizeSlug":true}} -->
    1014    <figure class="wp-block-image size-large">
    11         <img src="http://google.com/hi.png" alt="Image gallery image" />
     15        <img
     16            src="https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580"
     17            alt="Image gallery image"
     18            class="wp-image-1440"
     19        />
    1220    </figure>
    1321    <!-- /wp:image -->
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.json

    r53261 r55471  
    77            "ids": [],
    88            "shortCodeTransforms": [],
     9            "columns": 1,
    910            "caption": "",
    1011            "imageCrop": true,
     
    1213            "linkTo": "none",
    1314            "sizeSlug": "large",
    14             "allowResize": false,
    15             "className": "columns-1",
    16             "columns": 1
     15            "allowResize": false
    1716        },
    1817        "innerBlocks": [
     
    2120                "isValid": true,
    2221                "attributes": {
    23                     "url": "https://cldup.com/uuUqE_dXzy.jpg",
     22                    "url": "https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190",
    2423                    "alt": "Image gallery image",
    2524                    "caption": "",
     25                    "id": 1421,
    2626                    "sizeSlug": "large",
    2727                    "linkDestination": "none"
     
    3333                "isValid": true,
    3434                "attributes": {
    35                     "url": "http://google.com/hi.png",
     35                    "url": "https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580",
    3636                    "alt": "Image gallery image",
    3737                    "caption": "",
     38                    "id": 1440,
    3839                    "sizeSlug": "large",
    3940                    "linkDestination": "none"
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.parsed.json

    r53261 r55471  
    33        "blockName": "core/gallery",
    44        "attrs": {
    5             "linkTo": "none",
    6             "className": "columns-1"
     5            "columns": 1,
     6            "linkTo": "none"
    77        },
    88        "innerBlocks": [
     
    1010                "blockName": "core/image",
    1111                "attrs": {
     12                    "id": 1421,
    1213                    "sizeSlug": "large",
    13                     "linkDestination": "none"
     14                    "linkDestination": "none",
     15                    "inheritedAttributes": {
     16                        "linkDestination": true,
     17                        "linkTarget": true,
     18                        "sizeSlug": true
     19                    }
    1420                },
    1521                "innerBlocks": [],
    16                 "innerHTML": "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img src=\"https://cldup.com/uuUqE_dXzy.jpg\" alt=\"Image gallery image\" />\n\t</figure>\n\t",
     22                "innerHTML": "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img\n\t\t\tsrc=\"https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190\"\n\t\t\talt=\"Image gallery image\"\n\t\t\tclass=\"wp-image-1421\"\n\t\t/>\n\t</figure>\n\t",
    1723                "innerContent": [
    18                     "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img src=\"https://cldup.com/uuUqE_dXzy.jpg\" alt=\"Image gallery image\" />\n\t</figure>\n\t"
     24                    "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img\n\t\t\tsrc=\"https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190\"\n\t\t\talt=\"Image gallery image\"\n\t\t\tclass=\"wp-image-1421\"\n\t\t/>\n\t</figure>\n\t"
    1925                ]
    2026            },
     
    2228                "blockName": "core/image",
    2329                "attrs": {
     30                    "id": 1440,
    2431                    "sizeSlug": "large",
    25                     "linkDestination": "none"
     32                    "linkDestination": "none",
     33                    "inheritedAttributes": {
     34                        "linkDestination": true,
     35                        "linkTarget": true,
     36                        "sizeSlug": true
     37                    }
    2638                },
    2739                "innerBlocks": [],
    28                 "innerHTML": "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img src=\"http://google.com/hi.png\" alt=\"Image gallery image\" />\n\t</figure>\n\t",
     40                "innerHTML": "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img\n\t\t\tsrc=\"https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580\"\n\t\t\talt=\"Image gallery image\"\n\t\t\tclass=\"wp-image-1440\"\n\t\t/>\n\t</figure>\n\t",
    2941                "innerContent": [
    30                     "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img src=\"http://google.com/hi.png\" alt=\"Image gallery image\" />\n\t</figure>\n\t"
     42                    "\n\t<figure class=\"wp-block-image size-large\">\n\t\t<img\n\t\t\tsrc=\"https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580\"\n\t\t\talt=\"Image gallery image\"\n\t\t\tclass=\"wp-image-1440\"\n\t\t/>\n\t</figure>\n\t"
    3143                ]
    3244            }
    3345        ],
    34         "innerHTML": "\n<figure class=\"wp-block-gallery has-nested-images is-cropped columns-1\" >\n\t\n\n\t\n</figure>\n",
     46        "innerHTML": "\n<figure class=\"wp-block-gallery has-nested-images columns-1 is-cropped\">\n\t\n\n\t\n</figure>\n",
    3547        "innerContent": [
    36             "\n<figure class=\"wp-block-gallery has-nested-images is-cropped columns-1\" >\n\t",
     48            "\n<figure class=\"wp-block-gallery has-nested-images columns-1 is-cropped\">\n\t",
    3749            null,
    3850            "\n\n\t",
     
    4153        ]
    4254    },
    43     {
    44         "blockName": null,
    45         "attrs": {},
    46         "innerBlocks": [],
    47         "innerHTML": "\n",
    48         "innerContent": [
    49             "\n"
    50         ]
    51     }
     55    {
     56        "blockName": null,
     57        "attrs": {},
     58        "innerBlocks": [],
     59        "innerHTML": "\n",
     60        "innerContent": [ "\n" ]
     61    }
    5262]
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.serialized.html

    r53261 r55471  
    1 <!-- wp:gallery {"linkTo":"none","className":"columns-1"} -->
    2 <figure class="wp-block-gallery has-nested-images is-cropped columns-1"><!-- wp:image {"sizeSlug":"large","linkDestination":"none"} --><figure class="wp-block-image size-large"><img src="https://cldup.com/uuUqE_dXzy.jpg" alt="Image gallery image" /></figure><!-- /wp:image --><!-- wp:image {"sizeSlug":"large","linkDestination":"none"} --><figure class="wp-block-image size-large"><img src="http://google.com/hi.png" alt="Image gallery image" /></figure><!-- /wp:image --></figure>
     1<!-- wp:gallery {"columns":1,"linkTo":"none"} -->
     2<figure class="wp-block-gallery has-nested-images columns-1 is-cropped"><!-- wp:image {"id":1421,"sizeSlug":"large","linkDestination":"none"} -->
     3<figure class="wp-block-image size-large"><img src="https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190" alt="Image gallery image" class="wp-image-1421"/></figure>
     4<!-- /wp:image -->
     5
     6<!-- wp:image {"id":1440,"sizeSlug":"large","linkDestination":"none"} -->
     7<figure class="wp-block-image size-large"><img src="https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580" alt="Image gallery image" class="wp-image-1440"/></figure>
     8<!-- /wp:image --></figure>
    39<!-- /wp:gallery -->
  • trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html

    r55282 r55471  
    11
    2 <figure class="wp-block-gallery has-nested-images is-cropped columns-1 wp-block-gallery-1 is-layout-flex" >
    3    
     2<figure class="wp-block-gallery has-nested-images columns-1 is-cropped wp-block-gallery-1 is-layout-flex">
    43    <figure class="wp-block-image size-large">
    5         <img src="https://cldup.com/uuUqE_dXzy.jpg" alt="Image gallery image" />
     4        <img data-id="1421"
     5            src="https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190"
     6            alt="Image gallery image"
     7            class="wp-image-1421"
     8        />
    69    </figure>
    7    
    8 
    9    
    1010    <figure class="wp-block-image size-large">
    11         <img src="http://google.com/hi.png" alt="Image gallery image" />
     11        <img data-id="1440"
     12            src="https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580"
     13            alt="Image gallery image"
     14            class="wp-image-1440"
     15        />
    1216    </figure>
    13    
    1417</figure>
    15 
  • trunk/tests/phpunit/tests/blocks/render.php

    r55457 r55471  
    228228        $expected_html   = self::strip_r( file_get_contents( $server_html_path ) );
    229229
     230        // Convert HTML to be white space insensitive.
     231        $normalized_html = preg_replace( '/(\s+$)/m', '', $normalized_html );
     232        $expected_html   = preg_replace( '/(\s+$)/m', '', $expected_html );
     233
    230234        $this->assertSame(
    231235            $expected_html,
Note: See TracChangeset for help on using the changeset viewer.