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