ContactFormTest.php 1.3 KB

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