|
|
@@ -169,6 +169,9 @@ class ArrayContextTest extends TestCase
|
|
|
/**
|
|
|
* Test getting default value
|
|
|
*
|
|
|
+ * Tests includes making sure numeric elements are stripped but not keys beginning with numeric
|
|
|
+ * value
|
|
|
+ *
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testValDefault()
|
|
|
@@ -176,10 +179,14 @@ class ArrayContextTest extends TestCase
|
|
|
$context = new ArrayContext($this->request, [
|
|
|
'defaults' => [
|
|
|
'title' => 'Default value',
|
|
|
+ 'users' => ['tags' => 'common1', '9tags' => 'common2']
|
|
|
]
|
|
|
]);
|
|
|
|
|
|
$this->assertEquals('Default value', $context->val('title'));
|
|
|
+ $this->assertEquals('common1', $context->val('users.0.tags'));
|
|
|
+ $this->assertEquals('common1', $context->val('users.99.tags'));
|
|
|
+ $this->assertEquals('common2', $context->val('users.9.9tags'));
|
|
|
$result = $context->val('title', ['default' => 'explicit default']);
|
|
|
$this->assertEquals('explicit default', $result);
|
|
|
}
|
|
|
@@ -195,12 +202,14 @@ class ArrayContextTest extends TestCase
|
|
|
'required' => [
|
|
|
'Comments' => [
|
|
|
'required' => true,
|
|
|
- 'nope' => false
|
|
|
+ 'nope' => false,
|
|
|
+ 'tags' => true
|
|
|
]
|
|
|
]
|
|
|
]);
|
|
|
$this->assertTrue($context->isRequired('Comments.required'));
|
|
|
$this->assertFalse($context->isRequired('Comments.nope'));
|
|
|
+ $this->assertTrue($context->isRequired('Comments.0.tags'));
|
|
|
$this->assertFalse($context->isRequired('Articles.id'));
|
|
|
}
|
|
|
|
|
|
@@ -226,12 +235,14 @@ class ArrayContextTest extends TestCase
|
|
|
'schema' => [
|
|
|
'Comments' => [
|
|
|
'id' => ['type' => 'integer'],
|
|
|
+ 'tags' => ['type' => 'string'],
|
|
|
'comment' => ['length' => 255]
|
|
|
]
|
|
|
]
|
|
|
]);
|
|
|
$this->assertNull($context->type('Comments.undefined'));
|
|
|
$this->assertEquals('integer', $context->type('Comments.id'));
|
|
|
+ $this->assertEquals('string', $context->type('Comments.0.tags'));
|
|
|
$this->assertNull($context->type('Comments.comment'));
|
|
|
}
|
|
|
|
|
|
@@ -260,10 +271,12 @@ class ArrayContextTest extends TestCase
|
|
|
'comment' => ['type' => 'string', 'length' => 255],
|
|
|
'decimal' => ['type' => 'decimal', 'precision' => 2, 'length' => 5],
|
|
|
'floaty' => ['type' => 'float', 'precision' => 2, 'length' => 5],
|
|
|
+ 'tags' => ['type' => 'string', 'length' => 25],
|
|
|
]
|
|
|
]
|
|
|
]);
|
|
|
$this->assertEquals([], $context->attributes('Comments.id'));
|
|
|
+ $this->assertEquals(['length' => 25], $context->attributes('Comments.0.tags'));
|
|
|
$this->assertEquals(['length' => 255], $context->attributes('Comments.comment'));
|
|
|
$this->assertEquals(['precision' => 2, 'length' => 5], $context->attributes('Comments.decimal'));
|
|
|
$this->assertEquals(['precision' => 2, 'length' => 5], $context->attributes('Comments.floaty'));
|