Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 1, 2018
1 parent 97c9ba1 commit b464b44
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/TestCase/Form/FormTest.php
Expand Up @@ -233,6 +233,22 @@ public function testExecuteValid()
$this->assertTrue($form->execute($data));
}

/**
* Test setting and getting form data.
*
* @return void
*/
public function testDataSetGet()
{
$form = new Form();
$expected = ['title' => 'title', 'is_published' => true];
$form->setData(['title' => 'title', 'is_published' => true]);

$this->assertSame($expected, $form->getData());
$this->assertEquals('title', $form->getData('title'));
$this->assertNull($form->getData('non-existent'));
}

/**
* test __debugInfo
*
Expand All @@ -245,5 +261,6 @@ public function testDebugInfo()
$this->assertArrayHasKey('_schema', $result);
$this->assertArrayHasKey('_errors', $result);
$this->assertArrayHasKey('_validator', $result);
$this->assertArrayHasKey('_data', $result);
}
}
21 changes: 21 additions & 0 deletions tests/TestCase/View/Form/FormContextTest.php
Expand Up @@ -93,6 +93,27 @@ public function testValPresent()
$this->assertNull($context->val('Articles.nope'));
}

/**
* Test reading values from form data.
*/
public function testValPresentInForm()
{
$form = new Form();
$form->setData(['title' => 'set title']);

$context = new FormContext($this->request, ['entity' => $form]);

$this->assertEquals('set title', $context->val('title'));
$this->assertNull($context->val('Articles.body'));

$this->request = $this->request->withParsedBody([
'title' => 'New title',
]);
$context = new FormContext($this->request, ['entity' => $form]);

$this->assertEquals('New title', $context->val('title'));
}

/**
* Test getting values when the request and defaults are missing.
*
Expand Down

0 comments on commit b464b44

Please sign in to comment.