|
|
@@ -720,6 +720,53 @@ class EntityContextTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test getting association default value from table schema.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testValAssociatedSchemaDefault()
|
|
|
+ {
|
|
|
+ $table = $this->getTableLocator()->get('Articles');
|
|
|
+ $associatedTable = $table->hasMany('Comments')->getTarget();
|
|
|
+ $column = $associatedTable->getSchema()->getColumn('comment');
|
|
|
+ $associatedTable->getSchema()->addColumn('comment', ['default' => 'default comment'] + $column);
|
|
|
+ $row = $table->newEntity();
|
|
|
+
|
|
|
+ $context = new EntityContext($this->request, [
|
|
|
+ 'entity' => $row,
|
|
|
+ 'table' => 'Articles',
|
|
|
+ ]);
|
|
|
+ $result = $context->val('comments.0.comment');
|
|
|
+ $this->assertEquals('default comment', $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test getting association join table default value from table schema.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testValAssociatedJoinTableSchemaDefault()
|
|
|
+ {
|
|
|
+ $table = $this->getTableLocator()->get('Articles');
|
|
|
+ $joinTable = $table
|
|
|
+ ->belongsToMany('Tags')
|
|
|
+ ->setThrough('ArticlesTags')
|
|
|
+ ->junction();
|
|
|
+ $joinTable->getSchema()->addColumn('column', [
|
|
|
+ 'default' => 'default join table column value',
|
|
|
+ 'type' => 'text'
|
|
|
+ ]);
|
|
|
+ $row = $table->newEntity();
|
|
|
+
|
|
|
+ $context = new EntityContext($this->request, [
|
|
|
+ 'entity' => $row,
|
|
|
+ 'table' => 'Articles',
|
|
|
+ ]);
|
|
|
+ $result = $context->val('tags.0._joinData.column');
|
|
|
+ $this->assertEquals('default join table column value', $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Test validator for boolean fields.
|
|
|
*
|
|
|
* @return void
|