Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jun 4, 2024
1 parent e6d0683 commit 693566f
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require-dev": {
"laravel/pint": "^1.2",
"nunomaduro/larastan": "^2.4.0",
"orchestra/testbench": "^8.5",
"sampoyigi/testbench": "dev-main as 1.0",
"pestphp/pest-plugin-laravel": "^2.0"
},
"autoload": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:YzE5YjR2b3hrem1ucmdmc2Fkbm92NW1veHBkMWdpa3k="/>
<env name="DB_DATABASE" value="testbench"/>
</php>
<source>
<include>
Expand Down
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

34 changes: 34 additions & 0 deletions tests/ExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Igniter\Frontend\Tests;

use Igniter\Frontend\Extension;

it('registers permissions', function() {
$extension = new Extension(app());

$permissions = $extension->registerPermissions();

expect($permissions)->toHaveKeys([
'Igniter.FrontEnd.ManageSettings',
'Igniter.FrontEnd.ManageBanners',
'Igniter.FrontEnd.ManageSlideshow',
]);
});

it('registers navigation', function() {
$extension = new Extension(app());

$navigation = $extension->registerNavigation();

expect($navigation)->toHaveKeys(['design'])
->and($navigation['design']['child'])->toHaveKeys(['sliders']);
});

it('registers mail templates', function() {
$extension = new Extension(app());

$templates = $extension->registerMailTemplates();

expect($templates)->toHaveKey('igniter.frontend::mail.contact');
});
85 changes: 85 additions & 0 deletions tests/Http/Controllers/BannersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Igniter\Frontend\Tests\Http\Controllers;

use Igniter\Frontend\Models\Banner;

it('loads banners page', function() {
actingAsSuperUser()
->get(route('igniter.frontend.banners'))
->assertOk();
});

it('loads create banner page', function() {
actingAsSuperUser()
->get(route('igniter.frontend.banners', ['slug' => 'create']))
->assertOk();
});

it('loads edit banner page', function() {
$banner = Banner::create();

actingAsSuperUser()
->get(route('igniter.frontend.banners', ['slug' => 'edit/'.$banner->getKey()]))
->assertOk();
});

it('loads banner preview page', function() {
$banner = Banner::create();

actingAsSuperUser()
->get(route('igniter.frontend.banners', ['slug' => 'preview/'.$banner->getKey()]))
->assertOk();
});

it('creates banner', function() {
actingAsSuperUser()
->post(route('igniter.frontend.banners', ['slug' => 'create']), [
'Banner' => [
'name' => 'Created Banner',
'code' => 'banner-code',
'custom_code' => '<h1>Updated Banner</h1>',
'language_id' => 1,
'status' => 1,
],
], [
'X-Requested-With' => 'XMLHttpRequest',
'X-IGNITER-REQUEST-HANDLER' => 'onSave',
]);

expect(Banner::where('name', 'Created Banner')->exists())->toBeTrue();
});

it('updates banner', function() {
$banner = Banner::create();

actingAsSuperUser()
->post(route('igniter.frontend.banners', ['slug' => 'edit/'.$banner->getKey()]), [
'Banner' => [
'name' => 'Updated Banner',
'code' => 'banner-code',
'custom_code' => '<h1>Updated Banner</h1>',
'language_id' => 1,
'status' => 1,
],
], [
'X-Requested-With' => 'XMLHttpRequest',
'X-IGNITER-REQUEST-HANDLER' => 'onSave',
]);

expect(Banner::where('name', 'Updated Banner')->exists())->toBeTrue();
});

it('deletes banner', function() {
$banner = Banner::create();

actingAsSuperUser()
->post(route('igniter.frontend.banners', ['slug' => 'edit/'.$banner->getKey()]), [], [
'X-Requested-With' => 'XMLHttpRequest',
'X-IGNITER-REQUEST-HANDLER' => 'onDelete',
]);

expect(Banner::find($banner->getKey()))->toBeNull();
});


89 changes: 89 additions & 0 deletions tests/Http/Controllers/SlidersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Igniter\Frontend\Tests\Http\Controllers;

use Igniter\Frontend\Models\Slider;
use Igniter\User\Models\User;

it('loads sliders page', function() {
actingAsSuperUser()
->get(route('igniter.frontend.sliders'))
->assertOk();
});

it('loads create slider page', function() {
actingAsSuperUser()
->get(route('igniter.frontend.sliders', ['slug' => 'create']))
->assertOk();
});

it('loads edit slider page', function() {
$slider = Slider::create();

actingAsSuperUser()
->get(route('igniter.frontend.sliders', ['slug' => 'edit/'.$slider->getKey()]))
->assertOk();
});

it('loads slider preview page', function() {
$slider = Slider::create();

actingAsSuperUser()
->get(route('igniter.frontend.sliders', ['slug' => 'preview/'.$slider->getKey()]))
->assertOk();
});

it('creates slider', function() {
actingAsSuperUser()
->post(route('igniter.frontend.sliders', ['slug' => 'create']), [
'Slider' => [
'name' => 'Created Slider',
'code' => 'slider-code',
'images' => [
'path/to/image.jpg',
]
],
], [
'X-Requested-With' => 'XMLHttpRequest',
'X-IGNITER-REQUEST-HANDLER' => 'onSave',
]);

expect(Slider::where('name', 'Created Slider')->exists())->toBeTrue();
});

it('updates slider', function() {
$slider = Slider::create();

actingAsSuperUser()
->post(route('igniter.frontend.sliders', ['slug' => 'edit/'.$slider->getKey()]), [
'Slider' => [
'name' => 'Updated Slider',
'code' => 'slider-code',
'images' => [
'path/to/image.jpg',
]
],
], [
'X-Requested-With' => 'XMLHttpRequest',
'X-IGNITER-REQUEST-HANDLER' => 'onSave',
]);

expect(Slider::where('name', 'Updated Slider')->exists())->toBeTrue();
});

it('deletes slider', function() {
$slider = Slider::create();

actingAsSuperUser()
->post(route('igniter.frontend.sliders', ['slug' => 'edit/'.$slider->getKey()]), [], [
'X-Requested-With' => 'XMLHttpRequest',
'X-IGNITER-REQUEST-HANDLER' => 'onDelete',
]);

expect(Slider::find($slider->getKey()))->toBeNull();
});

function actingAsSuperUser()
{
return test()->actingAs(User::factory()->superUser()->create(), 'igniter-admin');
}
2 changes: 2 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<?php

uses(SamPoyigi\Testbench\TestCase::class)->in(__DIR__);
14 changes: 0 additions & 14 deletions tests/TestCase.php

This file was deleted.

0 comments on commit 693566f

Please sign in to comment.