mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-27 20:40:21 +00:00
Note: This is enforced by WPCS 3.0.0: 1. There should be no space between an increment/decrement operator and the variable it applies to. 2. Pre-increment/decrement should be favoured over post-increment/decrement for stand-alone statements. “Pre” will in/decrement and then return, “post” will return and then in/decrement. Using the “pre” version is slightly more performant and can prevent future bugs when code gets moved around. References: * [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#increment-decrement-operators WordPress PHP Coding Standards: Increment/decrement operators] * [https://github.com/WordPress/WordPress-Coding-Standards/pull/2130 WPCS: PR #2130 Core: add sniffs to check formatting of increment/decrement operators] Props jrf. See #59161, #58831. git-svn-id: https://develop.svn.wordpress.org/trunk@56549 602fd350-edb4-49c9-b593-d223f7449a82
106 lines
2.4 KiB
PHP
106 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Tests for WP_Block_List.
|
|
*
|
|
* @package WordPress
|
|
* @subpackage Blocks
|
|
* @since 5.5.0
|
|
*
|
|
* @group blocks
|
|
*/
|
|
class Tests_Blocks_wpBlockList extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Fake block type registry.
|
|
*
|
|
* @var WP_Block_Type_Registry
|
|
*/
|
|
private $registry = null;
|
|
|
|
/**
|
|
* Set up each test method.
|
|
*/
|
|
public function set_up() {
|
|
parent::set_up();
|
|
|
|
$this->registry = new WP_Block_Type_Registry();
|
|
$this->registry->register( 'core/example', array() );
|
|
}
|
|
|
|
/**
|
|
* Tear down each test method.
|
|
*/
|
|
public function tear_down() {
|
|
$this->registry = null;
|
|
|
|
parent::tear_down();
|
|
}
|
|
|
|
/**
|
|
* @ticket 49927
|
|
*/
|
|
public function test_array_access() {
|
|
$parsed_blocks = parse_blocks( '<!-- wp:example /-->' );
|
|
$context = array();
|
|
$blocks = new WP_Block_List( $parsed_blocks, $context, $this->registry );
|
|
|
|
// Test "offsetExists".
|
|
$this->assertArrayHasKey( 0, $blocks );
|
|
|
|
// Test "offsetGet".
|
|
$this->assertSame( 'core/example', $blocks[0]->name );
|
|
|
|
// Test "offsetSet".
|
|
$parsed_blocks[0]['blockName'] = 'core/updated';
|
|
$blocks[0] = new WP_Block( $parsed_blocks[0], $context, $this->registry );
|
|
$this->assertSame( 'core/updated', $blocks[0]->name );
|
|
|
|
// Test "offsetUnset".
|
|
unset( $blocks[0] );
|
|
$this->assertArrayNotHasKey( 0, $blocks );
|
|
}
|
|
|
|
/**
|
|
* @ticket 49927
|
|
*/
|
|
public function test_iterable() {
|
|
$parsed_blocks = parse_blocks( '<!-- wp:example --><!-- wp:example /--><!-- /wp:example -->' );
|
|
$context = array();
|
|
$blocks = new WP_Block_List( $parsed_blocks, $context, $this->registry );
|
|
$assertions = 0;
|
|
|
|
foreach ( $blocks as $block ) {
|
|
$this->assertSame( 'core/example', $block->name );
|
|
++$assertions;
|
|
foreach ( $block->inner_blocks as $inner_block ) {
|
|
$this->assertSame( 'core/example', $inner_block->name );
|
|
++$assertions;
|
|
}
|
|
}
|
|
|
|
$blocks->rewind();
|
|
while ( $blocks->valid() ) {
|
|
$key = $blocks->key();
|
|
$block = $blocks->current();
|
|
$this->assertSame( 0, $key );
|
|
++$assertions;
|
|
$this->assertSame( 'core/example', $block->name );
|
|
++$assertions;
|
|
$blocks->next();
|
|
}
|
|
|
|
$this->assertSame( 4, $assertions );
|
|
}
|
|
|
|
/**
|
|
* @ticket 49927
|
|
*/
|
|
public function test_countable() {
|
|
$parsed_blocks = parse_blocks( '<!-- wp:example /-->' );
|
|
$context = array();
|
|
$blocks = new WP_Block_List( $parsed_blocks, $context, $this->registry );
|
|
|
|
$this->assertCount( 1, $blocks );
|
|
}
|
|
}
|