Skip to content

Commit

Permalink
Fixing Unit Tests (#317)
Browse files Browse the repository at this point in the history
* updated tests workflow to new WordPress version construction

* Added missing block classes

* check test with align argument

* check tests if delete alignnone attribute from block layout

* check tests if supports align set as none

* Update class-blocks.php

* Update package.json

* fixed failed unit tests

---------

Co-authored-by: Nikita <[email protected]>
  • Loading branch information
Fellan-91 and nk-o authored Nov 19, 2024
1 parent e39c9c1 commit c4ffa51
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ jobs:
include:
# Test with the previous WP version.
- php: '7.4'
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
wordpress: 'previous major version'
- php: '8.2'
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
wordpress: 'previous major version'

env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wordpress == '' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wordpress ) }}
WP_ENV_CORE: ${{ matrix.wordpress == '' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', needs.compute-previous-wordpress-version.outputs.previous-wordpress-version ) }}

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions classes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1500,11 +1500,11 @@ public function render_callback( $attributes, $content = null, $context = 'front
'class' => '',
);

if ( $attributes['blockUniqueClass'] ) {
if ( isset( $attributes['blockUniqueClass'] ) && $attributes['blockUniqueClass'] ) {
$array_atts['class'] .= $attributes['blockUniqueClass'];
}

if ( $attributes['align'] ) {
if ( isset( $attributes['align'] ) && $attributes['align'] ) {
$array_atts['class'] .= ' align' . $attributes['align'];
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"env:start": "wp-env start",
"env:stop": "wp-env stop",
"env:destroy": "wp-env destroy",
"test": "npm-run-all lint test:unit",
"test": "npm-run-all lint test:unit:php test:e2e",
"test:e2e": "playwright test --config tests/e2e/playwright.config.js",
"test:e2e:ui": "playwright test --config tests/e2e/playwright.config.js --ui",
"test:e2e:install-playwright": "npx playwright install",
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/block-render-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public function add_test_block( $attrs = array() ) {
lazyblocks()->add_block( array_merge(
array(
'slug' => $block_slug,
'supports' => array(
'align' => false,
),
),
$attrs
) );
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/controls/select-control-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public function add_test_block( $attrs = array() ) {
lazyblocks()->add_block( array_merge(
array(
'slug' => $block_slug,
'supports' => array(
'align' => false,
),
),
$attrs
) );
Expand Down

0 comments on commit c4ffa51

Please sign in to comment.