|
6 | 6 |
|
7 | 7 | uses(RoutingTestCase::class); |
8 | 8 |
|
9 | | -it('should return a 200 status code for WordPress homepage', function () { |
| 9 | +expect()->extend('toHaveBodyClass', function (string $class) { |
| 10 | + preg_match('/<body[^>]*class=["\']([^"\']*)["\']/', $this->value, $matches); |
| 11 | + expect($matches)->toHaveCount(2, 'No body tag with class attribute found'); |
| 12 | + expect($matches[1])->toContain($class); |
| 13 | + return $this; |
| 14 | +}); |
| 15 | + |
| 16 | +it('handles the test route', function () { |
| 17 | + $client = new Client([ |
| 18 | + 'verify' => false, |
| 19 | + ]); |
| 20 | + |
| 21 | + $response = $client->request('GET', 'http://web:8080/test/'); |
| 22 | + expect($response->getStatusCode())->toBe(200); |
| 23 | + expect((string) $response->getBody())->toContain('Howdy'); |
| 24 | +}); |
| 25 | + |
| 26 | +it('does not intercept WordPress admin routes', function () { |
| 27 | + $client = new Client([ |
| 28 | + 'verify' => false, |
| 29 | + 'allow_redirects' => false, |
| 30 | + ]); |
| 31 | + |
| 32 | + $response = $client->request('GET', 'http://web:8080/wp/wp-admin/'); |
| 33 | + expect($response->getStatusCode())->toBe(302); |
| 34 | + expect($response->getHeader('Location')[0])->toContain('wp-login.php'); |
| 35 | +}); |
| 36 | + |
| 37 | +it('handles non-existent routes with 404', function () { |
| 38 | + $client = new Client([ |
| 39 | + 'verify' => false, |
| 40 | + 'http_errors' => false, |
| 41 | + ]); |
| 42 | + |
| 43 | + $response = $client->request('GET', 'http://web:8080/non-existent-' . time()); |
| 44 | + expect($response->getStatusCode())->toBe(404); |
| 45 | + expect((string) $response->getBody())->toContain('Page not found'); |
| 46 | + expect((string) $response->getBody())->toHaveBodyClass('error404'); |
| 47 | +}); |
| 48 | + |
| 49 | +it('handles default homepage', function () { |
10 | 50 | $client = new Client([ |
11 | 51 | 'verify' => false, |
12 | 52 | ]); |
13 | 53 |
|
14 | 54 | $response = $client->request('GET', 'http://web:8080/'); |
15 | 55 | expect($response->getStatusCode())->toBe(200); |
| 56 | + expect((string) $response->getBody())->toHaveBodyClass('home'); |
| 57 | +}); |
| 58 | + |
| 59 | +it('handles WordPress REST API routes', function () { |
| 60 | + $client = new Client([ |
| 61 | + 'verify' => false, |
| 62 | + ]); |
| 63 | + |
| 64 | + $response = $client->request('GET', 'http://web:8080/wp-json/'); |
| 65 | + expect($response->getStatusCode())->toBe(200); |
| 66 | + |
| 67 | + $data = json_decode((string) $response->getBody(), true); |
| 68 | + expect($data)->toHaveKey('name'); |
| 69 | + expect($data)->toHaveKey('url'); |
16 | 70 | }); |
17 | 71 |
|
18 | | -it('should return a 200 status code for Acorn test route', function () { |
| 72 | +it('handles WordPress search route', function () { |
19 | 73 | $client = new Client([ |
20 | 74 | 'verify' => false, |
21 | 75 | ]); |
22 | 76 |
|
23 | | - $response = $client->request('GET', 'http://web:8080/test'); |
| 77 | + $response = $client->request('GET', 'http://web:8080/search/test/'); |
24 | 78 | expect($response->getStatusCode())->toBe(200); |
25 | | - expect((string) $response->getBody())->toBe('Howdy'); |
| 79 | + expect((string) $response->getBody())->toHaveBodyClass('search'); |
26 | 80 | }); |
0 commit comments