| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tests; |
| 4 |
|
| 5 |
/* |
| 6 |
|-------------------------------------------------------------------------- |
| 7 |
| Test Case |
| 8 |
|-------------------------------------------------------------------------- |
| 9 |
| |
| 10 |
| The closure you provide to your test functions is always bound to a specific PHPUnit test |
| 11 |
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may |
| 12 |
| need to change it using the "pest()" function to bind a different classes or traits. |
| 13 |
| |
| 14 |
*/ |
| 15 |
|
| 16 |
use Pest\Browser\Api\Webpage; |
| 17 |
|
| 18 |
pest()->extend(TestCase::class)->in('Feature'); |
| 19 |
pest()->browser()->timeout(30000); |
| 20 |
|
| 21 |
/* |
| 22 |
|-------------------------------------------------------------------------- |
| 23 |
| Expectations |
| 24 |
|-------------------------------------------------------------------------- |
| 25 |
| |
| 26 |
| When you're writing tests, you often need to check that values meet certain conditions. The |
| 27 |
| "expect()" function gives you access to a set of "expectations" methods that you can use |
| 28 |
| to assert different things. Of course, you may extend the Expectation API at any time. |
| 29 |
| |
| 30 |
*/ |
| 31 |
|
| 32 |
expect()->extend('toBeOne', function () { |
| 33 |
return $this->toBe(1); |
| 34 |
}); |
| 35 |
|
| 36 |
/* |
| 37 |
|-------------------------------------------------------------------------- |
| 38 |
| Functions |
| 39 |
|-------------------------------------------------------------------------- |
| 40 |
| |
| 41 |
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your |
| 42 |
| project that you don't want to repeat in every file. Here you can also expose helpers as |
| 43 |
| global functions to help you to reduce the number of lines of code in your test files. |
| 44 |
| |
| 45 |
*/ |
| 46 |
|
| 47 |
function asUser(string $login, string $password) |
| 48 |
{ |
| 49 |
return visit('http://localhost:8100/wp-login.php') |
| 50 |
->assertPresent('#loginform') |
| 51 |
->fill('user_login', $login) |
| 52 |
->fill('user_pass', $password) |
| 53 |
->press('wp-submit') |
| 54 |
->assertPresent('#wpadminbar'); |
| 55 |
} |
| 56 |
|
| 57 |
function asAdmin() |
| 58 |
{ |
| 59 |
return asUser('admin', 'admin'); |
| 60 |
} |
| 61 |
|
| 62 |
function asAuthor() |
| 63 |
{ |
| 64 |
return asUser('author', 'author'); |
| 65 |
} |
| 66 |
|
| 67 |
function asEditor() |
| 68 |
{ |
| 69 |
return asUser('editor', 'editor'); |
| 70 |
} |
| 71 |
|