mirror of
https://github.com/pierre42100/comunic
synced 2025-06-21 17:45:18 +00:00
First commit
This commit is contained in:
90
developer/vendor/rockettheme/toolbox/Blueprints/tests/BlueprintSchemaTest.php
vendored
Normal file
90
developer/vendor/rockettheme/toolbox/Blueprints/tests/BlueprintSchemaTest.php
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
use RocketTheme\Toolbox\Blueprints\BlueprintSchema;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
|
||||
require_once 'helper.php';
|
||||
|
||||
class BlueprintsBlueprintSchemaTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreation()
|
||||
{
|
||||
$blueprints = new BlueprintSchema;
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'items' => [],
|
||||
'rules' => [],
|
||||
'nested' => [],
|
||||
'dynamic' => [],
|
||||
'filter' => ['validation' => true]
|
||||
],
|
||||
$blueprints->getState());
|
||||
|
||||
$this->assertEquals([], $blueprints->getDefaults());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testLoad($test)
|
||||
{
|
||||
$input = $this->loadYaml($test);
|
||||
|
||||
$blueprint = new BlueprintSchema;
|
||||
$blueprint->embed('', $input);
|
||||
|
||||
// Save test results if they do not exist (data needs to be verified by human!)
|
||||
/*
|
||||
$resultFile = YamlFile::instance(__DIR__ . '/data/schema/state/' . $test . '.yaml');
|
||||
if (!$resultFile->exists()) {
|
||||
$resultFile->content($blueprint->getState());
|
||||
$resultFile->save();
|
||||
}
|
||||
*/
|
||||
|
||||
// Test 1: Internal state.
|
||||
$this->assertEquals($this->loadYaml($test, 'schema/state'), $blueprint->getState());
|
||||
|
||||
// Save test results if they do not exist (data needs to be verified by human!)
|
||||
|
||||
$resultFile = YamlFile::instance(__DIR__ . '/data/schema/init/' . $test . '.yaml');
|
||||
if (!$resultFile->exists()) {
|
||||
$resultFile->content($blueprint->init()->getState());
|
||||
$resultFile->save();
|
||||
}
|
||||
|
||||
|
||||
// Test 2: Initialize blueprint.
|
||||
$this->assertEquals($this->loadYaml($test, 'schema/init'), $blueprint->init()->getState());
|
||||
|
||||
// Test 3: Default values.
|
||||
$this->assertEquals($this->loadYaml($test, 'schema/defaults'), $blueprint->getDefaults());
|
||||
|
||||
// Test 4: Extra values.
|
||||
$this->assertEquals($this->loadYaml($test, 'schema/extra'), $blueprint->extra($this->loadYaml($test, 'input')));
|
||||
|
||||
// Test 5: Merge data.
|
||||
$this->assertEquals(
|
||||
$this->loadYaml($test, 'schema/merge'),
|
||||
$blueprint->mergeData($blueprint->getDefaults(), $this->loadYaml($test, 'input'))
|
||||
);
|
||||
}
|
||||
|
||||
public function dataProvider()
|
||||
{
|
||||
return [
|
||||
['empty'],
|
||||
['basic'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function loadYaml($test, $type = 'blueprint')
|
||||
{
|
||||
$file = YamlFile::instance(__DIR__ . "/data/{$type}/{$test}.yaml");
|
||||
$content = $file->content();
|
||||
$file->free();
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user