test_case_fix

This commit is contained in:
KNaveenraj-ladybird
2023-10-26 22:32:54 +05:30
parent c24911a050
commit f8450a8ed8
6 changed files with 81 additions and 51 deletions

View File

@@ -1,23 +0,0 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class RouteTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_example()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}

View File

@@ -29,8 +29,7 @@ class ArticleControllerTest extends TestCase
//Create User -> Agent //Create User -> Agent
//$str = Str::random(10); $str = Str::random(10);
$str = 'demopass';
$password = Hash::make($str); $password = Hash::make($str);
$email = $faker->unique()->email(); $email = $faker->unique()->email();
$user = new User([ $user = new User([

View File

@@ -1,19 +0,0 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
class ArtisanCommandTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testRouteListCommand()
{
$this->artisan('route:list')
->assertExitCode(0);
}
}

View File

@@ -26,8 +26,7 @@ class CategoryControllerTest extends TestCase
//Create User -> Agent //Create User -> Agent
//$str = Str::random(10); $str = Str::random(10);
$str = 'demopass';
$password = Hash::make($str); $password = Hash::make($str);
$email = $faker->unique()->email(); $email = $faker->unique()->email();
$user = new User([ $user = new User([

View File

@@ -9,6 +9,7 @@ use Faker\Factory as FakerFactory;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Tests\TestCase; use Tests\TestCase;
Use Illuminate\Support\Str;
class PageControllerTest extends TestCase class PageControllerTest extends TestCase
{ {
@@ -23,8 +24,7 @@ class PageControllerTest extends TestCase
//Create User -> Agent //Create User -> Agent
//$str = Str::random(10); $str = Str::random(10);
$str = 'demopass';
$password = Hash::make($str); $password = Hash::make($str);
$email = $faker->unique()->email(); $email = $faker->unique()->email();
$user = new User([ $user = new User([

View File

@@ -9,7 +9,7 @@ use Faker\Factory as FakerFactory;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Lang;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Support\Str;
class TicketControllerTest extends TestCase class TicketControllerTest extends TestCase
{ {
/** /**
@@ -23,8 +23,7 @@ class TicketControllerTest extends TestCase
//Create User -> Agent //Create User -> Agent
//$str = Str::random(10); $str = Str::random(10);
$str = 'demopass';
$password = Hash::make($str); $password = Hash::make($str);
$email = $faker->unique()->email(); $email = $faker->unique()->email();
$user = new User([ $user = new User([
@@ -137,4 +136,79 @@ class TicketControllerTest extends TestCase
$response3->assertStatus(200); $response3->assertStatus(200);
$response3->assertSee(Lang::get('lang.you_have_successfully_replied_to_your_ticket')); $response3->assertSee(Lang::get('lang.you_have_successfully_replied_to_your_ticket'));
} }
public function test_user_change_the_status()
{
$faker = FakerFactory::create();
//Create User -> User
$str = Str::random(10);
$password = Hash::make($str);
$email = $faker->unique()->email();
$user = new User([
'first_name' => $faker->firstName(),
'last_name' => $faker->lastName(),
'email' => $email,
'user_name' => $faker->unique()->userName(),
'password' => $password,
'active' => 1,
'role' => 'user',
]);
$user->save();
// Authenticate as the created user
$this->actingAs($user);
$ticket = new Tickets(
[
'ticket_number' => 'AAAA-0000-0001',
'user_id' => $user->id,
'priority_id' => 2,
'sla' => 2,
'help_topic_id' => 1,
'status' => 1,
'source' => 1,
]
);
$ticket->save();
$ticket->dept_id = 1;
$ticket->save();
$ticket_thread = new Ticket_Thread(
[
'ticket_id' => $ticket->id,
'user_id' => $user->id,
'poster' => 'client',
'title' => 'TestCase',
'body' => 'Testing',
]
);
$ticket_thread->save();
$mytickets = $this->get(route('ticket2'));
$mytickets->assertStatus(200);
$response = $this->post(route('select_all'), [
'select_all' => [$ticket->id],
'submit' => 'Open',
]);
// Assert that the response status code indicates success
$response->assertStatus(302); // Adjust this as needed
// Assert that the ticket's status has been updated to open
$response->assertSessionHas('success', Lang::get('lang.tickets_have_been_opened'));
$response = $this->post(route('select_all'), [
'select_all' => [$ticket->id],
'submit' => 'Close',
]);
$response->assertStatus(302); // Adjust this as needed
$this->assertEquals(3, $ticket->fresh()->status); // Adjust this as needed
$response->assertSessionHas('success', Lang::get('lang.tickets_have_been_closed'));
}
} }