-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Enas
committed
Feb 23, 2023
1 parent
230f178
commit 346891d
Showing
8 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Illuminate\Contracts\Console\Kernel; | ||
|
||
trait CreatesApplication | ||
{ | ||
/** | ||
* Creates the application. | ||
* | ||
* @return \Illuminate\Foundation\Application | ||
*/ | ||
public function createApplication() | ||
{ | ||
$app = require __DIR__.'/../bootstrap/app.php'; | ||
|
||
$app->make(Kernel::class)->bootstrap(); | ||
|
||
return $app; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Corals\Modules\TroubleTicket\Facades\TroubleTickets; | ||
use Corals\Modules\TroubleTicket\Models\IssueType; | ||
use Corals\Modules\Utility\Category\Facades\Category; | ||
use Corals\User\Models\User; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Auth; | ||
use Tests\TestCase; | ||
|
||
class IssueTypesTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
protected $issueType; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); // TODO: Change the autogenerated stub | ||
|
||
$user = User::query()->whereHas('roles', function ($query) { | ||
$query->where('name', 'superuser'); | ||
})->first(); | ||
Auth::loginUsingId($user->id); | ||
} | ||
|
||
public function test_issue_types_store() | ||
{ | ||
$category = array_rand(Category::getCategoriesByParent('tt-categories')); | ||
$team = array_rand(TroubleTickets::getTeamsList()->toArray()); | ||
|
||
$response = $this->post( | ||
'trouble-ticket/issue-types', | ||
[ | ||
'title' => 'issue-type', | ||
'categories' => [$category], | ||
'team_id' => $team, | ||
'description' => 'issue-type', | ||
] | ||
); | ||
|
||
$this->issueType = IssueType::query()->where('title', 'issue-type')->first(); | ||
|
||
$response->assertDontSee('The given data was invalid') | ||
->assertRedirect('trouble-ticket/issue-types'); | ||
|
||
$this->assertDatabaseHas('tt_ticket_issue_types', [ | ||
'title' => $this->issueType->title, | ||
'team_id' => $this->issueType->team_id | ||
]); | ||
} | ||
|
||
public function test_issue_types_show() | ||
{ | ||
$this->test_issue_types_store(); | ||
|
||
if ($this->issueType) { | ||
$response = $this->get('trouble-ticket/issue-types/' . $this->issueType->hashed_id); | ||
|
||
$response->assertViewIs('TroubleTicket::issue_types.show')->assertStatus(200); | ||
} | ||
$this->assertTrue(true); | ||
} | ||
|
||
|
||
public function test_issue_types_edit() | ||
{ | ||
$this->test_issue_types_store(); | ||
|
||
if ($this->issueType) { | ||
$response = $this->get('trouble-ticket/issue-types/' . $this->issueType->hashed_id . '/edit'); | ||
|
||
$response->assertViewIs('TroubleTicket::issue_types.create_edit')->assertStatus(200); | ||
} | ||
$this->assertTrue(true); | ||
} | ||
|
||
public function test_issue_types_update() | ||
{ | ||
$this->test_issue_types_store(); | ||
|
||
if ($this->issueType) { | ||
$category = array_rand(Category::getCategoriesByParent('tt-categories')); | ||
|
||
$response = $this->put('trouble-ticket/issue-types/' . $this->issueType->hashed_id, [ | ||
'title' => $this->issueType->title, | ||
'team_id' => $this->issueType->team_id, | ||
'categories' => [$category], | ||
'description' => $this->issueType->description, | ||
]); | ||
|
||
$response->assertRedirect('trouble-ticket/issue-types'); | ||
$this->assertDatabaseHas('tt_ticket_issue_types', [ | ||
'title' => $this->issueType->title, | ||
'team_id' => $this->issueType->team_id | ||
]); | ||
} | ||
|
||
$this->assertTrue(true); | ||
} | ||
|
||
public function test_issue_types_delete() | ||
{ | ||
$this->test_issue_types_store(); | ||
|
||
if ($this->issueType) { | ||
$response = $this->delete('trouble-ticket/issue-types/' . $this->issueType->hashed_id); | ||
|
||
$response->assertStatus(200)->assertSeeText('Issue Type has been deleted successfully.'); | ||
|
||
$this->isSoftDeletableModel(IssueType::class); | ||
$this->assertDatabaseMissing('tt_ticket_issue_types', [ | ||
'title' => $this->issueType->title, | ||
'team_id' => $this->issueType->team_id | ||
]); | ||
} | ||
$this->assertTrue(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Corals\Modules\TroubleTicket\Models\Team; | ||
use Corals\User\Models\User; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Auth; | ||
use Tests\TestCase; | ||
|
||
class TeamsTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
protected $team; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); // TODO: Change the autogenerated stub | ||
|
||
$user = User::query()->whereHas('roles', function ($query) { | ||
$query->where('name', 'superuser'); | ||
})->first(); | ||
Auth::loginUsingId($user->id); | ||
} | ||
|
||
public function test_teams_store() | ||
{ | ||
$user = array_rand(User::all()->pluck('name', 'id')->toArray()); | ||
|
||
$response = $this->post( | ||
'trouble-ticket/teams', | ||
[ | ||
'name' => 'team', | ||
'users' => [$user], | ||
] | ||
); | ||
|
||
$this->team = Team::query()->where('name', 'team')->first(); | ||
|
||
$response->assertDontSee('The given data was invalid') | ||
->assertRedirect('trouble-ticket/teams'); | ||
|
||
$this->assertDatabaseHas('tt_teams', [ | ||
'name' => $this->team->name, | ||
]); | ||
} | ||
|
||
public function test_teams_show() | ||
{ | ||
$this->test_teams_store(); | ||
|
||
if ($this->team) { | ||
$response = $this->get('trouble-ticket/teams/' . $this->team->hashed_id); | ||
|
||
$response->assertViewIs('TroubleTicket::teams.show')->assertStatus(200); | ||
} | ||
$this->assertTrue(true); | ||
} | ||
|
||
|
||
public function test_teams_edit() | ||
{ | ||
$this->test_teams_store(); | ||
|
||
if ($this->team) { | ||
$response = $this->get('trouble-ticket/teams/' . $this->team->hashed_id . '/edit'); | ||
|
||
$response->assertViewIs('TroubleTicket::teams.create_edit')->assertStatus(200); | ||
} | ||
$this->assertTrue(true); | ||
} | ||
|
||
public function test_teams_update() | ||
{ | ||
$this->test_teams_store(); | ||
|
||
if ($this->team) { | ||
$user = array_rand(User::all()->pluck('name', 'id')->toArray()); | ||
|
||
$response = $this->put('trouble-ticket/teams/' . $this->team->hashed_id, [ | ||
'name' => $this->team->name, | ||
'users' => [$user], | ||
]); | ||
|
||
$response->assertRedirect('trouble-ticket/teams'); | ||
$this->assertDatabaseHas('tt_teams', [ | ||
'name' => $this->team->name, | ||
]); | ||
} | ||
|
||
$this->assertTrue(true); | ||
} | ||
|
||
public function test_teams_delete() | ||
{ | ||
$this->test_teams_store(); | ||
|
||
if ($this->team) { | ||
$response = $this->delete('trouble-ticket/teams/' . $this->team->hashed_id); | ||
|
||
$response->assertStatus(200)->assertSeeText('Team has been deleted successfully.'); | ||
|
||
$this->isSoftDeletableModel(Team::class); | ||
$this->assertDatabaseMissing('tt_teams', [ | ||
'name' => $this->team->name, | ||
]); | ||
} | ||
$this->assertTrue(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Corals\Modules\TroubleTicket\Models\IssueType; | ||
use Corals\Modules\TroubleTicket\Models\TroubleTicket; | ||
use Corals\Modules\Utility\Category\Facades\Category; | ||
use Corals\Modules\Utility\ListOfValue\Facades\ListOfValues; | ||
use Corals\User\Models\User; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Auth; | ||
use Tests\TestCase; | ||
|
||
class TroubleTicketsTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
protected $troubleTicket; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); // TODO: Change the autogenerated stub | ||
|
||
$user = User::query()->whereHas('roles', function ($query) { | ||
$query->where('name', 'superuser'); | ||
})->first(); | ||
Auth::loginUsingId($user->id); | ||
} | ||
|
||
public function test_trouble_tickets_store() | ||
{ | ||
$status = array_rand(ListOfValues::get('tt_status')); | ||
$priority = array_rand(ListOfValues::get('tt_priority')); | ||
$category = array_rand(Category::getCategoriesByParent('tt-categories')); | ||
$issueType = array_rand(IssueType::all()->pluck('title', 'id')->toArray()); | ||
$owner = array_rand(User::all()->pluck('name', 'id')->toArray()); | ||
|
||
$response = $this->post( | ||
'trouble-ticket/trouble-tickets', | ||
[ | ||
'title' => 'trouble-ticket', | ||
'status' => $status, | ||
'priority' => $priority, | ||
'category_id' => $category, | ||
'issue_type_id' => $issueType, | ||
'owner_id' => $owner, | ||
'assignee_id'=>1, | ||
'description' => 'trouble-ticket' | ||
] | ||
); | ||
|
||
$this->troubleTicket = TroubleTicket::query()->where('title', 'trouble-ticket')->first(); | ||
|
||
$response->assertDontSee('The given data was invalid') | ||
->assertRedirect('trouble-ticket/trouble-tickets'); | ||
|
||
$this->assertDatabaseHas('tt_trouble_tickets', [ | ||
'title' => $this->troubleTicket->title, | ||
'status' => $this->troubleTicket->status, | ||
'priority' => $this->troubleTicket->priority, | ||
'category_id' => $this->troubleTicket->category_id, | ||
'issue_type_id' => $this->troubleTicket->issue_type_id, | ||
'owner_id' => $this->troubleTicket->owner_id, | ||
]); | ||
} | ||
|
||
public function test_trouble_tickets_delete() | ||
{ | ||
$this->test_trouble_tickets_store(); | ||
|
||
if ($this->troubleTicket) { | ||
$response = $this->delete('trouble-ticket/trouble-tickets/' . $this->troubleTicket->hashed_id); | ||
|
||
$response->assertStatus(200)->assertSeeText('Support Ticket has been deleted successfully.'); | ||
|
||
$this->isSoftDeletableModel(TroubleTicket::class); | ||
$this->assertDatabaseMissing('tt_trouble_tickets', [ | ||
'title' => $this->troubleTicket->title, | ||
'status' => $this->troubleTicket->status, | ||
'priority' => $this->troubleTicket->priority, | ||
'category_id' => $this->troubleTicket->category_id, | ||
'issue_type_id' => $this->troubleTicket->issue_type_id, | ||
'owner_id' => $this->troubleTicket->owner_id, | ||
]); | ||
} | ||
$this->assertTrue(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
use CreatesApplication; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Corals\User\Models\User; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Auth; | ||
use Tests\TestCase; | ||
|
||
class IssueTypesViewTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); // TODO: Change the autogenerated stub | ||
|
||
$user = User::query()->whereHas('roles', function ($query) { | ||
$query->where('name', 'superuser'); | ||
})->first(); | ||
Auth::loginUsingId($user->id); | ||
} | ||
|
||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function test_issue_types_view() | ||
{ | ||
$response = $this->get('trouble-ticket/issue-types'); | ||
|
||
$response->assertStatus(200)->assertViewIs('TroubleTicket::issue_types.index'); | ||
} | ||
|
||
public function test_issue_types_create() | ||
{ | ||
$response = $this->get('trouble-ticket/issue-types/create'); | ||
|
||
$response->assertViewIs('TroubleTicket::issue_types.create_edit')->assertStatus(200); | ||
} | ||
} |
Oops, something went wrong.