/** * Test schema() * * @return void */ public function testSchema() { $form = new Form(); $schema = $form->schema(); $this->assertInstanceOf('Cake\\Form\\Schema', $schema); $this->assertSame($schema, $form->schema(), 'Same instance each time'); $schema = $this->getMock('Cake\\Form\\Schema'); $this->assertSame($schema, $form->schema($schema)); $this->assertSame($schema, $form->schema()); }
public static function getForm(string $tabId = null) : Form { $schema = new Schema(); $settings = self::getSettings($tabId); /** @var $v \ThreeCMS\Core\Settings\Setting **/ foreach ($settings as $v) { $schema->addField($v->getKey(), ['type' => 'text']); } $form = new Form(); $form->validator(self::getValidator($tabId)); $form->schema($schema); return $form; }
/** * Test fetching attributes. * * @return void */ public function testAttributes() { $form = new Form(); $form->schema()->addField('email', ['type' => 'string', 'length' => 10])->addField('amount', ['type' => 'decimal', 'length' => 5, 'precision' => 2]); $context = new FormContext($this->request, ['entity' => $form]); $this->assertEquals([], $context->attributes('id')); $this->assertEquals(['length' => 10, 'precision' => null], $context->attributes('email')); $this->assertEquals(['precision' => 2, 'length' => 5], $context->attributes('amount')); }