First commit

This commit is contained in:
Pierre Hubert
2016-11-19 12:08:12 +01:00
commit 990540b2b9
4706 changed files with 931207 additions and 0 deletions

View File

@ -0,0 +1,96 @@
<?php
use RocketTheme\Toolbox\Blueprints\BlueprintForm;
use RocketTheme\Toolbox\File\YamlFile;
require_once 'helper.php';
class BlueprintsBlueprintFormTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider dataProvider
*/
public function testLoad($test)
{
$blueprint = new Blueprint($test);
$blueprint->setOverrides(
['extends' => ['extends', 'basic']]
);
$blueprint->load();
// Save test results if they do not exist (data needs to be verified by human!)
/*
$resultFile = YamlFile::instance(__DIR__ . '/data/form/items/' . $test . '.yaml');
if (!$resultFile->exists()) {
$resultFile->content($blueprint->toArray());
$resultFile->save();
}
*/
// Test 1: Loaded form.
$this->assertEquals($this->loadYaml($test, 'form/items'), $blueprint->toArray());
}
public function dataProvider()
{
return [
['empty'],
['basic'],
['import'],
['extends']
];
}
protected function loadYaml($test, $type = 'blueprint')
{
$file = YamlFile::instance(__DIR__ . "/data/{$type}/{$test}.yaml");
$content = $file->content();
$file->free();
return $content;
}
}
class Blueprint extends BlueprintForm
{
/**
* @param string $filename
* @return string
*/
protected function loadFile($filename)
{
$file = YamlFile::instance(__DIR__ . "/data/blueprint/{$filename}.yaml");
$content = $file->content();
$file->free();
return $content;
}
/**
* @param string|array $path
* @param string $context
* @return array
*/
protected function getFiles($path, $context = null)
{
if (is_string($path)) {
// Resolve filename.
if (isset($this->overrides[$path])) {
$path = $this->overrides[$path];
} else {
if ($context === null) {
$context = $this->context;
}
if ($context && $context[strlen($context)-1] !== '/') {
$context .= '/';
}
$path = $context . $path;
}
}
$files = (array) $path;
return $files;
}
}

View 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;
}
}

View File

@ -0,0 +1,41 @@
rules:
name:
pattern: "[A-Z][a-z]+"
min: 3
max: 15
form:
validation: loose
fields:
text:
type: text
label: Text
placeholder: 'Enter your text'
enabled:
type: select
label: Enabled
default: true
data-options@: blueprint_data_option_test
user.name:
type: name
label: Name
default: John
validate:
type: name
user.country:
type: select
label: Enabled
default: fi
data-options@:
- blueprint_data_option_test
- { us: 'United States', fi: 'Finland', po: 'Poland' }
- true
undefined:
type: select
label: Undefined
data-options@: undefined_function

View File

@ -0,0 +1,17 @@
extends@: parent@
form:
fields:
enabled:
default: false
text:
default: My text
ordering@: enabled
user.name:
default: Joe
unset-validate@: true
undefined:
unset@: true

View File

@ -0,0 +1,4 @@
form:
fields:
address:
import@: partials/address

View File

@ -0,0 +1,17 @@
form:
fields:
user.address:
type: text
label: Address
user.zip:
type: text
label: ZIP code
user.city:
type: text
label: City
user.country:
type: text
label: Country

View File

@ -0,0 +1,40 @@
rules:
name:
pattern: '[A-Z][a-z]+'
min: 3
max: 15
form:
validation: loose
fields:
text:
type: text
label: Text
placeholder: 'Enter your text'
name: text
enabled:
type: select
label: Enabled
default: true
data-options@: blueprint_data_option_test
name: enabled
user.name:
type: name
label: Name
default: John
validate:
type: name
name: user.name
user.country:
type: select
label: Enabled
default: fi
data-options@:
- blueprint_data_option_test
- { us: 'United States', fi: Finland, po: Poland }
- true
name: user.country
undefined:
type: select
label: Undefined
data-options@: undefined_function
name: undefined

View File

@ -0,0 +1,34 @@
rules:
name:
pattern: '[A-Z][a-z]+'
min: 3
max: 15
form:
validation: loose
fields:
enabled:
type: select
label: Enabled
default: false
data-options@: blueprint_data_option_test
name: enabled
text:
type: text
label: Text
placeholder: 'Enter your text'
default: 'My text'
name: text
user.name:
type: name
label: Name
default: Joe
name: user.name
user.country:
type: select
label: Enabled
default: fi
data-options@:
- blueprint_data_option_test
- { us: 'United States', fi: Finland, po: Poland }
- true
name: user.country

