UtilitiesTest.php

Same filename in other branches
  1. 10 core/modules/sdc/tests/src/Unit/UtilitiesTest.php

Namespace

Drupal\Tests\sdc\Unit

File

core/modules/sdc/tests/src/Unit/UtilitiesTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\sdc\Unit;

use Drupal\sdc\Utilities;
use PHPUnit\Framework\TestCase;

/**
 * Unit tests for the Utilities class.
 *
 * @coversDefaultClass \Drupal\sdc\Utilities
 *
 * @group sdc
 */
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,
            ],
        ];
    }

}

Classes

Title Deprecated Summary
UtilitiesTest Unit tests for the Utilities class.

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