mirror of
https://github.com/pierre42100/comunic
synced 2025-06-21 09:35:19 +00:00
First commit
This commit is contained in:
96
developer/vendor/rockettheme/toolbox/Blueprints/tests/BlueprintFormTest.php
vendored
Normal file
96
developer/vendor/rockettheme/toolbox/Blueprints/tests/BlueprintFormTest.php
vendored
Normal 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;
|
||||
}
|
||||
|
||||
}
|
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;
|
||||
}
|
||||
}
|
41
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/basic.yaml
vendored
Normal file
41
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/basic.yaml
vendored
Normal 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
|
||||
|
0
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/empty.yaml
vendored
Normal file
0
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/empty.yaml
vendored
Normal file
17
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/extends.yaml
vendored
Normal file
17
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/extends.yaml
vendored
Normal 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
|
4
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/import.yaml
vendored
Normal file
4
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/import.yaml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
form:
|
||||
fields:
|
||||
address:
|
||||
import@: partials/address
|
17
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/partials/address.yaml
vendored
Normal file
17
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/partials/address.yaml
vendored
Normal 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
|
40
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/basic.yaml
vendored
Normal file
40
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/basic.yaml
vendored
Normal 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
|
1
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/empty.yaml
vendored
Normal file
1
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/empty.yaml
vendored
Normal file
@ -0,0 +1 @@
|
||||
{ }
|
34
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/extends.yaml
vendored
Normal file
34
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/extends.yaml
vendored
Normal 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
|
8
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/import.yaml
vendored
Normal file
8
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/import.yaml
vendored
Normal 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 }
|
12
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/input/basic.yaml
vendored
Normal file
12
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/input/basic.yaml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
text: Testing...
|
||||
user:
|
||||
name: Igor
|
||||
extra: data...
|
||||
|
||||
some:
|
||||
random: false
|
||||
variables:
|
||||
- true
|
||||
- false
|
||||
just: for
|
||||
fun:
|
7
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/input/empty.yaml
vendored
Normal file
7
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/input/empty.yaml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
some:
|
||||
random: false
|
||||
variables:
|
||||
- true
|
||||
- false
|
||||
just: for
|
||||
fun:
|
4
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/defaults/basic.yaml
vendored
Normal file
4
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/defaults/basic.yaml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
enabled: true
|
||||
user:
|
||||
name: John
|
||||
country: fi
|
0
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/defaults/empty.yaml
vendored
Normal file
0
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/defaults/empty.yaml
vendored
Normal file
8
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/extra/basic.yaml
vendored
Normal file
8
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/extra/basic.yaml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
some:
|
||||
random: false
|
||||
variables:
|
||||
- true
|
||||
- false
|
||||
just: for
|
||||
fun:
|
||||
user.extra: data...
|
7
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/extra/empty.yaml
vendored
Normal file
7
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/extra/empty.yaml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
some:
|
||||
random: false
|
||||
variables:
|
||||
- true
|
||||
- false
|
||||
just: for
|
||||
fun:
|
88
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/init/basic.yaml
vendored
Normal file
88
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/init/basic.yaml
vendored
Normal 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
|
11
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/init/empty.yaml
vendored
Normal file
11
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/init/empty.yaml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
items:
|
||||
'':
|
||||
form: { }
|
||||
type: _root
|
||||
form_field: false
|
||||
rules: { }
|
||||
nested:
|
||||
'': ''
|
||||
dynamic: { }
|
||||
filter:
|
||||
validation: true
|
14
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/merge/basic.yaml
vendored
Normal file
14
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/merge/basic.yaml
vendored
Normal 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
|
7
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/merge/empty.yaml
vendored
Normal file
7
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/merge/empty.yaml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
some:
|
||||
random: false
|
||||
variables:
|
||||
- true
|
||||
- false
|
||||
just: for
|
||||
fun:
|
81
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/state/basic.yaml
vendored
Normal file
81
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/state/basic.yaml
vendored
Normal 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
|
11
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/state/empty.yaml
vendored
Normal file
11
developer/vendor/rockettheme/toolbox/Blueprints/tests/data/schema/state/empty.yaml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
items:
|
||||
'':
|
||||
form: { }
|
||||
type: _root
|
||||
form_field: false
|
||||
rules: { }
|
||||
nested:
|
||||
'': ''
|
||||
dynamic: { }
|
||||
filter:
|
||||
validation: true
|
9
developer/vendor/rockettheme/toolbox/Blueprints/tests/helper.php
vendored
Normal file
9
developer/vendor/rockettheme/toolbox/Blueprints/tests/helper.php
vendored
Normal 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'];
|
||||
}
|
Reference in New Issue
Block a user