|
19 | 19 | use Codeception\Module\Laravel\InteractsWithExceptionHandling; |
20 | 20 | use Codeception\Module\Laravel\InteractsWithRouting; |
21 | 21 | use Codeception\Module\Laravel\InteractsWithSession; |
| 22 | +use Codeception\Module\Laravel\InteractsWithViews; |
22 | 23 | use Codeception\Subscriber\ErrorHandler; |
23 | 24 | use Codeception\TestInterface; |
24 | 25 | use Codeception\Util\ReflectionHelper; |
25 | 26 | use Exception; |
26 | | -use Illuminate\Contracts\Session\Session; |
27 | | -use Illuminate\Contracts\View\Factory as ViewContract; |
28 | 27 | use Illuminate\Database\Connection; |
29 | 28 | use Illuminate\Database\DatabaseManager; |
30 | 29 | use Illuminate\Database\Eloquent\Factory; |
31 | 30 | use Illuminate\Foundation\Application; |
32 | 31 | use Illuminate\Routing\Route; |
33 | | -use Illuminate\Support\ViewErrorBag; |
34 | 32 | use ReflectionException; |
35 | | -use function is_array; |
36 | 33 |
|
37 | 34 | /** |
38 | 35 | * |
@@ -134,6 +131,7 @@ class Laravel extends Framework implements ActiveRecord, PartedModule |
134 | 131 | use InteractsWithExceptionHandling; |
135 | 132 | use InteractsWithRouting; |
136 | 133 | use InteractsWithSession; |
| 134 | + use InteractsWithViews; |
137 | 135 |
|
138 | 136 | /** |
139 | 137 | * @var Application |
@@ -308,120 +306,6 @@ public function disableMiddleware() |
308 | 306 | $this->client->disableMiddleware(); |
309 | 307 | } |
310 | 308 |
|
311 | | - /** |
312 | | - * Assert that form errors are bound to the View. |
313 | | - * |
314 | | - * ``` php |
315 | | - * <?php |
316 | | - * $I->seeFormHasErrors(); |
317 | | - * ``` |
318 | | - */ |
319 | | - public function seeFormHasErrors(): void |
320 | | - { |
321 | | - /** @var ViewContract $view */ |
322 | | - $view = $this->app->make('view'); |
323 | | - /** @var ViewErrorBag $viewErrorBag */ |
324 | | - $viewErrorBag = $view->shared('errors'); |
325 | | - |
326 | | - $this->assertGreaterThan( |
327 | | - 0, |
328 | | - $viewErrorBag->count(), |
329 | | - 'Expecting that the form has errors, but there were none!' |
330 | | - ); |
331 | | - } |
332 | | - |
333 | | - /** |
334 | | - * Assert that there are no form errors bound to the View. |
335 | | - * |
336 | | - * ``` php |
337 | | - * <?php |
338 | | - * $I->dontSeeFormErrors(); |
339 | | - * ``` |
340 | | - */ |
341 | | - public function dontSeeFormErrors(): void |
342 | | - { |
343 | | - /** @var ViewContract $view */ |
344 | | - $view = $this->app->make('view'); |
345 | | - /** @var ViewErrorBag $viewErrorBag */ |
346 | | - $viewErrorBag = $view->shared('errors'); |
347 | | - |
348 | | - $this->assertEquals( |
349 | | - 0, |
350 | | - $viewErrorBag->count(), |
351 | | - 'Expecting that the form does not have errors, but there were!' |
352 | | - ); |
353 | | - } |
354 | | - |
355 | | - /** |
356 | | - * Verifies that multiple fields on a form have errors. |
357 | | - * |
358 | | - * This method will validate that the expected error message |
359 | | - * is contained in the actual error message, that is, |
360 | | - * you can specify either the entire error message or just a part of it: |
361 | | - * |
362 | | - * ``` php |
363 | | - * <?php |
364 | | - * $I->seeFormErrorMessages([ |
365 | | - * 'address' => 'The address is too long', |
366 | | - * 'telephone' => 'too short' // the full error message is 'The telephone is too short' |
367 | | - * ]); |
368 | | - * ``` |
369 | | - * |
370 | | - * If you don't want to specify the error message for some fields, |
371 | | - * you can pass `null` as value instead of the message string. |
372 | | - * If that is the case, it will be validated that |
373 | | - * that field has at least one error of any type: |
374 | | - * |
375 | | - * ``` php |
376 | | - * <?php |
377 | | - * $I->seeFormErrorMessages([ |
378 | | - * 'telephone' => 'too short', |
379 | | - * 'address' => null |
380 | | - * ]); |
381 | | - * ``` |
382 | | - * |
383 | | - * @param array $expectedErrors |
384 | | - */ |
385 | | - public function seeFormErrorMessages(array $expectedErrors): void |
386 | | - { |
387 | | - foreach ($expectedErrors as $field => $message) { |
388 | | - $this->seeFormErrorMessage($field, $message); |
389 | | - } |
390 | | - } |
391 | | - |
392 | | - /** |
393 | | - * Assert that a specific form error message is set in the view. |
394 | | - * |
395 | | - * If you want to assert that there is a form error message for a specific key |
396 | | - * but don't care about the actual error message you can omit `$expectedErrorMessage`. |
397 | | - * |
398 | | - * If you do pass `$expectedErrorMessage`, this method checks if the actual error message for a key |
399 | | - * contains `$expectedErrorMessage`. |
400 | | - * |
401 | | - * ``` php |
402 | | - * <?php |
403 | | - * $I->seeFormErrorMessage('username'); |
404 | | - * $I->seeFormErrorMessage('username', 'Invalid Username'); |
405 | | - * ``` |
406 | | - * @param string $field |
407 | | - * @param string|null $errorMessage |
408 | | - */ |
409 | | - public function seeFormErrorMessage(string $field, $errorMessage = null): void |
410 | | - { |
411 | | - /** @var ViewContract $view */ |
412 | | - $view = $this->app['view']; |
413 | | - /** @var ViewErrorBag $viewErrorBag */ |
414 | | - $viewErrorBag = $view->shared('errors'); |
415 | | - |
416 | | - if (!($viewErrorBag->has($field))) { |
417 | | - $this->fail("No form error message for key '$field'\n"); |
418 | | - } |
419 | | - |
420 | | - if (! is_null($errorMessage)) { |
421 | | - $this->assertStringContainsString($errorMessage, $viewErrorBag->first($field)); |
422 | | - } |
423 | | - } |
424 | | - |
425 | 309 | /** |
426 | 310 | * Returns a list of recognized domain names. |
427 | 311 | * This elements of this list are regular expressions. |
|
0 commit comments