mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-29 12:49:06 +02:00
Merge pull request #6865 from open-sausages/pulls/4.0/apcucache-fix
BUG Fix ApcuCache namespace
This commit is contained in:
commit
9dff7e4eeb
@ -27,9 +27,13 @@ class ApcuCacheFactory implements CacheFactory
|
|||||||
*/
|
*/
|
||||||
public function create($service, array $params = array())
|
public function create($service, array $params = array())
|
||||||
{
|
{
|
||||||
return Injector::inst()->create(ApcuCache::class, false, [
|
$namespace = isset($params['namespace'])
|
||||||
(isset($args['namespace'])) ? $args['namespace'] : '',
|
? $params['namespace'] . '_' . md5(BASE_PATH)
|
||||||
(isset($args['defaultLifetime'])) ? $args['defaultLifetime'] : 0,
|
: md5(BASE_PATH);
|
||||||
|
$defaultLifetime = isset($params['defaultLifetime']) ? $params['defaultLifetime'] : 0;
|
||||||
|
return Injector::inst()->createWithArgs(ApcuCache::class, [
|
||||||
|
$namespace,
|
||||||
|
$defaultLifetime,
|
||||||
$this->version
|
$this->version
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,8 @@ class DefaultCacheFactory implements CacheFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Chain this cache with ApcuCache
|
// Chain this cache with ApcuCache
|
||||||
$apcu = $this->createCache(ApcuCache::class, [$namespace, (int) $defaultLifetime / 5, $version]);
|
$apcuNamespace = $namespace . ($namespace ? '_' : '') . md5(BASE_PATH);
|
||||||
|
$apcu = $this->createCache(ApcuCache::class, [$apcuNamespace, (int) $defaultLifetime / 5, $version]);
|
||||||
return $this->createCache(ChainCache::class, [[$apcu, $fs]]);
|
return $this->createCache(ChainCache::class, [[$apcu, $fs]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class MemcachedCacheFactory implements CacheFactory
|
|||||||
/**
|
/**
|
||||||
* @param Memcached $memcachedClient
|
* @param Memcached $memcachedClient
|
||||||
*/
|
*/
|
||||||
public function __construct(Memcached $memcachedClient)
|
public function __construct(Memcached $memcachedClient = null)
|
||||||
{
|
{
|
||||||
$this->memcachedClient = $memcachedClient;
|
$this->memcachedClient = $memcachedClient;
|
||||||
}
|
}
|
||||||
@ -27,10 +27,14 @@ class MemcachedCacheFactory implements CacheFactory
|
|||||||
*/
|
*/
|
||||||
public function create($service, array $params = array())
|
public function create($service, array $params = array())
|
||||||
{
|
{
|
||||||
return Injector::inst()->create(MemcachedCache::class, false, [
|
$namespace = isset($params['namespace'])
|
||||||
|
? $params['namespace'] . '_' . md5(BASE_PATH)
|
||||||
|
: md5(BASE_PATH);
|
||||||
|
$defaultLifetime = isset($params['defaultLifetime']) ? $params['defaultLifetime'] : 0;
|
||||||
|
return Injector::inst()->createWithArgs(MemcachedCache::class, [
|
||||||
$this->memcachedClient,
|
$this->memcachedClient,
|
||||||
(isset($args['namespace'])) ? $args['namespace'] : '',
|
$namespace,
|
||||||
(isset($args['defaultLifetime'])) ? $args['defaultLifetime'] : 0
|
$defaultLifetime
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
88
tests/php/Core/Cache/CacheTest.php
Normal file
88
tests/php/Core/Cache/CacheTest.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Core\Tests\Cache;
|
||||||
|
|
||||||
|
use Psr\SimpleCache\CacheInterface;
|
||||||
|
use SilverStripe\Core\Cache\ApcuCacheFactory;
|
||||||
|
use SilverStripe\Core\Cache\MemcachedCacheFactory;
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Core\Test\Cache\CacheTest\MockCache;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use Symfony\Component\Cache\Simple\ApcuCache;
|
||||||
|
use Symfony\Component\Cache\Simple\MemcachedCache;
|
||||||
|
|
||||||
|
class CacheTest extends SapphireTest
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Config::modify()
|
||||||
|
->set(
|
||||||
|
Injector::class,
|
||||||
|
ApcuCacheFactory::class,
|
||||||
|
[
|
||||||
|
'constructor' => [ 'version' => 4400 ]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->set(
|
||||||
|
Injector::class,
|
||||||
|
CacheInterface::class . '.TestApcuCache',
|
||||||
|
[
|
||||||
|
'factory' => ApcuCacheFactory::class,
|
||||||
|
'constructor' => [
|
||||||
|
'namespace' => 'TestApcuCache',
|
||||||
|
'defaultLifetime' => 2600,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->set(
|
||||||
|
Injector::class,
|
||||||
|
CacheInterface::class . '.TestMemcache',
|
||||||
|
[
|
||||||
|
'factory' => MemcachedCacheFactory::class,
|
||||||
|
'constructor' => [
|
||||||
|
'namespace' => 'TestMemCache',
|
||||||
|
'defaultLifetime' => 5600,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->set(Injector::class, ApcuCache::class, MockCache::class)
|
||||||
|
->set(Injector::class, MemcachedCache::class, MockCache::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testApcuCacheFactory()
|
||||||
|
{
|
||||||
|
$cache = Injector::inst()->get(CacheInterface::class .'.TestApcuCache');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
MockCache::class,
|
||||||
|
$cache
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'TestApcuCache_'.md5(BASE_PATH),
|
||||||
|
2600,
|
||||||
|
4400
|
||||||
|
],
|
||||||
|
$cache->getArgs()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMemCacheFactory()
|
||||||
|
{
|
||||||
|
$cache = Injector::inst()->get(CacheInterface::class .'.TestMemcache');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
MockCache::class,
|
||||||
|
$cache
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
'TestMemCache_'.md5(BASE_PATH),
|
||||||
|
5600
|
||||||
|
],
|
||||||
|
$cache->getArgs()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
25
tests/php/Core/Cache/CacheTest/MockCache.php
Normal file
25
tests/php/Core/Cache/CacheTest/MockCache.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Core\Test\Cache\CacheTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
|
||||||
|
class MockCache implements TestOnly
|
||||||
|
{
|
||||||
|
protected $args = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->args = func_get_args();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get constructor args
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getArgs()
|
||||||
|
{
|
||||||
|
return $this->args;
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,6 @@ use SilverStripe\Forms\DateField;
|
|||||||
use SilverStripe\Forms\NumericField;
|
use SilverStripe\Forms\NumericField;
|
||||||
use SilverStripe\Forms\Schema\FormSchema;
|
use SilverStripe\Forms\Schema\FormSchema;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\Control\Controller;
|
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
use SilverStripe\Forms\TextField;
|
use SilverStripe\Forms\TextField;
|
||||||
@ -22,47 +21,11 @@ class FormSchemaTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
$form = new Form(null, 'TestForm', new FieldList(), new FieldList());
|
$form = new Form(null, 'TestForm', new FieldList(), new FieldList());
|
||||||
$formSchema = new FormSchema();
|
$formSchema = new FormSchema();
|
||||||
$expected = [
|
$expected = json_decode(file_get_contents(__DIR__.'/FormSchemaTest/testGetSchema.json'), true);
|
||||||
'name' => 'TestForm',
|
|
||||||
'id' => 'Form_TestForm',
|
|
||||||
'action' => null,
|
|
||||||
'method' => 'POST',
|
|
||||||
'attributes' => [
|
|
||||||
'id' => 'Form_TestForm',
|
|
||||||
'action' => null,
|
|
||||||
'method' => 'POST',
|
|
||||||
'enctype' => 'application/x-www-form-urlencoded',
|
|
||||||
'target' => null,
|
|
||||||
'class' => ''
|
|
||||||
],
|
|
||||||
'data' => [],
|
|
||||||
'fields' => [
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm_SecurityID',
|
|
||||||
'name' => 'SecurityID',
|
|
||||||
'type' => "Hidden",
|
|
||||||
'component' => null,
|
|
||||||
'holderId' => 'Form_TestForm_SecurityID_Holder',
|
|
||||||
'title' => 'Security ID',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'hidden',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'attributes' => [],
|
|
||||||
'data' => [],
|
|
||||||
'validation' => [],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'actions' => []
|
|
||||||
];
|
|
||||||
|
|
||||||
$schema = $formSchema->getSchema($form);
|
$schema = $formSchema->getSchema($form);
|
||||||
$this->assertInternalType('array', $schema);
|
$this->assertInternalType('array', $schema);
|
||||||
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($schema));
|
$this->assertEquals($expected, $schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetState()
|
public function testGetState()
|
||||||
@ -85,7 +48,7 @@ class FormSchemaTest extends SapphireTest
|
|||||||
|
|
||||||
$state = $formSchema->getState($form);
|
$state = $formSchema->getState($form);
|
||||||
$this->assertInternalType('array', $state);
|
$this->assertInternalType('array', $state);
|
||||||
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($state));
|
$this->assertEquals($expected, $state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetStateWithFormMessages()
|
public function testGetStateWithFormMessages()
|
||||||
@ -183,192 +146,11 @@ class FormSchemaTest extends SapphireTest
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
$formSchema = new FormSchema();
|
$formSchema = new FormSchema();
|
||||||
$expected = [
|
$expected = json_decode(file_get_contents(__DIR__.'/FormSchemaTest/testGetNestedSchema.json'), true);
|
||||||
'name' => 'TestForm',
|
|
||||||
'id' => 'Form_TestForm',
|
|
||||||
'action' => null,
|
|
||||||
'method' => 'POST',
|
|
||||||
'attributes' => [
|
|
||||||
'id' => 'Form_TestForm',
|
|
||||||
'action' => null,
|
|
||||||
'method' => 'POST',
|
|
||||||
'enctype' => 'application/x-www-form-urlencoded',
|
|
||||||
'target' => null,
|
|
||||||
'class' => ''
|
|
||||||
],
|
|
||||||
'data' => [],
|
|
||||||
'fields' => [
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm_Name',
|
|
||||||
'name' => 'Name',
|
|
||||||
'type' => 'Text',
|
|
||||||
'component' => null,
|
|
||||||
'holderId' => 'Form_TestForm_Name_Holder',
|
|
||||||
'title' => 'Name',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'text',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'attributes' => [],
|
|
||||||
'data' => [],
|
|
||||||
'validation' => [],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm_SecurityID',
|
|
||||||
'name' => 'SecurityID',
|
|
||||||
'type' => "Hidden",
|
|
||||||
'component' => null,
|
|
||||||
'holderId' => 'Form_TestForm_SecurityID_Holder',
|
|
||||||
'title' => 'Security ID',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'hidden',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'attributes' => [],
|
|
||||||
'data' => [],
|
|
||||||
'validation' => [],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'actions' => [
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm_action_save',
|
|
||||||
'title' => 'Save',
|
|
||||||
'name' => 'action_save',
|
|
||||||
'type' => null,
|
|
||||||
'component' => 'FormAction',
|
|
||||||
'holderId' => 'Form_TestForm_action_save_Holder',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'action',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'attributes' => [
|
|
||||||
'type' => 'submit',
|
|
||||||
],
|
|
||||||
'data' => [
|
|
||||||
'icon' => 'save',
|
|
||||||
],
|
|
||||||
'validation' => [],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm_action_cancel',
|
|
||||||
'title' => 'Cancel',
|
|
||||||
'name' => 'action_cancel',
|
|
||||||
'type' => null,
|
|
||||||
'component' => 'FormAction',
|
|
||||||
'holderId' => 'Form_TestForm_action_cancel_Holder',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'action',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'attributes' => [
|
|
||||||
'type' => 'button'
|
|
||||||
],
|
|
||||||
'data' => [
|
|
||||||
'icon' => null
|
|
||||||
],
|
|
||||||
'validation' => [],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm_Moreoptions',
|
|
||||||
'title' => 'More options',
|
|
||||||
'name' => 'Moreoptions',
|
|
||||||
'type' => 'Structural',
|
|
||||||
'component' => 'PopoverField',
|
|
||||||
'holderId' => 'Form_TestForm_Moreoptions_Holder',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'field CompositeField popover',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => null,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'attributes' => [],
|
|
||||||
'data' => [
|
|
||||||
'popoverTitle' => null,
|
|
||||||
'placement' => 'bottom',
|
|
||||||
'tag' => 'div',
|
|
||||||
'legend' => null,
|
|
||||||
'buttonTooltip' => null,
|
|
||||||
'inherited' => [
|
|
||||||
'data' => [
|
|
||||||
'fieldholder' => 'small'
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'validation' => [],
|
|
||||||
'children' => [
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm_action_publish',
|
|
||||||
'title' => 'Publish record',
|
|
||||||
'name' => 'action_publish',
|
|
||||||
'type' => null,
|
|
||||||
'component' => 'FormAction',
|
|
||||||
'holderId' => 'Form_TestForm_action_publish_Holder',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'action',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'attributes' => [
|
|
||||||
'type' => 'submit',
|
|
||||||
],
|
|
||||||
'data' => [
|
|
||||||
'icon' => null,
|
|
||||||
],
|
|
||||||
'validation' => [],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm_action_archive',
|
|
||||||
'title' => 'Archive',
|
|
||||||
'name' => 'action_archive',
|
|
||||||
'type' => null,
|
|
||||||
'component' => 'FormAction',
|
|
||||||
'holderId' => 'Form_TestForm_action_archive_Holder',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'action',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'attributes' => [
|
|
||||||
'type' => 'submit',
|
|
||||||
],
|
|
||||||
'data' => [
|
|
||||||
'icon' => null,
|
|
||||||
],
|
|
||||||
'validation' => [],
|
|
||||||
],
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$schema = $formSchema->getSchema($form);
|
$schema = $formSchema->getSchema($form);
|
||||||
|
|
||||||
$this->assertInternalType('array', $schema);
|
$this->assertInternalType('array', $schema);
|
||||||
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($schema));
|
$this->assertEquals($expected, $schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -406,155 +188,8 @@ class FormSchemaTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
$formSchema = new FormSchema();
|
$formSchema = new FormSchema();
|
||||||
$schema = $formSchema->getSchema($form);
|
$schema = $formSchema->getSchema($form);
|
||||||
$expected = [
|
$expected = json_decode(file_get_contents(__DIR__.'/FormSchemaTest/testSchemaValidation.json'), true);
|
||||||
'name' => 'TestForm',
|
|
||||||
'id' => 'Form_TestForm',
|
|
||||||
'action' => null,
|
|
||||||
'method' => 'POST',
|
|
||||||
'attributes' =>
|
|
||||||
[
|
|
||||||
'id' => 'Form_TestForm',
|
|
||||||
'action' => null,
|
|
||||||
'method' => 'POST',
|
|
||||||
'enctype' => 'application/x-www-form-urlencoded',
|
|
||||||
'target' => null,
|
|
||||||
'class' => '',
|
|
||||||
],
|
|
||||||
'data' =>
|
|
||||||
[],
|
|
||||||
'fields' =>
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'name' => 'Name',
|
|
||||||
'id' => 'Form_TestForm_Name',
|
|
||||||
'type' => 'Text',
|
|
||||||
'component' => null,
|
|
||||||
'holderId' => 'Form_TestForm_Name_Holder',
|
|
||||||
'title' => 'Name',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'text',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'validation' =>
|
|
||||||
[
|
|
||||||
'required' => true,
|
|
||||||
'max' => [
|
|
||||||
'length' => 40,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'attributes' =>
|
|
||||||
[],
|
|
||||||
'data' =>
|
|
||||||
[],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Date',
|
|
||||||
'id' => 'Form_TestForm_Date',
|
|
||||||
'type' => 'Date',
|
|
||||||
'component' => null,
|
|
||||||
'holderId' => 'Form_TestForm_Date_Holder',
|
|
||||||
'title' => 'Date',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'date text',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'lang' => 'en-US',
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'validation' =>
|
|
||||||
[
|
|
||||||
'date' => true,
|
|
||||||
],
|
|
||||||
'attributes' =>
|
|
||||||
[],
|
|
||||||
'data' => [
|
|
||||||
'html5' => true,
|
|
||||||
'min' => null,
|
|
||||||
'max' => null
|
|
||||||
],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Number',
|
|
||||||
'id' => 'Form_TestForm_Number',
|
|
||||||
'type' => 'Decimal',
|
|
||||||
'component' => null,
|
|
||||||
'holderId' => 'Form_TestForm_Number_Holder',
|
|
||||||
'title' => 'Number',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'numeric text',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'validation' =>
|
|
||||||
[
|
|
||||||
'numeric' => true,
|
|
||||||
],
|
|
||||||
'attributes' =>
|
|
||||||
[],
|
|
||||||
'data' =>
|
|
||||||
[],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Money',
|
|
||||||
'id' => 'Form_TestForm_Money',
|
|
||||||
'type' => 'Text',
|
|
||||||
'component' => null,
|
|
||||||
'holderId' => 'Form_TestForm_Money_Holder',
|
|
||||||
'title' => 'Money',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'currency text',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'validation' =>
|
|
||||||
[
|
|
||||||
'currency' => true,
|
|
||||||
],
|
|
||||||
'attributes' =>
|
|
||||||
[],
|
|
||||||
'data' =>
|
|
||||||
[],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'SecurityID',
|
|
||||||
'id' => 'Form_TestForm_SecurityID',
|
|
||||||
'type' => 'Hidden',
|
|
||||||
'component' => null,
|
|
||||||
'holderId' => 'Form_TestForm_SecurityID_Holder',
|
|
||||||
'title' => 'Security ID',
|
|
||||||
'source' => null,
|
|
||||||
'extraClass' => 'hidden',
|
|
||||||
'description' => null,
|
|
||||||
'rightTitle' => null,
|
|
||||||
'leftTitle' => null,
|
|
||||||
'readOnly' => false,
|
|
||||||
'disabled' => false,
|
|
||||||
'customValidationMessage' => '',
|
|
||||||
'validation' =>
|
|
||||||
[],
|
|
||||||
'attributes' =>
|
|
||||||
[],
|
|
||||||
'data' =>
|
|
||||||
[],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'actions' =>
|
|
||||||
[],
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->assertInternalType('array', $schema);
|
$this->assertInternalType('array', $schema);
|
||||||
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($schema));
|
$this->assertEquals($expected, $schema);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
181
tests/php/Forms/FormSchemaTest/testGetNestedSchema.json
Normal file
181
tests/php/Forms/FormSchemaTest/testGetNestedSchema.json
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
{
|
||||||
|
"name": "TestForm",
|
||||||
|
"id": "Form_TestForm",
|
||||||
|
"action": null,
|
||||||
|
"method": "POST",
|
||||||
|
"attributes": {
|
||||||
|
"id": "Form_TestForm",
|
||||||
|
"action": null,
|
||||||
|
"method": "POST",
|
||||||
|
"enctype": "application\/x-www-form-urlencoded",
|
||||||
|
"target": null,
|
||||||
|
"class": ""
|
||||||
|
},
|
||||||
|
"data": [],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"id": "Form_TestForm_Name",
|
||||||
|
"name": "Name",
|
||||||
|
"type": "Text",
|
||||||
|
"component": null,
|
||||||
|
"holderId": "Form_TestForm_Name_Holder",
|
||||||
|
"title": "Name",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "text",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"attributes": [],
|
||||||
|
"data": [],
|
||||||
|
"validation": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "Form_TestForm_SecurityID",
|
||||||
|
"name": "SecurityID",
|
||||||
|
"type": "Hidden",
|
||||||
|
"component": null,
|
||||||
|
"holderId": "Form_TestForm_SecurityID_Holder",
|
||||||
|
"title": "Security ID",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "hidden",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"attributes": [],
|
||||||
|
"data": [],
|
||||||
|
"validation": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"id": "Form_TestForm_action_save",
|
||||||
|
"title": "Save",
|
||||||
|
"name": "action_save",
|
||||||
|
"type": null,
|
||||||
|
"component": "FormAction",
|
||||||
|
"holderId": "Form_TestForm_action_save_Holder",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "action",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"attributes": {
|
||||||
|
"type": "submit"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"icon": "save"
|
||||||
|
},
|
||||||
|
"validation": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "Form_TestForm_action_cancel",
|
||||||
|
"title": "Cancel",
|
||||||
|
"name": "action_cancel",
|
||||||
|
"type": null,
|
||||||
|
"component": "FormAction",
|
||||||
|
"holderId": "Form_TestForm_action_cancel_Holder",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "action",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"attributes": {
|
||||||
|
"type": "button"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"icon": null
|
||||||
|
},
|
||||||
|
"validation": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "Form_TestForm_Moreoptions",
|
||||||
|
"title": "More options",
|
||||||
|
"name": "Moreoptions",
|
||||||
|
"type": "Structural",
|
||||||
|
"component": "PopoverField",
|
||||||
|
"holderId": "Form_TestForm_Moreoptions_Holder",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "field CompositeField popover",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": null,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"attributes": [],
|
||||||
|
"data": {
|
||||||
|
"popoverTitle": null,
|
||||||
|
"placement": "bottom",
|
||||||
|
"tag": "div",
|
||||||
|
"legend": null,
|
||||||
|
"buttonTooltip": null,
|
||||||
|
"inherited": {
|
||||||
|
"data": {
|
||||||
|
"fieldholder": "small"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"validation": [],
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"id": "Form_TestForm_action_publish",
|
||||||
|
"title": "Publish record",
|
||||||
|
"name": "action_publish",
|
||||||
|
"type": null,
|
||||||
|
"component": "FormAction",
|
||||||
|
"holderId": "Form_TestForm_action_publish_Holder",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "action",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"attributes": {
|
||||||
|
"type": "submit"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"icon": null
|
||||||
|
},
|
||||||
|
"validation": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "Form_TestForm_action_archive",
|
||||||
|
"title": "Archive",
|
||||||
|
"name": "action_archive",
|
||||||
|
"type": null,
|
||||||
|
"component": "FormAction",
|
||||||
|
"holderId": "Form_TestForm_action_archive_Holder",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "action",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"attributes": {
|
||||||
|
"type": "submit"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"icon": null
|
||||||
|
},
|
||||||
|
"validation": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
37
tests/php/Forms/FormSchemaTest/testGetSchema.json
Normal file
37
tests/php/Forms/FormSchemaTest/testGetSchema.json
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"name": "TestForm",
|
||||||
|
"id": "Form_TestForm",
|
||||||
|
"action": null,
|
||||||
|
"method": "POST",
|
||||||
|
"attributes": {
|
||||||
|
"id": "Form_TestForm",
|
||||||
|
"action": null,
|
||||||
|
"method": "POST",
|
||||||
|
"enctype": "application\/x-www-form-urlencoded",
|
||||||
|
"target": null,
|
||||||
|
"class": ""
|
||||||
|
},
|
||||||
|
"data": [],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"id": "Form_TestForm_SecurityID",
|
||||||
|
"name": "SecurityID",
|
||||||
|
"type": "Hidden",
|
||||||
|
"component": null,
|
||||||
|
"holderId": "Form_TestForm_SecurityID_Holder",
|
||||||
|
"title": "Security ID",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "hidden",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"attributes": [],
|
||||||
|
"data": [],
|
||||||
|
"validation": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actions": []
|
||||||
|
}
|
129
tests/php/Forms/FormSchemaTest/testSchemaValidation.json
Normal file
129
tests/php/Forms/FormSchemaTest/testSchemaValidation.json
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
{
|
||||||
|
"name": "TestForm",
|
||||||
|
"id": "Form_TestForm",
|
||||||
|
"action": null,
|
||||||
|
"method": "POST",
|
||||||
|
"attributes": {
|
||||||
|
"id": "Form_TestForm",
|
||||||
|
"action": null,
|
||||||
|
"method": "POST",
|
||||||
|
"enctype": "application\/x-www-form-urlencoded",
|
||||||
|
"target": null,
|
||||||
|
"class": ""
|
||||||
|
},
|
||||||
|
"data": [],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "Name",
|
||||||
|
"id": "Form_TestForm_Name",
|
||||||
|
"type": "Text",
|
||||||
|
"component": null,
|
||||||
|
"holderId": "Form_TestForm_Name_Holder",
|
||||||
|
"title": "Name",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "text",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"validation": {
|
||||||
|
"required": true,
|
||||||
|
"max": {
|
||||||
|
"length": 40
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"attributes": [],
|
||||||
|
"data": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Date",
|
||||||
|
"id": "Form_TestForm_Date",
|
||||||
|
"type": "Date",
|
||||||
|
"component": null,
|
||||||
|
"holderId": "Form_TestForm_Date_Holder",
|
||||||
|
"title": "Date",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "date text",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"lang": "en-US",
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"validation": {
|
||||||
|
"date": true
|
||||||
|
},
|
||||||
|
"attributes": [],
|
||||||
|
"data": {
|
||||||
|
"html5": true,
|
||||||
|
"min": null,
|
||||||
|
"max": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Number",
|
||||||
|
"id": "Form_TestForm_Number",
|
||||||
|
"type": "Decimal",
|
||||||
|
"component": null,
|
||||||
|
"holderId": "Form_TestForm_Number_Holder",
|
||||||
|
"title": "Number",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "numeric text",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"validation": {
|
||||||
|
"numeric": true
|
||||||
|
},
|
||||||
|
"attributes": [],
|
||||||
|
"data": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Money",
|
||||||
|
"id": "Form_TestForm_Money",
|
||||||
|
"type": "Text",
|
||||||
|
"component": null,
|
||||||
|
"holderId": "Form_TestForm_Money_Holder",
|
||||||
|
"title": "Money",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "currency text",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"validation": {
|
||||||
|
"currency": true
|
||||||
|
},
|
||||||
|
"attributes": [],
|
||||||
|
"data": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SecurityID",
|
||||||
|
"id": "Form_TestForm_SecurityID",
|
||||||
|
"type": "Hidden",
|
||||||
|
"component": null,
|
||||||
|
"holderId": "Form_TestForm_SecurityID_Holder",
|
||||||
|
"title": "Security ID",
|
||||||
|
"source": null,
|
||||||
|
"extraClass": "hidden",
|
||||||
|
"description": null,
|
||||||
|
"rightTitle": null,
|
||||||
|
"leftTitle": null,
|
||||||
|
"readOnly": false,
|
||||||
|
"disabled": false,
|
||||||
|
"customValidationMessage": "",
|
||||||
|
"validation": [],
|
||||||
|
"attributes": [],
|
||||||
|
"data": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actions": []
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user