Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
retlehs committed Dec 17, 2024
1 parent 21643b8 commit 7bf5f6b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
62 changes: 58 additions & 4 deletions tests/Integration/Routing/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,75 @@

uses(RoutingTestCase::class);

it('should return a 200 status code for WordPress homepage', function () {
expect()->extend('toHaveBodyClass', function (string $class) {
preg_match('/<body[^>]*class=["\']([^"\']*)["\']/', $this->value, $matches);
expect($matches)->toHaveCount(2, 'No body tag with class attribute found');
expect($matches[1])->toContain($class);
return $this;
});

it('handles the test route', function () {
$client = new Client([
'verify' => false,
]);

$response = $client->request('GET', 'http://web:8080/test/');
expect($response->getStatusCode())->toBe(200);
expect((string) $response->getBody())->toContain('Howdy');
});

it('does not intercept WordPress admin routes', function () {
$client = new Client([
'verify' => false,
'allow_redirects' => false,
]);

$response = $client->request('GET', 'http://web:8080/wp/wp-admin/');
expect($response->getStatusCode())->toBe(302);
expect($response->getHeader('Location')[0])->toContain('wp-login.php');
});

it('handles non-existent routes with 404', function () {
$client = new Client([
'verify' => false,
'http_errors' => false,
]);

$response = $client->request('GET', 'http://web:8080/non-existent-' . time());
expect($response->getStatusCode())->toBe(404);
expect((string) $response->getBody())->toContain('Page not found');
expect((string) $response->getBody())->toHaveBodyClass('error404');
});

it('handles default homepage', function () {
$client = new Client([
'verify' => false,
]);

$response = $client->request('GET', 'http://web:8080/');
expect($response->getStatusCode())->toBe(200);
expect((string) $response->getBody())->toHaveBodyClass('home');
});

it('handles WordPress REST API routes', function () {
$client = new Client([
'verify' => false,
]);

$response = $client->request('GET', 'http://web:8080/wp-json/');
expect($response->getStatusCode())->toBe(200);

$data = json_decode((string) $response->getBody(), true);
expect($data)->toHaveKey('name');
expect($data)->toHaveKey('url');
});

it('should return a 200 status code for Acorn test route', function () {
it('handles WordPress search route', function () {
$client = new Client([
'verify' => false,
]);

$response = $client->request('GET', 'http://web:8080/test');
$response = $client->request('GET', 'http://web:8080/search/test/');
expect($response->getStatusCode())->toBe(200);
expect((string) $response->getBody())->toBe('Howdy');
expect((string) $response->getBody())->toHaveBodyClass('search');
});
6 changes: 3 additions & 3 deletions tests/Integration/Routing/RoutingTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Roots\Acorn\Tests\Integration\Routing;

use Mockery\Adapter\Phpunit\MockeryTestCase;
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Roots\Acorn\Tests\Test\Concerns\SupportsGlobalStubs;
use Roots\Acorn\Tests\Test\Concerns\SupportsScopedFixtures;

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

// Ensure routes directory exists
if (!is_dir('/roots/app/public/routes')) {
if (! is_dir('/roots/app/public/routes')) {
mkdir('/roots/app/public/routes', 0777, true);
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Test/Concerns/SupportsRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Roots\Acorn\Tests\Test\Concerns;

use Roots\Acorn\Application;
use Illuminate\Support\Facades\Route;
use Roots\Acorn\Application;

trait SupportsRouting
{
Expand Down

0 comments on commit 7bf5f6b

Please sign in to comment.