Skip to content

Commit

Permalink
test(FeatureTest): update login captcha test
Browse files Browse the repository at this point in the history
- Update login captcha test to use the correct route
- Assert the Content-Type header matches the configured type
  • Loading branch information
guanguans committed Oct 17, 2023
1 parent 52034c9 commit eb95bd3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
6 changes: 4 additions & 2 deletions tests/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

namespace Guanguans\DcatLoginCaptcha\Tests;

use Guanguans\DcatLoginCaptcha\LoginCaptchaServiceProvider;

it('can generate login captcha', function (): void {
$this->get('admin/captcha/generate')
$this->get(admin_base_path(LoginCaptchaServiceProvider::setting('route.uri')))
->assertOk()
->assertHeader('Content-Type', 'image/png');
->assertHeader('Content-Type', sprintf('image/%s', LoginCaptchaServiceProvider::setting('type')));
})->group(__DIR__, __FILE__);
Empty file removed tests/Fixtures/.gitkeep
Empty file.
6 changes: 3 additions & 3 deletions tests/LoginCaptchaServiceProviderrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
use Guanguans\DcatLoginCaptcha\Setting;
use Illuminate\Support\Facades\Validator;

it('can return provides', function (): void {
it('can get provides', function (): void {
expect(new LoginCaptchaServiceProvider(app()))
->provides()->toBeArray();
})->group(__DIR__, __FILE__);

it('can return setting form', function (): void {
it('can get setting form', function (): void {
expect(new LoginCaptchaServiceProvider(app()))
->settingForm()->toBeInstanceOf(Setting::class);
})->group(__DIR__, __FILE__);

it('can check dcat_login_captcha rule', function (): void {
it('can check `dcat_login_captcha` rule', function (): void {
expect(Validator::make(['captcha' => 'foo'], ['captcha' => 'dcat_login_captcha']))
->fails()->toBeTrue();
})->group(__DIR__, __FILE__);
1 change: 0 additions & 1 deletion tests/Support/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
})->group(__DIR__, __FILE__);

it('can get login captcha url', function (): void {
expect(login_captcha_url('foo.bar'))->toBeString();
expect(login_captcha_url())->toBeString();
})->group(__DIR__, __FILE__);

Expand Down
10 changes: 1 addition & 9 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Route;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Orchestra\Testbench\Concerns\WithWorkbench;
use PhpParser\Node;
Expand Down Expand Up @@ -70,8 +69,7 @@ protected function install(): void
Artisan::call('admin:install');
// Artisan::call('admin:ext-install', ['name' => 'guanguans.dcat-login-captcha', ['--path' => __DIR__.'/../']]);
// Artisan::call('admin:ext-enable', ['name' => 'guanguans.dcat-login-captcha']);
$loginCaptchaServiceProvider = app(LoginCaptchaServiceProvider::class);
$loginCaptchaServiceProvider->init();
app(LoginCaptchaServiceProvider::class)->init();
} catch (\Throwable $throwable) {
dump($throwable->getMessage());
}
Expand All @@ -98,12 +96,6 @@ protected function defineEnvironment($app): void
});
}

protected function defineRoutes($router): void
{
Route::get('foo/bar', static function (): void {
})->name('dcat.admin.foo.bar');
}

protected function fixDatabaseMigrations(): void
{
$nodeTraverser = new NodeTraverser();
Expand Down

0 comments on commit eb95bd3

Please sign in to comment.