FormTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Form;
  16. use Cake\Form\Form;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * Form test case.
  20. */
  21. class FormTest extends TestCase {
  22. /**
  23. * Test schema()
  24. *
  25. * @return void
  26. */
  27. public function testSchema() {
  28. $form = new Form();
  29. $schema = $form->schema();
  30. $this->assertInstanceOf('Cake\Form\Schema', $schema);
  31. $this->assertSame($schema, $form->schema(), 'Same instance each time');
  32. $schema = $this->getMock('Cake\Form\Schema');
  33. $this->assertSame($schema, $form->schema($schema));
  34. $this->assertSame($schema, $form->schema());
  35. }
  36. /**
  37. * Test validator()
  38. *
  39. * @return void
  40. */
  41. public function testValidator() {
  42. $form = new Form();
  43. $validator = $form->validator();
  44. $this->assertInstanceOf('Cake\Validation\Validator', $validator);
  45. $this->assertSame($validator, $form->validator(), 'Same instance each time');
  46. $schema = $this->getMock('Cake\Validation\Validator');
  47. $this->assertSame($validator, $form->validator($validator));
  48. $this->assertSame($validator, $form->validator());
  49. }
  50. /**
  51. * Test isValid method.
  52. *
  53. * @return void
  54. */
  55. public function testIsValid() {
  56. $form = new Form();
  57. $form->validator()
  58. ->add('email', 'format', ['rule' => 'email'])
  59. ->add('body', 'length', ['rule' => ['minLength', 12]]);
  60. $data = [
  61. 'email' => 'rong',
  62. 'body' => 'too short'
  63. ];
  64. $this->assertFalse($form->isValid($data));
  65. $this->assertCount(2, $form->errors());
  66. $data = [
  67. 'email' => 'test@example.com',
  68. 'body' => 'Some content goes here'
  69. ];
  70. $this->assertTrue($form->isValid($data));
  71. $this->assertCount(0, $form->errors());
  72. }
  73. public function testExecuteInvalid() {
  74. }
  75. public function testExecuteValid() {
  76. }
  77. }