|
| 1 | +Feature: Server-side block conversion commands |
| 2 | + |
| 3 | + # The conversion functions ship with the Gutenberg build from |
| 4 | + # https://github.com/WordPress/gutenberg/pull/82013 and are not part of any |
| 5 | + # released WordPress or Gutenberg version yet, so on a plain install every |
| 6 | + # command fails with the same error. |
| 7 | + |
| 8 | + @require-wp-5.0 |
| 9 | + Scenario: Convert fails without the server-side block conversion |
| 10 | + Given a WP install |
| 11 | + |
| 12 | + When I try `wp block convert '<p>Text</p>'` |
| 13 | + Then STDERR should be: |
| 14 | + """ |
| 15 | + Error: Server-side block conversion is not available. Activate the Gutenberg plugin from https://github.com/WordPress/gutenberg/pull/82013. |
| 16 | + """ |
| 17 | + And STDOUT should be empty |
| 18 | + And the return code should be 1 |
| 19 | + |
| 20 | + @require-wp-5.0 |
| 21 | + Scenario: Conversion support fails without the server-side block conversion |
| 22 | + Given a WP install |
| 23 | + |
| 24 | + When I try `wp block conversion-support` |
| 25 | + Then STDERR should be: |
| 26 | + """ |
| 27 | + Error: Server-side block conversion is not available. Activate the Gutenberg plugin from https://github.com/WordPress/gutenberg/pull/82013. |
| 28 | + """ |
| 29 | + And STDOUT should be empty |
| 30 | + And the return code should be 1 |
| 31 | + |
| 32 | + # The scenarios below need a Gutenberg build from that pull request, which |
| 33 | + # CI cannot install, so they are tagged @broken and `composer behat` skips |
| 34 | + # them. To run them locally: |
| 35 | + # |
| 36 | + # 1. Build the plugin zip from the `try/13163-php-block-conversion` branch |
| 37 | + # (`npm run build:plugin-zip` in a Gutenberg checkout). |
| 38 | + # 2. Copy it to `gutenberg.zip` in the root of this package. Git ignores it. |
| 39 | + # 3. Prepare the test database once with `composer prepare-tests`. |
| 40 | + # 4. Run the scenarios by tag, bypassing the @broken exclusion: |
| 41 | + # |
| 42 | + # vendor/bin/behat --tags=@broken features/block-convert.feature |
| 43 | + # |
| 44 | + # Each scenario installs the zip with `wp plugin install gutenberg.zip --activate`. |
| 45 | + |
| 46 | + @broken |
| 47 | + Scenario: Convert HTML passed as an argument |
| 48 | + Given a WP install |
| 49 | + And I run `wp plugin install {PROJECT_DIR}/gutenberg.zip --activate` |
| 50 | + |
| 51 | + When I run `wp block convert '<h2>Title</h2><p>Text</p>'` |
| 52 | + Then STDOUT should contain: |
| 53 | + """ |
| 54 | + <!-- wp:heading --> |
| 55 | + """ |
| 56 | + And STDOUT should contain: |
| 57 | + """ |
| 58 | + <!-- wp:paragraph --> |
| 59 | + """ |
| 60 | + And STDOUT should contain: |
| 61 | + """ |
| 62 | + <p>Text</p> |
| 63 | + """ |
| 64 | + And STDERR should be empty |
| 65 | + |
| 66 | + @broken |
| 67 | + Scenario: Convert HTML from STDIN and from a file |
| 68 | + Given a WP install |
| 69 | + And I run `wp plugin install {PROJECT_DIR}/gutenberg.zip --activate` |
| 70 | + And a page.html file: |
| 71 | + """ |
| 72 | + <h2>Title</h2> |
| 73 | + <p>Text</p> |
| 74 | + """ |
| 75 | + |
| 76 | + When I run `cat page.html | wp block convert` |
| 77 | + Then STDOUT should contain: |
| 78 | + """ |
| 79 | + <!-- wp:heading --> |
| 80 | + """ |
| 81 | + And STDOUT should contain: |
| 82 | + """ |
| 83 | + <!-- wp:paragraph --> |
| 84 | + """ |
| 85 | + |
| 86 | + When I run `wp block convert --file=page.html` |
| 87 | + Then STDOUT should contain: |
| 88 | + """ |
| 89 | + <!-- wp:heading --> |
| 90 | + """ |
| 91 | + And STDOUT should contain: |
| 92 | + """ |
| 93 | + <!-- wp:paragraph --> |
| 94 | + """ |
| 95 | + |
| 96 | + When I try `wp block convert --file=missing.html` |
| 97 | + Then STDERR should contain: |
| 98 | + """ |
| 99 | + Error: File 'missing.html' does not exist or is not readable. |
| 100 | + """ |
| 101 | + And the return code should be 1 |
| 102 | + |
| 103 | + When I try `wp block convert '<p>Text</p>' --file=page.html` |
| 104 | + Then STDERR should contain: |
| 105 | + """ |
| 106 | + Error: Pass the HTML either as an argument or with --file, not both. |
| 107 | + """ |
| 108 | + And the return code should be 1 |
| 109 | + |
| 110 | + When I try `wp block convert < /dev/null` |
| 111 | + Then STDERR should contain: |
| 112 | + """ |
| 113 | + Error: No HTML given. Pass it as an argument, with --file, or on STDIN. |
| 114 | + """ |
| 115 | + And the return code should be 1 |
| 116 | +
|
| 117 | + @broken |
| 118 | + Scenario: Existing block markup is left alone and unknown markup becomes a Custom HTML block |
| 119 | + Given a WP install |
| 120 | + And I run `wp plugin install {PROJECT_DIR}/gutenberg.zip --activate` |
| 121 | +
|
| 122 | + When I run `wp block convert '<!-- wp:paragraph --><p>Text</p><!-- /wp:paragraph -->'` |
| 123 | + Then STDOUT should be: |
| 124 | + """ |
| 125 | + <!-- wp:paragraph --><p>Text</p><!-- /wp:paragraph --> |
| 126 | + """ |
| 127 | +
|
| 128 | + When I run `wp block convert '<marquee>Text</marquee>'` |
| 129 | + Then STDOUT should contain: |
| 130 | + """ |
| 131 | + <!-- wp:html --> |
| 132 | + """ |
| 133 | +
|
| 134 | + @broken |
| 135 | + Scenario: List the blocks a conversion can produce |
| 136 | + Given a WP install |
| 137 | + And I run `wp plugin install {PROJECT_DIR}/gutenberg.zip --activate` |
| 138 | +
|
| 139 | + When I run `wp block conversion-support` |
| 140 | + Then STDOUT should be a table containing rows: |
| 141 | + | name | support | |
| 142 | + | core/paragraph | converts | |
| 143 | + | core/table | declines | |
| 144 | +
|
| 145 | + When I run `wp block conversion-support --support=declines --field=name` |
| 146 | + Then STDOUT should contain: |
| 147 | + """ |
| 148 | + core/table |
| 149 | + """ |
| 150 | + And STDOUT should not contain: |
| 151 | + """ |
| 152 | + core/paragraph |
| 153 | + """ |
| 154 | +
|
| 155 | + When I run `wp block conversion-support --format=json` |
| 156 | + Then STDOUT should contain: |
| 157 | + """ |
| 158 | + {"name":"core\/paragraph","support":"converts"} |
| 159 | + """ |
| 160 | +
|
| 161 | + When I run `wp block conversion-support --format=count` |
| 162 | + Then STDOUT should be a number |
0 commit comments