66use App \Model \Table \ReportsTable ;
77use Cake \Core \Configure ;
88use Cake \ORM \TableRegistry ;
9+ use Cake \TestSuite \EmailTrait ;
910use Cake \TestSuite \IntegrationTestTrait ;
1011use Cake \TestSuite \TestCase ;
1112
1819class IncidentsControllerTest extends TestCase
1920{
2021 use IntegrationTestTrait;
22+ use EmailTrait;
2123
2224 protected IncidentsTable $ Incidents ;
2325 protected ReportsTable $ Reports ;
@@ -38,6 +40,7 @@ public function setUp(): void
3840 //$Session = new SessionComponent(new ComponentRegistry());
3941 $ this ->session (['Developer.id ' => 1 ]);
4042 $ this ->Reports = TableRegistry::getTableLocator ()->get ('Reports ' );
43+ $ this ->setupTransports ();
4144 }
4245
4346 public function testView (): void
@@ -103,6 +106,13 @@ public function testCreate(): void
103106 $ this ->configRequest (['input ' => $ bugReport ]);
104107 $ this ->post ('/incidents/create ' );
105108
109+ $ this ->assertSame (200 , $ this ->_response ->getStatusCode (), 'The reponse code should be 200 ! ' );
110+ $ incident = json_decode ($ this ->_response ->getBody (), true );
111+ $ this ->assertNotNull ($ incident , 'The incident should be an array ! ' );
112+
113+ $ expected = ['success ' => true ];
114+ $ this ->assertEquals ($ expected , $ incident );
115+
106116 $ report = $ this ->Reports ->find (
107117 'all ' ,
108118 order: ['Reports.created desc ' ]
@@ -125,6 +135,10 @@ public function testCreate(): void
125135 //Configure::write('test_transport_email', null);
126136
127137 $ this ->post ('/incidents/create ' );
138+ $ this ->assertSame (200 , $ this ->_response ->getStatusCode (), 'The reponse code should be 200 ! ' );
139+ $ result = json_decode ($ this ->_response ->getBody (), true );
140+ $ this ->assertNotNull ($ result );
141+ $ this ->assertSame (true , $ result ['success ' ]);
128142
129143 $ report = $ this ->Reports ->find (
130144 'all ' ,
@@ -146,20 +160,31 @@ public function testCreate(): void
146160 IncidentsTable::getStrippedPmaVersion ($ bugReportDecoded ['pma_version ' ]),
147161 $ report ['pma_version ' ]
148162 );
163+ }
149164
165+ public function testCreateInvalidEmptyReport (): void
166+ {
150167 $ this ->configRequest (['input ' => '' ]);
151168 $ this ->post ('/incidents/create ' );
169+ $ this ->assertSame (200 , $ this ->_response ->getStatusCode (), 'The reponse code should be 200 ! ' );
152170 $ result = json_decode ($ this ->_response ->getBody (), true );
153171 $ this ->assertNotNull ($ result );
154- $ this ->assertEquals (false , $ result ['success ' ]);
172+ $ this ->assertSame (false , $ result ['success ' ]);
173+ }
155174
175+ public function testCreateInvalidReport (): void
176+ {
156177 // Test invalid Notification email configuration
157178 Configure::write ('NotificationEmailsTo ' , '' );
158179
159180 $ bugReport = file_get_contents (TESTS . 'Fixture ' . DS . 'report_php.json ' );
160181 $ bugReportDecoded = json_decode ($ bugReport , true );
161182 $ this ->configRequest (['input ' => $ bugReport ]);
162183 $ this ->post ('/incidents/create ' );
184+ $ this ->assertSame (200 , $ this ->_response ->getStatusCode (), 'The reponse code should be 200 ! ' );
185+ $ result = json_decode ($ this ->_response ->getBody (), true );
186+ $ this ->assertNotNull ($ result );
187+ $ this ->assertSame (true , $ result ['success ' ]);
163188
164189 $ report = $ this ->Reports ->find (
165190 'all ' ,
@@ -170,9 +195,6 @@ public function testCreate(): void
170195 . $ report ['id ' ];
171196 $ this ->assertEquals ('4.5.4.1 ' , $ report ['pma_version ' ]);
172197
173- $ emailContent = Configure::read ('test_transport_email ' );
174-
175- // Since no email sent
176- $ this ->assertEquals (null , $ emailContent );
198+ $ this ->assertNoMailSent ();
177199 }
178200}
0 commit comments