ContactFormTest.php 1.3 KB

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