Repository navigation
Blocks: add new methods to new package #17126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
933a090
Move block_classes method to new Blocks package.
jeherve 32f25d8
Add new method to check for AMP view from the package.
jeherve 7c1142b
Add tests for new methods
jeherve 785c7a6
Move away from array_push
anomiex 0e8b450
Fix typo
jeherve 826249c
Update test with proper bar and baz attributes
jeherve 05858ec
Add more assertions to cover all attributes
jeherve d9805e9
Add test for invalid alignment value.
jeherve e1d868a
Ensure we always remove AMP filter, even when test fails.
jeherve 83fb164
Remove unneeded default
anomiex d56a0a9
Switch to alternative approach to handle potential test failures
anomiex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
| /** | ||
| * PHPUnit bootstrap file. | ||
| * | ||
| * @package automattic/jetpack-blocks | ||
| */ | ||
|
|
||
| /** | ||
| * Load the composer autoloader. | ||
| */ | ||
| require_once __DIR__ . '/../../vendor/autoload.php'; | ||
|
|
||
| /** | ||
| * Load WorDBless | ||
| */ | ||
| \WorDBless\Load::load(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | ||
| /** | ||
| * Test methods from Automattic\Jetpack\Blocks | ||
| * | ||
| * @since 9.0.0 | ||
| * | ||
| * @package automattic/jetpack-blocks | ||
| */ | ||
|
|
||
| namespace Automattic\Jetpack; | ||
|
|
||
| use Automattic\Jetpack\Blocks; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** | ||
| * Class Test_Blocks | ||
| */ | ||
| class Test_Blocks extends TestCase { | ||
| /** | ||
| * Test the different inputs and matching output for Classes. | ||
| * | ||
| * @since 9.0.0 | ||
| * | ||
| * @covers Automattic\Jetpack\Blocks::classes | ||
| */ | ||
| public function test_block_classes() { | ||
| $block_name = 'foo'; | ||
| $attr = array( | ||
| 'bar' => 'baz', | ||
| 'align' => 'wide', | ||
| 'className' => 'editorclass', | ||
| ); | ||
| $extra = array( 'extraclass' ); | ||
|
|
||
| $block_classes = Blocks::classes( $block_name, $attr, $extra ); | ||
|
|
||
| $this->assertContains( 'wp-block-jetpack-foo', $block_classes ); // a general class is created from the block name. | ||
| $this->assertNotContains( 'bar', $block_classes ); // The extra 'bar' attribute should be dropped. | ||
| $this->assertNotContains( 'baz', $block_classes ); // The extra 'baz' attribute should be dropped. | ||
| $this->assertNotContains( 'align ', $block_classes ); // The align attribute should only be used to create a new attribute. | ||
| $this->assertNotContains( 'className', $block_classes ); // The className attribute should be dropped, only the editorclass value should remain. | ||
| $this->assertContains( 'alignwide', $block_classes ); // an alignment class is created. | ||
| $this->assertContains( 'editorclass', $block_classes ); // className classes are passed. | ||
| $this->assertContains( 'extraclass', $block_classes ); // Extra class remains. | ||
| } | ||
|
jeherve marked this conversation as resolved.
Resolved
|
||
|
|
||
| /** | ||
| * Test for invalid alignment values. | ||
| * | ||
| * @since 9.0.0 | ||
| * | ||
| * @covers Automattic\Jetpack\Blocks::classes | ||
| */ | ||
| public function test_block_classes_invalid_align() { | ||
| $attr = array( 'align' => 'test' ); | ||
| $block_classes = Blocks::classes( 'test', $attr ); | ||
|
|
||
| $this->assertNotContains( 'aligntest', $block_classes ); | ||
| } | ||
|
|
||
| /** | ||
| * Test whether we can detect an AMP view. | ||
| * | ||
| * @since 9.0.0 | ||
| * | ||
| * @covers Automattic\Jetpack\Blocks::is_amp_request | ||
| */ | ||
| public function test_is_amp_request() { | ||
| add_filter( 'jetpack_is_amp_request', '__return_true' ); | ||
| try { | ||
| $this->assertTrue( Blocks::is_amp_request() ); | ||
| } finally { | ||
| remove_filter( 'jetpack_is_amp_request', '__return_true' ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test whether we can detect an AMP view. | ||
| * | ||
| * @since 9.0.0 | ||
| * | ||
| * @covers Automattic\Jetpack\Blocks::is_amp_request | ||
| */ | ||
| public function test_is_not_amp_request() { | ||
| $this->assertFalse( Blocks::is_amp_request() ); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.