Skip to content

Commit 7bf5f6b

Browse files
committed
more tests
1 parent 21643b8 commit 7bf5f6b

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

tests/Integration/Routing/RoutingTest.php

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,75 @@
66

77
uses(RoutingTestCase::class);
88

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 () {
1050
$client = new Client([
1151
'verify' => false,
1252
]);
1353

1454
$response = $client->request('GET', 'http://web:8080/');
1555
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');
1670
});
1771

18-
it('should return a 200 status code for Acorn test route', function () {
72+
it('handles WordPress search route', function () {
1973
$client = new Client([
2074
'verify' => false,
2175
]);
2276

23-
$response = $client->request('GET', 'http://web:8080/test');
77+
$response = $client->request('GET', 'http://web:8080/search/test/');
2478
expect($response->getStatusCode())->toBe(200);
25-
expect((string) $response->getBody())->toBe('Howdy');
79+
expect((string) $response->getBody())->toHaveBodyClass('search');
2680
});

tests/Integration/Routing/RoutingTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Roots\Acorn\Tests\Integration\Routing;
44

5-
use Mockery\Adapter\Phpunit\MockeryTestCase;
65
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
6+
use Mockery\Adapter\Phpunit\MockeryTestCase;
77
use Roots\Acorn\Tests\Test\Concerns\SupportsGlobalStubs;
88
use Roots\Acorn\Tests\Test\Concerns\SupportsScopedFixtures;
99

@@ -19,7 +19,7 @@ protected function setUp(): void
1919
$this->clearStubs();
2020

2121
// Ensure routes directory exists
22-
if (!is_dir('/roots/app/public/routes')) {
22+
if (! is_dir('/roots/app/public/routes')) {
2323
mkdir('/roots/app/public/routes', 0777, true);
2424
}
2525

@@ -37,7 +37,7 @@ protected function setUp(): void
3737
file_put_contents('/roots/app/public/routes/web.php', $webRoutes);
3838

3939
// Ensure mu-plugins directory exists
40-
if (!is_dir('/roots/app/public/content/mu-plugins')) {
40+
if (! is_dir('/roots/app/public/content/mu-plugins')) {
4141
mkdir('/roots/app/public/content/mu-plugins', 0777, true);
4242
}
4343

tests/Test/Concerns/SupportsRouting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Roots\Acorn\Tests\Test\Concerns;
44

5-
use Roots\Acorn\Application;
65
use Illuminate\Support\Facades\Route;
6+
use Roots\Acorn\Application;
77

88
trait SupportsRouting
99
{

0 commit comments

Comments
 (0)