Unverified Commit 1890b5bb authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #103 from bvipul/develop

Added Manage Page Tests
parents c90fdf22 333f1a78
...@@ -50,7 +50,7 @@ class PagesRepository extends BaseRepository ...@@ -50,7 +50,7 @@ class PagesRepository extends BaseRepository
//Making extra fields //Making extra fields
$input['page_slug'] = str_slug($input['title']); $input['page_slug'] = str_slug($input['title']);
$input['status'] = isset($input['status']) ? 1 : 0; $input['status'] = isset($input['status']) ? 1 : 0;
$input['created_by'] = access()->user()->id; $input['created_by'] = auth()->id();
if ($page = Page::create($input)) { if ($page = Page::create($input)) {
event(new PageCreated($page)); event(new PageCreated($page));
......
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
}, },
"classmap": [ "classmap": [
"tests/TestCase.php" "tests/TestCase.php"
],
"files": [
"tests/Utilities/helpers.php"
] ]
}, },
"scripts": { "scripts": {
......
<?php
use App\Models\Page\Page;
use Faker\Generator as Faker;
$factory->define(Page::class, function (Faker $faker) {
$title = $faker->sentence;
return [
'title' => $title,
'page_slug' => str_slug($title),
'description' => $faker->paragraph,
'created_by' => 1
];
});
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
<env name="SCOUT_DRIVER" value="null"/> <env name="SCOUT_DRIVER" value="null"/>
</php> </php>
<testsuites> <!-- <testsuites>
<testsuite name="Application Test Suite"> <testsuite name="Application Test Suite">
<directory suffix="Test.php"> <directory suffix="Test.php">
./tests ./tests
</directory> </directory>
</testsuite> </testsuite>
</testsuites> </testsuites> -->
</phpunit> </phpunit>
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\Page\Page;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ManagePageTest extends TestCase
{
/** @test */
public function test_pages_index_route()
{
$this->actingAs($this->admin)
->get(route('admin.pages.index'))
->assertSee(trans('labels.backend.pages.management'))
->assertSee(trans('labels.backend.pages.table.title'))
->assertSee(trans('labels.backend.pages.table.status'))
->assertSee($this->admin->name);
}
/** @test */
public function test_create_and_edit_page_has_all_fields()
{
$this->actingAs($this->admin)
->get(route('admin.pages.create'))
->assertSee(trans('validation.attributes.backend.pages.title'))
->assertSee(trans('validation.attributes.backend.pages.description'))
->assertSee(trans('validation.attributes.backend.pages.cannonical_link'))
->assertSee(trans('validation.attributes.backend.pages.seo_title'))
->assertSee(trans('validation.attributes.backend.pages.seo_keyword'))
->assertSee(trans('validation.attributes.backend.pages.seo_description'))
->assertSee(trans('validation.attributes.backend.pages.is_active'));
$page = create(Page::class);
$this->actingAs($this->admin)
->get(route('admin.pages.edit', $page))
->assertSee(trans('validation.attributes.backend.pages.title'))
->assertSee(trans('validation.attributes.backend.pages.description'))
->assertSee(trans('validation.attributes.backend.pages.cannonical_link'))
->assertSee(trans('validation.attributes.backend.pages.seo_title'))
->assertSee(trans('validation.attributes.backend.pages.seo_keyword'))
->assertSee(trans('validation.attributes.backend.pages.seo_description'))
->assertSee(trans('validation.attributes.backend.pages.is_active'));
}
/** @test */
public function test_create_page_successfully()
{
$page = make(Page::class);
$this->actingAs($this->admin)
->post(route('admin.pages.store'), $page->toArray())
->assertRedirect(route('admin.pages.index'));
$this->assertDatabaseHas('pages', ['title' => $page->title, 'description' => $page->description]);
}
/** @test */
public function it_fails_for_validation_on_create_page()
{
$page = make(Page::class, ['title' => '', 'description' => '']);
$this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.pages.store'), $page->toArray())
->assertSessionHasErrors(['title', 'description']);
$page = make(Page::class, ['title' => '']);
$this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.pages.store'), $page->toArray())
->assertSessionHasErrors('title');
$page = make(Page::class, ['description' => '']);
$this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.pages.store'), $page->toArray())
->assertSessionHasErrors('description');
}
/** @test */
public function it_updates_successfully()
{
$page = create(Page::class);
$title = 'Changed title';
$slug = str_slug($title);
$description = 'Changed Description';
$this->actingAs($this->admin)
->patch(route('admin.pages.update', $page), ['title' => $title, 'description' => $description]);
$this->assertDatabaseHas('pages', ['id' => $page->id, 'title' => $title, 'page_slug' => $slug, 'description' => $description]);
}
/** @test */
public function it_fails_for_validation_on_update()
{
$page = create(Page::class);
$page1 = $page2 = $page3 = $page->toArray();
$page1['title'] = '';
$page1['description'] = '';
$this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.pages.store'), $page1)
->assertSessionHasErrors(['title', 'description']);
$page2['title'] = '';
$this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.pages.store'), $page2)
->assertSessionHasErrors('title');
$page3['description'] = '';
$this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.pages.store'), $page3)
->assertSessionHasErrors('description');
}
}
...@@ -6,6 +6,7 @@ use App\Models\Access\Role\Role; ...@@ -6,6 +6,7 @@ use App\Models\Access\Role\Role;
use App\Models\Access\User\User; use App\Models\Access\User\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
...@@ -73,4 +74,13 @@ abstract class TestCase extends BaseTestCase ...@@ -73,4 +74,13 @@ abstract class TestCase extends BaseTestCase
$this->executiveRole = Role::find(2); $this->executiveRole = Role::find(2);
$this->userRole = Role::find(3); $this->userRole = Role::find(3);
} }
public function tearDown()
{
$this->beforeApplicationDestroyed(function () {
DB::disconnect();
});
parent::tearDown();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment