ContactFormTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Tools\Form;
  3. use Tools\TestSuite\TestCase;
  4. class ContactFormTest extends TestCase {
  5. /**
  6. * @var array
  7. */
  8. public $fixtures = [
  9. 'core.posts', 'core.authors',
  10. 'plugin.tools.tools_users', 'plugin.tools.roles',
  11. ];
  12. /**
  13. * @var \Tools\Form\ContactForm
  14. */
  15. public $Form;
  16. /**
  17. * SetUp method
  18. *
  19. * @return void
  20. */
  21. public function setUp() {
  22. parent::setUp();
  23. $this->Form = new ContactForm();
  24. }
  25. /**
  26. * Test testValidate
  27. *
  28. * @return void
  29. */
  30. public function testValidate() {
  31. $requestData = [
  32. 'name' => 'Foo',
  33. 'email' => 'foo',
  34. 'subject' => '',
  35. 'body' => 'Some message'
  36. ];
  37. $result = $this->Form->validate($requestData);
  38. $this->assertFalse($result);
  39. $errors = $this->Form->getErrors();
  40. $this->assertSame(['email', 'subject'], array_keys($errors));
  41. $requestData = [
  42. 'name' => 'Foo',
  43. 'email' => 'foo@example.org',
  44. 'subject' => 'Yeah',
  45. 'body' => 'Some message'
  46. ];
  47. $result = $this->Form->validate($requestData);
  48. $this->assertTrue($result);
  49. }
  50. /**
  51. * Test testExecute
  52. *
  53. * @return void
  54. */
  55. public function testExecute() {
  56. $requestData = [
  57. 'name' => 'Foo',
  58. 'email' => 'foo@example.org',
  59. 'subject' => 'Yeah',
  60. 'body' => 'Some message'
  61. ];
  62. $result = $this->Form->execute($requestData);
  63. $this->assertTrue($result);
  64. }
  65. }