|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQl\ContactUs; |
| 9 | + |
| 10 | +use Magento\TestFramework\Fixture\Config; |
| 11 | +use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; |
| 12 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 13 | + |
| 14 | +#[ |
| 15 | + Config("contact/contact/enabled", "1") |
| 16 | +] |
| 17 | +class ContactUsTest extends GraphQlAbstract |
| 18 | +{ |
| 19 | + /** |
| 20 | + * Successfuly send contact us form |
| 21 | + */ |
| 22 | + public function testContactUsSuccess() |
| 23 | + { |
| 24 | + $query = <<<MUTATION |
| 25 | +mutation { |
| 26 | + contactUs(input: { |
| 27 | + comment:"Test Contact Us", |
| 28 | + email:"test@adobe.com", |
| 29 | + name:"John Doe", |
| 30 | + telephone:"1111111111" |
| 31 | + }) |
| 32 | + { |
| 33 | + status |
| 34 | + } |
| 35 | +} |
| 36 | +MUTATION; |
| 37 | + |
| 38 | + $expected = [ |
| 39 | + "contactUs" => [ |
| 40 | + "status" => true |
| 41 | + ] |
| 42 | + ]; |
| 43 | + $response = $this->graphQlMutation($query, [], '', []); |
| 44 | + $this->assertEquals($expected, $response, "Contact Us form can not be send"); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Failed send contact us form - missing email |
| 49 | + */ |
| 50 | + public function testContactUsBadEmail() |
| 51 | + { |
| 52 | + $query = <<<MUTATION |
| 53 | +mutation { |
| 54 | + contactUs(input: { |
| 55 | + comment:"Test Contact Us", |
| 56 | + name:"John Doe", |
| 57 | + email:"adobe.com", |
| 58 | + telephone:"1111111111" |
| 59 | + }) |
| 60 | + { |
| 61 | + status |
| 62 | + } |
| 63 | +} |
| 64 | +MUTATION; |
| 65 | + $this->expectException(ResponseContainsErrorsException::class); |
| 66 | + $this->expectExceptionMessage( |
| 67 | + 'GraphQL response contains errors: The email address is invalid. Verify the email address and try again.' |
| 68 | + ); |
| 69 | + $this->graphQlMutation($query, [], '', []); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Failed send contact us form - missing name |
| 74 | + */ |
| 75 | + public function testContactUsMissingName() |
| 76 | + { |
| 77 | + $query = <<<MUTATION |
| 78 | +mutation { |
| 79 | + contactUs(input: { |
| 80 | + comment:"Test Contact Us", |
| 81 | + email:"test@adobe.com", |
| 82 | + telephone:"1111111111" |
| 83 | + }) |
| 84 | + { |
| 85 | + status |
| 86 | + } |
| 87 | +} |
| 88 | +MUTATION; |
| 89 | + $this->expectException(ResponseContainsErrorsException::class); |
| 90 | + $this->expectExceptionMessage( |
| 91 | + 'GraphQL response contains errors: Field ContactUsInput.name of required type String! was not provided.' |
| 92 | + ); |
| 93 | + $this->graphQlMutation($query, [], '', []); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Failed send contact us form - missing name |
| 98 | + */ |
| 99 | + public function testContactUsMissingComment() |
| 100 | + { |
| 101 | + $query = <<<MUTATION |
| 102 | +mutation { |
| 103 | + contactUs(input: { |
| 104 | + email:"test@adobe.com", |
| 105 | + name:"John Doe", |
| 106 | + telephone:"1111111111" |
| 107 | + }) |
| 108 | + { |
| 109 | + status |
| 110 | + } |
| 111 | +} |
| 112 | +MUTATION; |
| 113 | + $this->expectException(ResponseContainsErrorsException::class); |
| 114 | + $this->expectExceptionMessage( |
| 115 | + 'GraphQL response contains errors: Field ContactUsInput.comment of required type String! was not provided.' |
| 116 | + ); |
| 117 | + $this->graphQlMutation($query, [], '', []); |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * Failed send contact us form - missing name |
| 122 | + */ |
| 123 | + #[ |
| 124 | + Config("contact/contact/enabled", "0") |
| 125 | + ] |
| 126 | + public function testContactUsDisabled() |
| 127 | + { |
| 128 | + $query = <<<MUTATION |
| 129 | +mutation { |
| 130 | + contactUs(input: { |
| 131 | + comment:"Test Contact Us", |
| 132 | + email:"test@adobe.com", |
| 133 | + name:"John Doe", |
| 134 | + telephone:"1111111111" |
| 135 | + }) |
| 136 | + { |
| 137 | + status |
| 138 | + } |
| 139 | +} |
| 140 | +MUTATION; |
| 141 | + |
| 142 | + $this->expectException(ResponseContainsErrorsException::class); |
| 143 | + $this->expectExceptionMessage('GraphQL response contains errors: The contact form is unavailable.'); |
| 144 | + $this->graphQlMutation($query, [], '', []); |
| 145 | + } |
| 146 | +} |
0 commit comments