ContactFormTest.php 1.4 KB

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