class YamlTestBase

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Serialization/YamlTestBase.php \Drupal\Tests\Component\Serialization\YamlTestBase
  2. 10 core/tests/Drupal/Tests/Component/Serialization/YamlTestBase.php \Drupal\Tests\Component\Serialization\YamlTestBase
  3. 11.x core/tests/Drupal/Tests/Component/Serialization/YamlTestBase.php \Drupal\Tests\Component\Serialization\YamlTestBase

Provides standard data to validate different YAML implementations.

Hierarchy

  • class \Drupal\Tests\Component\Serialization\YamlTestBase extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of YamlTestBase

File

core/tests/Drupal/Tests/Component/Serialization/YamlTestBase.php, line 10

Namespace

Drupal\Tests\Component\Serialization
View source
abstract class YamlTestBase extends TestCase {
    
    /**
     * Some data that should be able to be serialized.
     */
    public function providerEncodeDecodeTests() {
        return [
            [
                'foo' => 'bar',
                'id' => 'schnitzel',
                'ponies' => [
                    'nope',
                    'thanks',
                ],
                'how' => [
                    'about' => 'if',
                    'i' => 'ask',
                    'nicely',
                ],
                'the' => [
                    'answer' => [
                        'still' => 'would',
                        'be' => 'Y',
                    ],
                ],
                'how_many_times' => 123,
                'should_i_ask' => FALSE,
                1,
                FALSE,
                [
                    1,
                    FALSE,
                ],
                [
                    10,
                ],
                [
                    0 => '123456',
                ],
            ],
            [
                NULL,
            ],
        ];
    }
    
    /**
     * Some data that should be able to be de-serialized.
     */
    public function providerDecodeTests() {
        $data = [
            // NULL files.
[
                '',
                NULL,
            ],
            [
                "\n",
                NULL,
            ],
            [
                "---\n...\n",
                NULL,
            ],
            // Node anchors.
[
                "\njquery.ui:\n  version: &jquery_ui 1.10.2\n\njquery.ui.accordion:\n  version: *jquery_ui\n",
                [
                    'jquery.ui' => [
                        'version' => '1.10.2',
                    ],
                    'jquery.ui.accordion' => [
                        'version' => '1.10.2',
                    ],
                ],
            ],
        ];
        // 1.2 Bool values.
        foreach ($this->providerBoolTest() as $test) {
            $data[] = [
                'bool: ' . $test[0],
                [
                    'bool' => $test[1],
                ],
            ];
        }
        $data = array_merge($data, $this->providerBoolTest());
        return $data;
    }
    
    /**
     * Tests different boolean serialization and de-serialization.
     */
    public function providerBoolTest() {
        return [
            [
                'true',
                TRUE,
            ],
            [
                'TRUE',
                TRUE,
            ],
            [
                'True',
                TRUE,
            ],
            [
                'y',
                'y',
            ],
            [
                'Y',
                'Y',
            ],
            [
                'false',
                FALSE,
            ],
            [
                'FALSE',
                FALSE,
            ],
            [
                'False',
                FALSE,
            ],
            [
                'n',
                'n',
            ],
            [
                'N',
                'N',
            ],
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary
YamlTestBase::providerBoolTest public function Tests different boolean serialization and de-serialization.
YamlTestBase::providerDecodeTests public function Some data that should be able to be de-serialized.
YamlTestBase::providerEncodeDecodeTests public function Some data that should be able to be serialized.

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