Apply fixes from StyleCI
This commit is contained in:

committed by
KNaveenraj-ladybird

parent
17f3d11c32
commit
e198e87e86
@@ -10,7 +10,6 @@ use App\Model\kb\Category;
|
|||||||
use App\Model\kb\Relationship;
|
use App\Model\kb\Relationship;
|
||||||
use App\User;
|
use App\User;
|
||||||
use Faker\Factory as FakerFactory;
|
use Faker\Factory as FakerFactory;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Facades\Lang;
|
use Illuminate\Support\Facades\Lang;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
@@ -19,7 +18,6 @@ use Tests\TestCase;
|
|||||||
|
|
||||||
class ArticleControllerTest extends TestCase
|
class ArticleControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $user; // Declare a user property
|
protected $user; // Declare a user property
|
||||||
|
|
||||||
// Set up the authenticated user before each test
|
// Set up the authenticated user before each test
|
||||||
@@ -56,22 +54,18 @@ class ArticleControllerTest extends TestCase
|
|||||||
$this->actingAs($user);
|
$this->actingAs($user);
|
||||||
|
|
||||||
$this->assertAuthenticated();
|
$this->assertAuthenticated();
|
||||||
|
|
||||||
}
|
}
|
||||||
/** @test */
|
|
||||||
public
|
|
||||||
function it_can_display_the_article_index_page()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_can_display_the_article_index_page()
|
||||||
|
{
|
||||||
$response = $this->get(route('article.index'));
|
$response = $this->get(route('article.index'));
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public
|
public function testStoreArticleWithCategories()
|
||||||
function testStoreArticleWithCategories()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// Create a Category model for testing
|
// Create a Category model for testing
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'Test Category',
|
'name' => 'Test Category',
|
||||||
@@ -143,10 +137,8 @@ class ArticleControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public
|
public function testEditArticle()
|
||||||
function testEditArticle()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
$article = Article::latest()->first(); // Create a sample Article for testing
|
$article = Article::latest()->first(); // Create a sample Article for testing
|
||||||
$relationship = Relationship::latest()->first(); // Create a sample Relationship for testing
|
$relationship = Relationship::latest()->first(); // Create a sample Relationship for testing
|
||||||
@@ -165,10 +157,8 @@ class ArticleControllerTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public
|
public function testUpdateArticle()
|
||||||
function testUpdateArticle()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$article = Article::latest()->first();
|
$article = Article::latest()->first();
|
||||||
$category = Category::latest()->first();
|
$category = Category::latest()->first();
|
||||||
|
|
||||||
@@ -205,10 +195,8 @@ class ArticleControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public
|
public function it_can_delete_a_category()
|
||||||
function it_can_delete_a_category()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// Create a sample article, relationship
|
// Create a sample article, relationship
|
||||||
$article = Article::latest()->first();
|
$article = Article::latest()->first();
|
||||||
$relationship = Relationship::find($article->id);
|
$relationship = Relationship::find($article->id);
|
||||||
@@ -233,10 +221,8 @@ class ArticleControllerTest extends TestCase
|
|||||||
$this->assertDatabaseMissing('kb_category', ['id' => $category->id]);
|
$this->assertDatabaseMissing('kb_category', ['id' => $category->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public
|
public function it_cannot_delete_a_article_if_related()
|
||||||
function it_cannot_delete_a_article_if_related()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// Create a category
|
// Create a category
|
||||||
$article = Article::find(1);
|
$article = Article::find(1);
|
||||||
|
|
||||||
@@ -253,4 +239,3 @@ class ArticleControllerTest extends TestCase
|
|||||||
$response->assertSessionHas('fails', Lang::get('lang.article_not_deleted'));
|
$response->assertSessionHas('fails', Lang::get('lang.article_not_deleted'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ use App\Model\kb\Category;
|
|||||||
use App\Model\kb\Relationship;
|
use App\Model\kb\Relationship;
|
||||||
use App\User;
|
use App\User;
|
||||||
use Faker\Factory as FakerFactory;
|
use Faker\Factory as FakerFactory;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Facades\Lang;
|
use Illuminate\Support\Facades\Lang;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
@@ -57,7 +56,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
public function it_can_display_the_category_index_page()
|
public function it_can_display_the_category_index_page()
|
||||||
{
|
{
|
||||||
|
|
||||||
$response = $this->get(route('category.index'));
|
$response = $this->get(route('category.index'));
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@@ -65,7 +63,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testValidationPasses()
|
public function testValidationPasses()
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'New Category',
|
'name' => 'New Category',
|
||||||
'description' => 'Category Description',
|
'description' => 'Category Description',
|
||||||
@@ -83,7 +80,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testValidationFailsWhenNameMissing()
|
public function testValidationFailsWhenNameMissing()
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'description' => 'Category Description',
|
'description' => 'Category Description',
|
||||||
];
|
];
|
||||||
@@ -97,7 +93,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testValidationFailsWhenNameExceedsMaxLength()
|
public function testValidationFailsWhenNameExceedsMaxLength()
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => str_repeat('A', 251),
|
'name' => str_repeat('A', 251),
|
||||||
'description' => 'Category Description',
|
'description' => 'Category Description',
|
||||||
@@ -112,7 +107,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testValidationFailsWhenNameNotUnique()
|
public function testValidationFailsWhenNameNotUnique()
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'New Category',
|
'name' => 'New Category',
|
||||||
'description' => 'Category Description',
|
'description' => 'Category Description',
|
||||||
@@ -127,7 +121,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testValidationFailsWhenDescriptionMissing()
|
public function testValidationFailsWhenDescriptionMissing()
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'New Category',
|
'name' => 'New Category',
|
||||||
];
|
];
|
||||||
@@ -141,7 +134,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testEditCategory()
|
public function testEditCategory()
|
||||||
{
|
{
|
||||||
|
|
||||||
$category = Category::latest()->first();
|
$category = Category::latest()->first();
|
||||||
$categories = Category::pluck('name', 'id')->toArray();
|
$categories = Category::pluck('name', 'id')->toArray();
|
||||||
$response = $this->get(
|
$response = $this->get(
|
||||||
@@ -156,7 +148,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
public function it_can_update_an_existing_category()
|
public function it_can_update_an_existing_category()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Retrieve an existing category from the database
|
// Retrieve an existing category from the database
|
||||||
$category = Category::latest()->first();
|
$category = Category::latest()->first();
|
||||||
|
|
||||||
@@ -179,7 +170,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
public function it_cannot_update_an_existing_category()
|
public function it_cannot_update_an_existing_category()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Retrieve an existing category from the database
|
// Retrieve an existing category from the database
|
||||||
$category = Category::latest()->first();
|
$category = Category::latest()->first();
|
||||||
|
|
||||||
@@ -200,7 +190,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
public function it_can_delete_a_category()
|
public function it_can_delete_a_category()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Create a category
|
// Create a category
|
||||||
$category = Category::latest()->first();
|
$category = Category::latest()->first();
|
||||||
|
|
||||||
@@ -219,5 +208,4 @@ class CategoryControllerTest extends TestCase
|
|||||||
// Assert that the response has a success message
|
// Assert that the response has a success message
|
||||||
$response->assertSessionHas('success', Lang::get('lang.category_deleted_successfully'));
|
$response->assertSessionHas('success', Lang::get('lang.category_deleted_successfully'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -6,8 +6,6 @@ use App\Http\Requests\kb\PageRequest;
|
|||||||
use App\Model\kb\Page;
|
use App\Model\kb\Page;
|
||||||
use App\User;
|
use App\User;
|
||||||
use Faker\Factory as FakerFactory;
|
use Faker\Factory as FakerFactory;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
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;
|
||||||
|
@@ -5,15 +5,101 @@ namespace Tests\Unit;
|
|||||||
use App\Model\helpdesk\Ticket\Ticket_Thread;
|
use App\Model\helpdesk\Ticket\Ticket_Thread;
|
||||||
use App\Model\helpdesk\Ticket\Tickets;
|
use App\Model\helpdesk\Ticket\Tickets;
|
||||||
use App\User;
|
use App\User;
|
||||||
use DateTimeZone;
|
|
||||||
use Faker\Factory as FakerFactory;
|
use Faker\Factory as FakerFactory;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
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;
|
||||||
|
|
||||||
class TicketControllerTest extends TestCase
|
class TicketControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* A basic unit test example.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function test_tooltip()
|
||||||
|
{
|
||||||
|
$faker = FakerFactory::create();
|
||||||
|
|
||||||
|
//Create User -> Agent
|
||||||
|
|
||||||
|
//$str = Str::random(10);
|
||||||
|
$str = 'demopass';
|
||||||
|
$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,
|
||||||
|
'assign_group' => 1,
|
||||||
|
'primary_dpt' => 1,
|
||||||
|
'active' => 1,
|
||||||
|
'role' => 'agent',
|
||||||
|
'agent_tzone' => 81,
|
||||||
|
]);
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
// Check if data is inserted
|
||||||
|
$this->assertDatabaseHas('users', ['email'=>$email]);
|
||||||
|
|
||||||
|
// Authenticate as the created user
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$this->assertAuthenticated();
|
||||||
|
|
||||||
|
// Define the dashboard route name
|
||||||
|
$dashboardRouteName = 'dashboard';
|
||||||
|
|
||||||
|
// Generate the dashboard route URL
|
||||||
|
$dashboardUrl = route($dashboardRouteName);
|
||||||
|
|
||||||
|
// Simulate a GET request to the dashboard route
|
||||||
|
$dashboardResponse = $this->get($dashboardUrl);
|
||||||
|
|
||||||
|
// Assert that the response status code is 200 (OK)
|
||||||
|
$dashboardResponse->assertStatus(200);
|
||||||
|
|
||||||
|
// Create a ticket for testing.
|
||||||
|
|
||||||
|
$ticket = new Tickets(
|
||||||
|
[
|
||||||
|
'ticket_number' => 'TEST-0000-000'.$faker->randomDigit(),
|
||||||
|
'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();
|
||||||
|
|
||||||
|
//Create Ticket_thread for Testing
|
||||||
|
|
||||||
|
$ticket_thread = new Ticket_Thread(
|
||||||
|
[
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'poster' => 'client',
|
||||||
|
'title' => 'TestCase2',
|
||||||
|
'body' => 'Testing2',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$ticket_thread->save();
|
||||||
|
|
||||||
|
// Make a GET request to the getTooltip
|
||||||
|
$response = $this->get(route('ticket.tooltip', ['ticket_id' => $ticket->id]));
|
||||||
|
|
||||||
|
// Assert that the response status is 200 (OK).
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
//Testing Reply Alert and Last Activity filed
|
//Testing Reply Alert and Last Activity filed
|
||||||
public function test_reply()
|
public function test_reply()
|
||||||
{
|
{
|
||||||
@@ -53,6 +139,5 @@ class TicketControllerTest extends TestCase
|
|||||||
$response3 = $this->post(route('ticket.reply', ['id' => $tickets->id]), $replyData);
|
$response3 = $this->post(route('ticket.reply', ['id' => $tickets->id]), $replyData);
|
||||||
$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'));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user