View File

@ -0,0 +1,8 @@
form:
fields:
address:
fields:
user.address: { type: text, label: Address, name: user.address }
user.zip: { type: text, label: 'ZIP code', name: user.zip }
user.city: { type: text, label: City, name: user.city }
user.country: { type: text, label: Country, name: user.country }

View File

@ -0,0 +1,12 @@
text: Testing...
user:
name: Igor
extra: data...
some:
random: false
variables:
- true
- false
just: for
fun:

View File

@ -0,0 +1,7 @@
some:
random: false
variables:
- true
- false
just: for
fun:

View File

@ -0,0 +1,4 @@
enabled: true
user:
name: John
country: fi

View File

@ -0,0 +1,8 @@
some:
random: false
variables:
- true
- false
just: for
fun:
user.extra: data...

View File

@ -0,0 +1,7 @@
some:
random: false
variables:
- true
- false
just: for
fun:

View File

@ -0,0 +1,88 @@
items:
'':
form:
validation: loose
type: _root
form_field: false
text:
type: text
label: Text
placeholder: 'Enter your text'
validation: loose
name: text
enabled:
type: select
label: Enabled
default: true
data-options@: blueprint_data_option_test
validation: loose
name: enabled
options:
'yes': 'Yes'
'no': 'No'
user:
type: _parent
name: user
form_field: false
user.name:
type: name
label: Name
default: John
validate:
type: name
validation: loose
name: user.name
user.country:
type: select
label: Enabled
default: fi
data-options@:
- blueprint_data_option_test
-
us: 'United States'
fi: Finland
po: Poland
- true
validation: loose
name: user.country
options:
fi: Finland
po: Poland
us: 'United States'
undefined:
type: select
label: Undefined
data-options@: undefined_function
validation: loose
name: undefined
rules:
name:
pattern: '[A-Z][a-z]+'
min: 3
max: 15
nested:
'': ''
text: text
enabled: enabled
user:
name: user.name
country: user.country
undefined: undefined
dynamic:
enabled:
options:
action: data
params: blueprint_data_option_test
user.country:
options:
action: data
params:
- blueprint_data_option_test
- { us: 'United States', fi: Finland, po: Poland }
- true
undefined:
options:
action: data
params: undefined_function
filter:
validation: true

View File

@ -0,0 +1,11 @@
items:
'':
form: { }
type: _root
form_field: false
rules: { }
nested:
'': ''
dynamic: { }
filter:
validation: true

View File

@ -0,0 +1,14 @@
text: Testing...
user:
name: Igor
country: fi
extra: data...
some:
random: false
variables:
- true
- false
just: for
fun:
enabled: true

View File

@ -0,0 +1,7 @@
some:
random: false
variables:
- true
- false
just: for
fun:

View File

@ -0,0 +1,81 @@
items:
'':
form:
validation: loose
type: _root
form_field: false
text:
type: text
label: Text
placeholder: 'Enter your text'
validation: loose
name: text
enabled:
type: select
label: Enabled
default: true
data-options@: blueprint_data_option_test
validation: loose
name: enabled
user:
type: _parent
name: user
form_field: false
user.name:
type: name
label: Name
default: John
validate:
type: name
validation: loose
name: user.name
user.country:
type: select
label: Enabled
default: fi
data-options@:
- blueprint_data_option_test
-
us: 'United States'
fi: Finland
po: Poland
- true
validation: loose
name: user.country
undefined:
type: select
label: Undefined
data-options@: undefined_function
validation: loose
name: undefined
rules:
name:
pattern: '[A-Z][a-z]+'
min: 3
max: 15
nested:
'': ''
text: text
enabled: enabled
user:
name: user.name
country: user.country
undefined: undefined
dynamic:
enabled:
options:
action: data
params: blueprint_data_option_test
user.country:
options:
action: data
params:
- blueprint_data_option_test
- { us: 'United States', fi: Finland, po: Poland }
- true
undefined:
options:
action: data
params: undefined_function
filter:
validation: true

View File

@ -0,0 +1,11 @@
items:
'':
form: { }
type: _root
form_field: false
rules: { }
nested:
'': ''
dynamic: { }
filter:
validation: true

View File

@ -0,0 +1,9 @@
<?php
function blueprint_data_option_test(array $param = null, $sort = false)
{
if ($sort) {
asort($param);
}
return $param ?: ['yes' => 'Yes', 'no' => 'No'];
}