class UtilitiesTest

Same name in other branches
  1. 11.x core/modules/sdc/tests/src/Unit/UtilitiesTest.php \Drupal\Tests\sdc\Unit\UtilitiesTest

Unit tests for the Utilities class.

@coversDefaultClass \Drupal\sdc\Utilities

@group sdc

Hierarchy

  • class \Drupal\Tests\sdc\Unit\UtilitiesTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of UtilitiesTest

File

core/modules/sdc/tests/src/Unit/UtilitiesTest.php, line 17

Namespace

Drupal\Tests\sdc\Unit
View source
final class UtilitiesTest extends TestCase {
    
    /**
     * @covers ::isRenderArray
     * @dataProvider dataProviderIsRenderArray
     */
    public function testIsRenderArray($build, $expected) {
        $this->assertSame($expected, Utilities::isRenderArray($build));
    }
    public static function dataProviderIsRenderArray() {
        return [
            'valid markup render array' => [
                [
                    '#markup' => 'hello world',
                ],
                TRUE,
            ],
            'invalid "foo" string' => [
                [
                    'foo',
                    '#markup' => 'hello world',
                ],
                FALSE,
            ],
            'null is not an array' => [
                NULL,
                FALSE,
            ],
            'an empty array is not a render array' => [
                [],
                FALSE,
            ],
            'funny enough a key with # is valid' => [
                [
                    '#' => TRUE,
                ],
                TRUE,
            ],
            'nested arrays can be valid too' => [
                [
                    'one' => [
                        2 => [
                            '#three' => 'charm!',
                        ],
                    ],
                ],
                TRUE,
            ],
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary
UtilitiesTest::dataProviderIsRenderArray public static function
UtilitiesTest::testIsRenderArray public function @covers ::isRenderArray
@dataProvider dataProviderIsRenderArray

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.