-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate shape divider block to a server-rendered block (#2107)
* Start deprecating for server-rendered solution * disable tests for now * Gut the block * Fix flip controls * Moar cleanup * Remove inline color picker * moar cleanup * Migrate to UnitControl * Implement server-rendered shape-divider block * Re-enable and fix tests * Re-apply margin toggles * Clean up tests * Add new phpunit tests * removed submodule that I have no idea was added * Fix failing cypress tests
- Loading branch information
1 parent
2c032b6
commit 769eb86
Showing
18 changed files
with
455 additions
and
582 deletions.
There are no files selected for viewing
This file contains 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
142 changes: 142 additions & 0 deletions
142
.dev/tests/phpunit/src/blocks/shape-divider/test-index.php
This file contains 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,142 @@ | ||
<?php | ||
/** | ||
* Test src/blocks/shape-divider/index.php | ||
* | ||
* @package CoBlocks | ||
*/ | ||
class CoBlocks_Shape_Divider_Index_Tests extends WP_UnitTestCase { | ||
|
||
public function setUp() { | ||
parent::setUp(); | ||
|
||
include_once COBLOCKS_PLUGIN_DIR . 'src/blocks/shape-divider/index.php'; | ||
set_current_screen( 'edit-post' ); | ||
} | ||
|
||
public function tearDown() { | ||
parent::tearDown(); | ||
|
||
unset( $GLOBALS['current_screen'] ); | ||
} | ||
|
||
/** | ||
* Test that block renders with default attributes. | ||
*/ | ||
public function test_coblocks_render_block_shape_divider_returns_default_block_with_default_attributes() { | ||
$rendered_block = coblocks_render_block_shape_divider( array() ); | ||
|
||
$this->assertContains( 'class="wp-block-coblocks-shape-divider mt-0 mb-0" style="color: #111;"', $rendered_block ); | ||
$this->assertContains( 'class="wp-block-coblocks-shape-divider__svg-wrapper" style="height:100px;"', $rendered_block ); | ||
$this->assertContains( 'svg class="divider--wavy"', $rendered_block ); | ||
$this->assertContains( 'class="wp-block-coblocks-shape-divider__alt-wrapper" style="height:50px;"', $rendered_block ); | ||
|
||
// Test passing the default attributes renders exactly the same as no attributes. | ||
$rendered_block = coblocks_render_block_shape_divider( array( | ||
'shapeHeight' => '100px', | ||
'backgroundHeight' => '50px', | ||
'customColor' => '#111', | ||
'noBottomMargin' => true, | ||
'noTopMargin' => true, | ||
) ); | ||
|
||
$this->assertContains( 'class="wp-block-coblocks-shape-divider mt-0 mb-0" style="color: #111;"', $rendered_block ); | ||
$this->assertContains( 'class="wp-block-coblocks-shape-divider__svg-wrapper" style="height:100px;"', $rendered_block ); | ||
$this->assertContains( 'svg class="divider--wavy"', $rendered_block ); | ||
$this->assertContains( 'class="wp-block-coblocks-shape-divider__alt-wrapper" style="height:50px;"', $rendered_block ); | ||
} | ||
|
||
/** | ||
* Test that the block renders color classes or custom styles. | ||
*/ | ||
public function test_coblocks_render_block_shape_divider_returns_color_classes_or_styles() { | ||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider has-primary-color mt-0 mb-0" style=""', | ||
coblocks_render_block_shape_divider( array( 'color' => 'primary' ) ) | ||
); | ||
|
||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider mt-0 mb-0" style="color: #123;"', | ||
coblocks_render_block_shape_divider( array( 'customColor' => '#123' ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Test that the block renders background color classes or custom color styles. | ||
*/ | ||
public function test_coblocks_render_block_shape_divider_returns_background_color_classes_or_styles() { | ||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider has-primary-background-color mt-0 mb-0" style="color: #111;"', | ||
coblocks_render_block_shape_divider( array( 'backgroundColor' => 'primary' ) ) | ||
); | ||
|
||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider mt-0 mb-0" style="color: #111; background-color: #123;"', | ||
coblocks_render_block_shape_divider( array( 'customBackgroundColor' => '#123' ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Test that the block renders vertically flipped class. | ||
*/ | ||
public function test_coblocks_render_block_shape_divider_returns_vertically_flipped_class() { | ||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider is-vertically-flipped mt-0 mb-0" style="color: #111;"', | ||
coblocks_render_block_shape_divider( array( 'verticalFlip' => true ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Test that the block renders vertically flipped class. | ||
*/ | ||
public function test_coblocks_render_block_shape_divider_returns_horizontally_flipped_class() { | ||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider is-horizontally-flipped mt-0 mb-0" style="color: #111;"', | ||
coblocks_render_block_shape_divider( array( 'horizontalFlip' => true ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Test that the block renders a custom height styles. | ||
*/ | ||
public function test_coblocks_render_block_shape_divider_returns_custom_shape_height() { | ||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider__svg-wrapper" style="height:123px;"', | ||
coblocks_render_block_shape_divider( array( 'shapeHeight' => '123px' ) ) | ||
); | ||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider__alt-wrapper" style="height:123px;"', | ||
coblocks_render_block_shape_divider( array( 'backgroundHeight' => '123px' ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Test that the block renders margin classes. | ||
*/ | ||
public function test_coblocks_render_block_shape_divider_returns_margin_classes() { | ||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider mt-0" style="color: #111;"', | ||
coblocks_render_block_shape_divider( array( 'noBottomMargin' => false ) ) | ||
); | ||
$this->assertContains( | ||
'class="wp-block-coblocks-shape-divider mb-0" style="color: #111;"', | ||
coblocks_render_block_shape_divider( array( 'noTopMargin' => false ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Test the file actions are hooked properly. | ||
*/ | ||
public function test_file_actions() { | ||
$actions = [ | ||
[ 'init', 'coblocks_register_block_shape_divider' ], | ||
]; | ||
|
||
foreach ( $actions as $action_data ) { | ||
if ( ! has_action( $action_data[0], $action_data[1] ) ) { | ||
$this->fail( "$action_data[0] is not attached to $action_data[1]." ); | ||
} | ||
} | ||
|
||
$this->assertTrue( true ); | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.