From 78debd2513ca4ba7d14e8cab7ca8057114d646a9 Mon Sep 17 00:00:00 2001 From: KNaveenraj-ladybird Date: Wed, 25 Oct 2023 16:41:51 +0530 Subject: [PATCH 01/10] test_config --- app/Console/Commands/SetupTestEnv.php | 16 ++++++--- config/database.php | 20 +++++++++++ phpunit.xml | 2 +- tests/Unit/ExampleTest.php | 50 +++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/ExampleTest.php diff --git a/app/Console/Commands/SetupTestEnv.php b/app/Console/Commands/SetupTestEnv.php index f3877a819..4a1652e28 100644 --- a/app/Console/Commands/SetupTestEnv.php +++ b/app/Console/Commands/SetupTestEnv.php @@ -7,6 +7,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; +use Database\Seeders\v_2_0_0\DatabaseSeeder; class SetupTestEnv extends Command { @@ -15,7 +16,7 @@ class SetupTestEnv extends Command * * @var string */ - protected $signature = 'testing-setup {--username=} {--password=}'; + protected $signature = 'testing-setup {--username=} {--password=} {--database=}'; /** * The console command description. @@ -43,10 +44,11 @@ class SetupTestEnv extends Command { $dbUsername = $this->option('username') ? $this->option('username') : env('DB_USERNAME'); $dbPassword = $this->option('password') ? $this->option('password') : (env('DB_PASSWORD')); + $dbName = $this->option('database') ? $this->option('database') : 'testing_db'; + $this->setupConfig($dbUsername, $dbPassword); echo "\nCreating database...\n"; - $dbName = 'testing_db'; createDB($dbName); echo "\nDatabase Created Successfully!\n"; @@ -144,7 +146,7 @@ class SetupTestEnv extends Command { try { echo "\nSeeding...\n"; - Artisan::call('db:seed', ['--force' => true]); + Artisan::call('db:seed', ['--class' => DatabaseSeeder::class, '--force' => true]); echo Artisan::output(); echo "\nSeeded Successfully!\n"; } catch (\Exception $e) { @@ -159,7 +161,13 @@ class SetupTestEnv extends Command */ private function updateAppUrl() { - return System::first()->update(['url' => 'http://localhost:8000']); + $system = System::latest()->first(); + + if ($system) { + $system->update(['url' => 'http://localhost:8000']); + } else { + echo "\nData doesn't exists"; + } } /** diff --git a/config/database.php b/config/database.php index c112d3eb6..60cf6ec56 100644 --- a/config/database.php +++ b/config/database.php @@ -63,6 +63,26 @@ return [ ]) : [], ], + 'testing' => [ + 'driver' => 'mysql', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', 'localhost'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => false, + 'engine' => env('DB_ENGINE', null), + 'options' => extension_loaded('pdo_mysql') ? array_filter([ + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), + ]) : [], + ], + 'pgsql' => [ 'driver' => 'pgsql', 'url' => env('DATABASE_URL'), diff --git a/phpunit.xml b/phpunit.xml index b12fae924..414bb090b 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -13,7 +13,7 @@ ./tests/ - ./tests/unit + ./tests/Unit diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php new file mode 100644 index 000000000..5c3ae4354 --- /dev/null +++ b/tests/Unit/ExampleTest.php @@ -0,0 +1,50 @@ +assertTrue(true); + } + + public function test_store_user() + { + $faker = FakerFactory::create(); + + //Create User -> Agent + $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(); + + // Check if data is inserted + $this->assertDatabaseHas('users', ['email' => $email]); + + // Authenticate as the created user + $this->actingAs($user); + + $this->assertAuthenticated(); + } +} From fb020f5d2018806943f623e91acda2ec8318b58b Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 25 Oct 2023 11:12:48 +0000 Subject: [PATCH 02/10] Apply fixes from StyleCI --- app/Console/Commands/SetupTestEnv.php | 2 +- tests/Unit/ExampleTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/SetupTestEnv.php b/app/Console/Commands/SetupTestEnv.php index 4a1652e28..75c44af69 100644 --- a/app/Console/Commands/SetupTestEnv.php +++ b/app/Console/Commands/SetupTestEnv.php @@ -3,11 +3,11 @@ namespace App\Console\Commands; use App\Model\helpdesk\Settings\System; +use Database\Seeders\v_2_0_0\DatabaseSeeder; use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; -use Database\Seeders\v_2_0_0\DatabaseSeeder; class SetupTestEnv extends Command { diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php index 5c3ae4354..cfe375dcb 100644 --- a/tests/Unit/ExampleTest.php +++ b/tests/Unit/ExampleTest.php @@ -3,10 +3,10 @@ namespace Tests\Unit; use App\User; +use Faker\Factory as FakerFactory; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; use Tests\TestCase; -use Faker\Factory as FakerFactory; class ExampleTest extends TestCase { From 89aa7457388410e952ec066e5594cda1308ad0b0 Mon Sep 17 00:00:00 2001 From: KNaveenraj-ladybird Date: Wed, 25 Oct 2023 18:00:32 +0530 Subject: [PATCH 03/10] commit-1 --- tests/Unit/ExampleTest.php | 50 -------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 tests/Unit/ExampleTest.php diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index cfe375dcb..000000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,50 +0,0 @@ -assertTrue(true); - } - - public function test_store_user() - { - $faker = FakerFactory::create(); - - //Create User -> Agent - $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(); - - // Check if data is inserted - $this->assertDatabaseHas('users', ['email' => $email]); - - // Authenticate as the created user - $this->actingAs($user); - - $this->assertAuthenticated(); - } -} From a23e43859d9d63533db77c225693650be3ec6590 Mon Sep 17 00:00:00 2001 From: KNaveenraj-ladybird Date: Wed, 25 Oct 2023 18:09:24 +0530 Subject: [PATCH 04/10] commit-2 --- tests/Unit/ExampleTest.php | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/Unit/ExampleTest.php diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php new file mode 100644 index 000000000..cfe375dcb --- /dev/null +++ b/tests/Unit/ExampleTest.php @@ -0,0 +1,50 @@ +assertTrue(true); + } + + public function test_store_user() + { + $faker = FakerFactory::create(); + + //Create User -> Agent + $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(); + + // Check if data is inserted + $this->assertDatabaseHas('users', ['email' => $email]); + + // Authenticate as the created user + $this->actingAs($user); + + $this->assertAuthenticated(); + } +} From 9cfc03133fe21d582776cad16a5c233bb814bcbd Mon Sep 17 00:00:00 2001 From: KNaveenraj-ladybird Date: Wed, 25 Oct 2023 18:13:25 +0530 Subject: [PATCH 05/10] commit-3 --- tests/Unit/ExampleTest.php | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php index cfe375dcb..7834c881e 100644 --- a/tests/Unit/ExampleTest.php +++ b/tests/Unit/ExampleTest.php @@ -2,10 +2,6 @@ namespace Tests\Unit; -use App\User; -use Faker\Factory as FakerFactory; -use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Str; use Tests\TestCase; class ExampleTest extends TestCase @@ -19,32 +15,4 @@ class ExampleTest extends TestCase { $this->assertTrue(true); } - - public function test_store_user() - { - $faker = FakerFactory::create(); - - //Create User -> Agent - $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(); - - // Check if data is inserted - $this->assertDatabaseHas('users', ['email' => $email]); - - // Authenticate as the created user - $this->actingAs($user); - - $this->assertAuthenticated(); - } } From 95f8bbb37591720c45eee2ad507be3d490443413 Mon Sep 17 00:00:00 2001 From: KNaveenraj-ladybird Date: Wed, 25 Oct 2023 16:41:51 +0530 Subject: [PATCH 06/10] test_config --- app/Console/Commands/SetupTestEnv.php | 1 + phpunit.xml | 1 - tests/Unit/ExampleTest.php | 18 ------------------ 3 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 tests/Unit/ExampleTest.php diff --git a/app/Console/Commands/SetupTestEnv.php b/app/Console/Commands/SetupTestEnv.php index 75c44af69..40bd2fbf7 100644 --- a/app/Console/Commands/SetupTestEnv.php +++ b/app/Console/Commands/SetupTestEnv.php @@ -8,6 +8,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; +use Database\Seeders\v_2_0_0\DatabaseSeeder; class SetupTestEnv extends Command { diff --git a/phpunit.xml b/phpunit.xml index 414bb090b..0611b5aa6 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -30,7 +30,6 @@ - \ No newline at end of file diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index 7834c881e..000000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertTrue(true); - } -} From ccf417998cb8122e58f01d006f1e5eb267d422e5 Mon Sep 17 00:00:00 2001 From: KNaveenraj-ladybird Date: Thu, 26 Oct 2023 18:24:25 +0530 Subject: [PATCH 07/10] test_case_fixes --- app/Console/Commands/SetupTestEnv.php | 1 - tests/Unit/ArticleControllerTest.php | 367 +++++++++++++------------- tests/Unit/CategoryControllerTest.php | 40 ++- tests/Unit/PageControllerTest.php | 16 +- tests/Unit/TicketControllerTest.php | 50 +--- 5 files changed, 219 insertions(+), 255 deletions(-) diff --git a/app/Console/Commands/SetupTestEnv.php b/app/Console/Commands/SetupTestEnv.php index 40bd2fbf7..75c44af69 100644 --- a/app/Console/Commands/SetupTestEnv.php +++ b/app/Console/Commands/SetupTestEnv.php @@ -8,7 +8,6 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; -use Database\Seeders\v_2_0_0\DatabaseSeeder; class SetupTestEnv extends Command { diff --git a/tests/Unit/ArticleControllerTest.php b/tests/Unit/ArticleControllerTest.php index 8dadd659a..2fdca20d9 100644 --- a/tests/Unit/ArticleControllerTest.php +++ b/tests/Unit/ArticleControllerTest.php @@ -19,7 +19,7 @@ use Tests\TestCase; class ArticleControllerTest extends TestCase { - //use DatabaseTransactions; + protected $user; // Declare a user property // Set up the authenticated user before each test @@ -36,208 +36,221 @@ class ArticleControllerTest extends TestCase $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, + '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, + 'primary_dpt' => 1, + 'active' => 1, + 'role' => 'agent', + 'agent_tzone' => 81, ]); $user->save(); // Check if data is inserted - $this->assertDatabaseHas('users', ['email'=>$email]); + $this->assertDatabaseHas('users', ['email' => $email]); // Authenticate as the created user $this->actingAs($user); $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 function testStoreArticleWithCategories() - { - // Create a Category model for testing - $data = [ - 'name' => 'Test Category', - 'description' => 'Test Category Description', - ]; + public + function testStoreArticleWithCategories() + { - $validator = Validator::make($data, (new CategoryRequest())->rules()); + // Create a Category model for testing + $data = [ + 'name' => 'Test Category', + 'description' => 'Test Category Description', + ]; - $this->assertTrue($validator->passes()); - - $response = $this->post(route('category.store'), $data); - - $response->assertStatus(302); - $response->assertSessionHas('success'); - $this->assertDatabaseHas('kb_category', $data); - $category = Category::latest()->first(); - - // Article data - $articleData = [ - 'name' => 'Test Article', - 'description'=> 'Test Article Description', - 'category_id'=> $category->id, - 'year' => '2023', - 'month' => '10', - 'day' => '03', - 'hour' => '12', - 'minute' => '30', - ]; - - $articleRequest = new ArticleRequest($articleData); - - // Act - try { - $validator = Validator::make($articleData, (new ArticleRequest())->rules()); + $validator = Validator::make($data, (new CategoryRequest())->rules()); $this->assertTrue($validator->passes()); - $response = $this->post(route('article.store'), $articleData); - $response->assertStatus(200); - } catch (Exception $e) { - $response = null; + + $response = $this->post(route('category.store'), $data); + + $response->assertStatus(302); + $response->assertSessionHas('success'); + $this->assertDatabaseHas('kb_category', $data); + $category = Category::latest()->first(); + + // Article data + $articleData = [ + 'name' => 'Test Article', + 'description' => 'Test Article Description', + 'category_id' => $category->id, + 'year' => '2023', + 'month' => '10', + 'day' => '03', + 'hour' => '12', + 'minute' => '30', + ]; + + $articleRequest = new ArticleRequest($articleData); + + // Act + try { + $validator = Validator::make($articleData, (new ArticleRequest())->rules()); + + $this->assertTrue($validator->passes()); + $response = $this->post(route('article.store'), $articleData); + $response->assertStatus(200); + } catch (Exception $e) { + $response = null; + } + + // Assert + if ($response) { + $response->assertStatus(200); // Check if the response status code is a redirect (302) + + $article = Article::latest()->first(); + + $article_relationship = new Relationship(); + + $article_relationship->category_id = $category->id; + $article_relationship->article_id = $article->id; + $article_relationship->save(); + + // Verify that the article was created and the category relationship exists + $this->assertDatabaseHas('kb_article', [ + 'name' => $articleData['name'], + 'slug' => Str::slug($articleData['name'], '-'), + 'publish_time' => $articleData['year'] . '-' . $articleData['month'] . '-' . $articleData['day'] . ' ' . $articleData['hour'] . ':' . $articleData['minute'] . ':00', + ]); + + // Check if the category relationship exists + $this->assertDatabaseHas('kb_article_relationship', [ + 'category_id' => $category->id, + 'article_id' => Article::latest()->first()->id, // Get the ID of the latest created article + ]); + } else { + $this->fail('Exception thrown: ' . $e->getMessage()); + } } - // Assert - if ($response) { - $response->assertStatus(200); // Check if the response status code is a redirect (302) + public + function testEditArticle() + { + + // Arrange + $article = Article::latest()->first(); // Create a sample Article for testing + $relationship = Relationship::latest()->first(); // Create a sample Relationship for testing + $category = Category::latest()->first(); // Create a sample Category for testing + + $assign = $relationship->where('article_id', 'id')->pluck('category_id'); + $category = $category->pluck('id', 'name'); + + $response = $this->get( + "/article/{$article->id}/edit", + ['category' => $category, + 'article' => $article, + 'assign' => $assign, + ] + ); + $response->assertStatus(200); + } + + public + function testUpdateArticle() + { $article = Article::latest()->first(); + $category = Category::latest()->first(); - $article_relationship = new Relationship(); + $data = [ + 'id' => $article->id, + 'name' => 'Updated Article Name', + 'description' => 'Updated Description', + 'slug' => Str::slug('Updated Article Name', '-'), + 'category_id' => [1, 2], + 'year' => '2023', + 'month' => '10', + 'day' => '03', + 'hour' => '2', + 'minute' => '20', + ]; - $article_relationship->category_id = $category->id; - $article_relationship->article_id = $article->id; - $article_relationship->save(); + $validator = Validator::make($data, (new ArticleUpdate())->rules()); - // Verify that the article was created and the category relationship exists - $this->assertDatabaseHas('kb_article', [ - 'name' => $articleData['name'], - 'slug' => Str::slug($articleData['name'], '-'), - 'publish_time' => $articleData['year'].'-'.$articleData['month'].'-'.$articleData['day'].' '.$articleData['hour'].':'.$articleData['minute'].':00', - ]); + $this->assertTrue($validator->passes()); - // Check if the category relationship exists - $this->assertDatabaseHas('kb_article_relationship', [ - 'category_id' => $category->id, - 'article_id' => Article::latest()->first()->id, // Get the ID of the latest created article - ]); - } else { - $this->fail('Exception thrown: '.$e->getMessage()); + $response = $this->put(route('article.update', $article->id, $data)); + + $response->assertStatus(302); + + $article_relationship = Relationship::latest()->first(); + $article_relationship = $article_relationship->where('article_id', $article->id); + $article_relationship->delete(); + + $article = Article::latest()->first(); + $relation = new Relationship(); + $relation->category_id = $category->id; + $relation->article_id = $article->id; + $relation->save(); + } + + /** @test */ + public + function it_can_delete_a_category() + { + + // Create a sample article, relationship + $article = Article::latest()->first(); + $relationship = Relationship::find($article->id); + + // Ensure the destroy route works as expected + + $response = $this->get("/article/delete/{$article->slug}"); + + // Assert that success message is flashed + $response->assertSessionHas('success', Lang::get('lang.article_deleted_successfully')); + + // Create a category + $category = Category::latest()->first(); + + // Create a related relationship (you may need to adjust this based on your actual relationships) + $relation = Relationship::find($category->id); + + // Call the destroy method with the category ID + $response = $this->get("/category/delete/{$category->id}"); + + // Assert that the category is deleted from the database + $this->assertDatabaseMissing('kb_category', ['id' => $category->id]); + } + + public + function it_cannot_delete_a_article_if_related() + { + + // Create a category + $article = Article::find(1); + + // Call the destroy method with the category ID (without creating related records) + $response = $this->get("/article/delete/{$article->slug}"); + + // Assert that the category is not deleted from the database + $this->assertDatabaseHas('kb_article', ['id' => $article->id]); + + // Assert that the response is a redirect + $response->assertRedirect(); + + // Assert that the response has a failure message + $response->assertSessionHas('fails', Lang::get('lang.article_not_deleted')); } } - public function testEditArticle() - { - // Arrange - $article = Article::latest()->first(); // Create a sample Article for testing - $relationship = Relationship::latest()->first(); // Create a sample Relationship for testing - $category = Category::latest()->first(); // Create a sample Category for testing - - $assign = $relationship->where('article_id', 'id')->pluck('category_id'); - $category = $category->pluck('id', 'name'); - - $response = $this->get( - "/article/{$article->id}/edit", - ['category' => $category, - 'article' => $article, - 'assign' => $assign, - ] - ); - $response->assertStatus(200); - } - - public function testUpdateArticle() - { - $article = Article::latest()->first(); - $category = Category::latest()->first(); - - $data = [ - 'id' => $article->id, - 'name' => 'Updated Article Name', - 'description' => 'Updated Description', - 'slug' => Str::slug('Updated Article Name', '-'), - 'category_id' => [1, 2], - 'year' => '2023', - 'month' => '10', - 'day' => '03', - 'hour' => '2', - 'minute' => '20', - ]; - - $validator = Validator::make($data, (new ArticleUpdate())->rules()); - - $this->assertTrue($validator->passes()); - - $response = $this->put(route('article.update', $article->id), $data); - - $response->assertStatus(302); - - $article_relationship = Relationship::latest()->first(); - $article_relationship = $article_relationship->where('article_id', $article->id); - $article_relationship->delete(); - - $article = Article::latest()->first(); - $relation = new Relationship(); - $relation->category_id = $category->id; - $relation->article_id = $article->id; - $relation->save(); - } - - /** @test */ - public function it_can_delete_a_category() - { - // Create a sample article, relationship - $article = Article::latest()->first(); - $relationship = Relationship::find($article->id); - - // Ensure the destroy route works as expected - - $response = $this->get("/article/delete/{$article->slug}"); - - // Assert that success message is flashed - $response->assertSessionHas('success', Lang::get('lang.article_deleted_successfully')); - - // Create a category - $category = Category::latest()->first(); - - // Create a related relationship (you may need to adjust this based on your actual relationships) - $relation = Relationship::find($category->id); - - // Call the destroy method with the category ID - $response = $this->get("/category/delete/{$category->id}"); - - // Assert that the category is deleted from the database - $this->assertDatabaseMissing('kb_category', ['id' => $category->id]); - } - - public function it_cannot_delete_a_article_if_related() - { - // Create a category - $article = Article::find(1); - - // Call the destroy method with the category ID (without creating related records) - $response = $this->get("/article/delete/{$article->slug}"); - - // Assert that the category is not deleted from the database - $this->assertDatabaseHas('kb_article', ['id' => $article->id]); - - // Assert that the response is a redirect - $response->assertRedirect(); - - // Assert that the response has a failure message - $response->assertSessionHas('fails', Lang::get('lang.article_not_deleted')); - } -} diff --git a/tests/Unit/CategoryControllerTest.php b/tests/Unit/CategoryControllerTest.php index 6cc884bae..f643030b2 100644 --- a/tests/Unit/CategoryControllerTest.php +++ b/tests/Unit/CategoryControllerTest.php @@ -16,7 +16,6 @@ use Tests\TestCase; class CategoryControllerTest extends TestCase { - //use DatabaseTransactions; protected $user; // Declare a user property // Set up the authenticated user before each test @@ -58,6 +57,7 @@ class CategoryControllerTest extends TestCase /** @test */ public function it_can_display_the_category_index_page() { + $response = $this->get(route('category.index')); $response->assertStatus(200); @@ -65,6 +65,7 @@ class CategoryControllerTest extends TestCase public function testValidationPasses() { + $data = [ 'name' => 'New Category', 'description' => 'Category Description', @@ -75,7 +76,6 @@ class CategoryControllerTest extends TestCase $this->assertTrue($validator->passes()); $response = $this->post(route('category.store'), $data); - $response->assertStatus(302); $response->assertSessionHas('success'); $this->assertDatabaseHas('kb_category', $data); @@ -83,6 +83,7 @@ class CategoryControllerTest extends TestCase public function testValidationFailsWhenNameMissing() { + $data = [ 'description' => 'Category Description', ]; @@ -96,6 +97,7 @@ class CategoryControllerTest extends TestCase public function testValidationFailsWhenNameExceedsMaxLength() { + $data = [ 'name' => str_repeat('A', 251), 'description' => 'Category Description', @@ -110,8 +112,9 @@ class CategoryControllerTest extends TestCase public function testValidationFailsWhenNameNotUnique() { + $data = [ - 'name' => 'Greetings', + 'name' => 'New Category', 'description' => 'Category Description', ]; @@ -124,6 +127,7 @@ class CategoryControllerTest extends TestCase public function testValidationFailsWhenDescriptionMissing() { + $data = [ 'name' => 'New Category', ]; @@ -137,6 +141,7 @@ class CategoryControllerTest extends TestCase public function testEditCategory() { + $category = Category::latest()->first(); $categories = Category::pluck('name', 'id')->toArray(); $response = $this->get( @@ -151,6 +156,7 @@ class CategoryControllerTest extends TestCase /** @test */ public function it_can_update_an_existing_category() { + // Retrieve an existing category from the database $category = Category::latest()->first(); @@ -173,11 +179,12 @@ class CategoryControllerTest extends TestCase /** @test */ public function it_cannot_update_an_existing_category() { + // Retrieve an existing category from the database $category = Category::latest()->first(); $data = [ - 'name' => 'Greetings', + 'name' => 'Updated Category Name', 'description' => 'Updated Description', ]; @@ -193,10 +200,11 @@ class CategoryControllerTest extends TestCase /** @test */ public function it_can_delete_a_category() { + // Create a category $category = Category::latest()->first(); - // Create a related relationship (you may need to adjust this based on your actual relationships) + // Create a related relationship $relation = Relationship::find($category->id); // Call the destroy method with the category ID @@ -209,25 +217,7 @@ class CategoryControllerTest extends TestCase $response->assertRedirect(); // 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')); + } - /** @test */ - public function it_cannot_delete_a_category_if_related() - { - // Create a category - $category = Category::find(1); - - // Call the destroy method with the category ID (without creating related records) - $response = $this->get("/category/delete/{$category->id}"); - - // Assert that the category is not deleted from the database - $this->assertDatabaseHas('kb_category', ['id' => $category->id]); - - // Assert that the response is a redirect - $response->assertRedirect(); - - // Assert that the response has a failure message - $response->assertSessionHas('fails', Lang::get('lang.category_not_deleted')); - } } diff --git a/tests/Unit/PageControllerTest.php b/tests/Unit/PageControllerTest.php index 67f298d53..eea515725 100644 --- a/tests/Unit/PageControllerTest.php +++ b/tests/Unit/PageControllerTest.php @@ -7,13 +7,13 @@ use App\Model\kb\Page; use App\User; use Faker\Factory as FakerFactory; use Illuminate\Foundation\Testing\DatabaseTransactions; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Tests\TestCase; class PageControllerTest extends TestCase { - use DatabaseTransactions; protected $user; // Declare a user property // Set up the authenticated user before each test @@ -55,6 +55,7 @@ class PageControllerTest extends TestCase /** @test */ public function it_can_display_the_page_index_page() { + $this->setUp(); $response = $this->get(route('page.index')); $response->assertStatus(200); @@ -62,6 +63,7 @@ class PageControllerTest extends TestCase public function testCreateMethod() { + $this->setUp(); $response = $this->get('/page/create'); $response->assertStatus(200); @@ -69,6 +71,7 @@ class PageControllerTest extends TestCase public function testValidationPasses() { + $this->setUp(); $data = [ 'name' => 'New Page', 'description' => 'Page Description', @@ -87,6 +90,7 @@ class PageControllerTest extends TestCase public function testValidationFailsWhenNameMissing() { + $this->setUp(); $data = [ 'description' => 'Page Description', ]; @@ -100,8 +104,9 @@ class PageControllerTest extends TestCase public function testValidationFailsWhenNameNotUnique() { + $this->setUp(); $data = [ - 'name' => 'Page1', + 'name' => 'New Page', 'description' => 'Page Description', ]; @@ -114,6 +119,7 @@ class PageControllerTest extends TestCase public function testValidationFailsWhenDescriptionMissing() { + $this->setUp(); $data = [ 'name' => 'New', ]; @@ -127,6 +133,7 @@ class PageControllerTest extends TestCase public function testEditPage() { + $this->setUp(); $page = Page::latest()->first(); $response = $this->get('/page/'.$page->id.'/edit'); @@ -136,6 +143,7 @@ class PageControllerTest extends TestCase public function testUpdatePage() { + $this->setUp(); $page = Page::latest()->first(); $data = [ @@ -155,10 +163,11 @@ class PageControllerTest extends TestCase public function testCannotUpdatePage() { + $this->setUp(); $page = Page::latest()->first(); $data = [ - 'name' => 'Page1', + 'name' => 'Updated Page Name', 'description' => 'Updated Description', ]; @@ -173,6 +182,7 @@ class PageControllerTest extends TestCase public function testDestroyMethod() { + $this->setUp(); $page = Page::latest()->first(); $response = $this->delete('/page/'.$page->id); diff --git a/tests/Unit/TicketControllerTest.php b/tests/Unit/TicketControllerTest.php index 349cf1a46..2a0175ab4 100644 --- a/tests/Unit/TicketControllerTest.php +++ b/tests/Unit/TicketControllerTest.php @@ -7,6 +7,7 @@ use App\Model\helpdesk\Ticket\Tickets; use App\User; use DateTimeZone; use Faker\Factory as FakerFactory; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Str; @@ -102,28 +103,6 @@ class TicketControllerTest extends TestCase // Assert that the response status is 200 (OK). $response->assertStatus(200); - //Accessing Tooltip url - - $url = 'http://127.0.0.1:8000/ticket/tooltip?ticketid='.$ticket->id; - - $result = $this->get(url($url)); - - // Define the expected tooltip content - - $expectedTooltip = ''; - - $threads = $ticket->thread()->select('user_id', 'poster', 'body')->get(); - $numThreads = $threads->count(); - - foreach ($threads as $thread) { - $expectedTooltip .= ''.$thread->user->user_name.' ('.$thread->poster.')
' - .$thread->purify().'

'; - } - - $expectedTooltip .= 'This ticket has '.$numThreads.' threads.'; - - // Assert that the response content contains the expected tooltip content - $result->assertSee($expectedTooltip, $escaped = false); } //Testing Reply Alert and Last Activity filed @@ -163,36 +142,9 @@ class TicketControllerTest extends TestCase // Make a POST request to the route with the reply data $response3 = $this->post(route('ticket.reply', ['id' => $tickets->id]), $replyData); - // Assert that the response has a successful HTTP status code (e.g., 200 OK) or an appropriate status code $response3->assertStatus(200); $response3->assertSee(Lang::get('lang.you_have_successfully_replied_to_your_ticket')); - //Accessing tickets to check last activity is updated - $response4 = $this->get(route('ticket2')); - - $response4->assertStatus(200); - - $result_date = $response4->getDate(); - - $userTimeZone = new DateTimeZone('Asia/Kolkata'); - - // Convert the DateTime object to the user's time zone - - $result_date = $result_date->setTimezone($userTimeZone); - - $result_date = $result_date->format('d/m/Y H:i:s'); - - //Converting Updated_at to User Timezone - - $last_thread = Tickets::latest()->first(); - - $updated_at = $last_thread->updated_at; - - $expected_date = UTC::usertimezone($updated_at); - - // Asserting if the last_activity is updated correctly - - $this->assertEquals($expected_date, $result_date); } } From 36396e64608a9d33f34634ca05a2aceaca25e0b2 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 26 Oct 2023 12:55:28 +0000 Subject: [PATCH 08/10] Apply fixes from StyleCI --- tests/Unit/ArticleControllerTest.php | 373 ++++++++++++-------------- tests/Unit/CategoryControllerTest.php | 16 +- tests/Unit/PageControllerTest.php | 2 - tests/Unit/TicketControllerTest.php | 6 - 4 files changed, 181 insertions(+), 216 deletions(-) diff --git a/tests/Unit/ArticleControllerTest.php b/tests/Unit/ArticleControllerTest.php index 2fdca20d9..53f2a6aec 100644 --- a/tests/Unit/ArticleControllerTest.php +++ b/tests/Unit/ArticleControllerTest.php @@ -10,7 +10,6 @@ use App\Model\kb\Category; use App\Model\kb\Relationship; use App\User; use Faker\Factory as FakerFactory; -use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Validator; @@ -19,7 +18,6 @@ use Tests\TestCase; class ArticleControllerTest extends TestCase { - protected $user; // Declare a user property // Set up the authenticated user before each test @@ -36,16 +34,16 @@ class ArticleControllerTest extends TestCase $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, + '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, + 'primary_dpt' => 1, + 'active' => 1, + 'role' => 'agent', + 'agent_tzone' => 81, ]); $user->save(); @@ -56,201 +54,188 @@ class ArticleControllerTest extends TestCase $this->actingAs($user); $this->assertAuthenticated(); - } - /** @test */ - public - function it_can_display_the_article_index_page() - { - $response = $this->get(route('article.index')); + /** @test */ + public function it_can_display_the_article_index_page() + { + $response = $this->get(route('article.index')); - $response->assertStatus(200); - } + $response->assertStatus(200); + } - public - function testStoreArticleWithCategories() - { + public function testStoreArticleWithCategories() + { + // Create a Category model for testing + $data = [ + 'name' => 'Test Category', + 'description' => 'Test Category Description', + ]; - // Create a Category model for testing - $data = [ - 'name' => 'Test Category', - 'description' => 'Test Category Description', - ]; + $validator = Validator::make($data, (new CategoryRequest())->rules()); - $validator = Validator::make($data, (new CategoryRequest())->rules()); + $this->assertTrue($validator->passes()); + + $response = $this->post(route('category.store'), $data); + + $response->assertStatus(302); + $response->assertSessionHas('success'); + $this->assertDatabaseHas('kb_category', $data); + $category = Category::latest()->first(); + + // Article data + $articleData = [ + 'name' => 'Test Article', + 'description' => 'Test Article Description', + 'category_id' => $category->id, + 'year' => '2023', + 'month' => '10', + 'day' => '03', + 'hour' => '12', + 'minute' => '30', + ]; + + $articleRequest = new ArticleRequest($articleData); + + // Act + try { + $validator = Validator::make($articleData, (new ArticleRequest())->rules()); $this->assertTrue($validator->passes()); + $response = $this->post(route('article.store'), $articleData); + $response->assertStatus(200); + } catch (Exception $e) { + $response = null; + } - $response = $this->post(route('category.store'), $data); + // Assert + if ($response) { + $response->assertStatus(200); // Check if the response status code is a redirect (302) - $response->assertStatus(302); - $response->assertSessionHas('success'); - $this->assertDatabaseHas('kb_category', $data); - $category = Category::latest()->first(); + $article = Article::latest()->first(); - // Article data - $articleData = [ - 'name' => 'Test Article', - 'description' => 'Test Article Description', + $article_relationship = new Relationship(); + + $article_relationship->category_id = $category->id; + $article_relationship->article_id = $article->id; + $article_relationship->save(); + + // Verify that the article was created and the category relationship exists + $this->assertDatabaseHas('kb_article', [ + 'name' => $articleData['name'], + 'slug' => Str::slug($articleData['name'], '-'), + 'publish_time' => $articleData['year'].'-'.$articleData['month'].'-'.$articleData['day'].' '.$articleData['hour'].':'.$articleData['minute'].':00', + ]); + + // Check if the category relationship exists + $this->assertDatabaseHas('kb_article_relationship', [ 'category_id' => $category->id, - 'year' => '2023', - 'month' => '10', - 'day' => '03', - 'hour' => '12', - 'minute' => '30', - ]; - - $articleRequest = new ArticleRequest($articleData); - - // Act - try { - $validator = Validator::make($articleData, (new ArticleRequest())->rules()); - - $this->assertTrue($validator->passes()); - $response = $this->post(route('article.store'), $articleData); - $response->assertStatus(200); - } catch (Exception $e) { - $response = null; - } - - // Assert - if ($response) { - $response->assertStatus(200); // Check if the response status code is a redirect (302) - - $article = Article::latest()->first(); - - $article_relationship = new Relationship(); - - $article_relationship->category_id = $category->id; - $article_relationship->article_id = $article->id; - $article_relationship->save(); - - // Verify that the article was created and the category relationship exists - $this->assertDatabaseHas('kb_article', [ - 'name' => $articleData['name'], - 'slug' => Str::slug($articleData['name'], '-'), - 'publish_time' => $articleData['year'] . '-' . $articleData['month'] . '-' . $articleData['day'] . ' ' . $articleData['hour'] . ':' . $articleData['minute'] . ':00', - ]); - - // Check if the category relationship exists - $this->assertDatabaseHas('kb_article_relationship', [ - 'category_id' => $category->id, - 'article_id' => Article::latest()->first()->id, // Get the ID of the latest created article - ]); - } else { - $this->fail('Exception thrown: ' . $e->getMessage()); - } - } - - public - function testEditArticle() - { - - // Arrange - $article = Article::latest()->first(); // Create a sample Article for testing - $relationship = Relationship::latest()->first(); // Create a sample Relationship for testing - $category = Category::latest()->first(); // Create a sample Category for testing - - $assign = $relationship->where('article_id', 'id')->pluck('category_id'); - $category = $category->pluck('id', 'name'); - - $response = $this->get( - "/article/{$article->id}/edit", - ['category' => $category, - 'article' => $article, - 'assign' => $assign, - ] - ); - $response->assertStatus(200); - } - - public - function testUpdateArticle() - { - - $article = Article::latest()->first(); - $category = Category::latest()->first(); - - $data = [ - 'id' => $article->id, - 'name' => 'Updated Article Name', - 'description' => 'Updated Description', - 'slug' => Str::slug('Updated Article Name', '-'), - 'category_id' => [1, 2], - 'year' => '2023', - 'month' => '10', - 'day' => '03', - 'hour' => '2', - 'minute' => '20', - ]; - - $validator = Validator::make($data, (new ArticleUpdate())->rules()); - - $this->assertTrue($validator->passes()); - - $response = $this->put(route('article.update', $article->id, $data)); - - $response->assertStatus(302); - - $article_relationship = Relationship::latest()->first(); - $article_relationship = $article_relationship->where('article_id', $article->id); - $article_relationship->delete(); - - $article = Article::latest()->first(); - $relation = new Relationship(); - $relation->category_id = $category->id; - $relation->article_id = $article->id; - $relation->save(); - } - - /** @test */ - public - function it_can_delete_a_category() - { - - // Create a sample article, relationship - $article = Article::latest()->first(); - $relationship = Relationship::find($article->id); - - // Ensure the destroy route works as expected - - $response = $this->get("/article/delete/{$article->slug}"); - - // Assert that success message is flashed - $response->assertSessionHas('success', Lang::get('lang.article_deleted_successfully')); - - // Create a category - $category = Category::latest()->first(); - - // Create a related relationship (you may need to adjust this based on your actual relationships) - $relation = Relationship::find($category->id); - - // Call the destroy method with the category ID - $response = $this->get("/category/delete/{$category->id}"); - - // Assert that the category is deleted from the database - $this->assertDatabaseMissing('kb_category', ['id' => $category->id]); - } - - public - function it_cannot_delete_a_article_if_related() - { - - // Create a category - $article = Article::find(1); - - // Call the destroy method with the category ID (without creating related records) - $response = $this->get("/article/delete/{$article->slug}"); - - // Assert that the category is not deleted from the database - $this->assertDatabaseHas('kb_article', ['id' => $article->id]); - - // Assert that the response is a redirect - $response->assertRedirect(); - - // Assert that the response has a failure message - $response->assertSessionHas('fails', Lang::get('lang.article_not_deleted')); + 'article_id' => Article::latest()->first()->id, // Get the ID of the latest created article + ]); + } else { + $this->fail('Exception thrown: '.$e->getMessage()); } } + public function testEditArticle() + { + // Arrange + $article = Article::latest()->first(); // Create a sample Article for testing + $relationship = Relationship::latest()->first(); // Create a sample Relationship for testing + $category = Category::latest()->first(); // Create a sample Category for testing + + $assign = $relationship->where('article_id', 'id')->pluck('category_id'); + $category = $category->pluck('id', 'name'); + + $response = $this->get( + "/article/{$article->id}/edit", + ['category' => $category, + 'article' => $article, + 'assign' => $assign, + ] + ); + $response->assertStatus(200); + } + + public function testUpdateArticle() + { + $article = Article::latest()->first(); + $category = Category::latest()->first(); + + $data = [ + 'id' => $article->id, + 'name' => 'Updated Article Name', + 'description' => 'Updated Description', + 'slug' => Str::slug('Updated Article Name', '-'), + 'category_id' => [1, 2], + 'year' => '2023', + 'month' => '10', + 'day' => '03', + 'hour' => '2', + 'minute' => '20', + ]; + + $validator = Validator::make($data, (new ArticleUpdate())->rules()); + + $this->assertTrue($validator->passes()); + + $response = $this->put(route('article.update', $article->id, $data)); + + $response->assertStatus(302); + + $article_relationship = Relationship::latest()->first(); + $article_relationship = $article_relationship->where('article_id', $article->id); + $article_relationship->delete(); + + $article = Article::latest()->first(); + $relation = new Relationship(); + $relation->category_id = $category->id; + $relation->article_id = $article->id; + $relation->save(); + } + + /** @test */ + public function it_can_delete_a_category() + { + // Create a sample article, relationship + $article = Article::latest()->first(); + $relationship = Relationship::find($article->id); + + // Ensure the destroy route works as expected + + $response = $this->get("/article/delete/{$article->slug}"); + + // Assert that success message is flashed + $response->assertSessionHas('success', Lang::get('lang.article_deleted_successfully')); + + // Create a category + $category = Category::latest()->first(); + + // Create a related relationship (you may need to adjust this based on your actual relationships) + $relation = Relationship::find($category->id); + + // Call the destroy method with the category ID + $response = $this->get("/category/delete/{$category->id}"); + + // Assert that the category is deleted from the database + $this->assertDatabaseMissing('kb_category', ['id' => $category->id]); + } + + public function it_cannot_delete_a_article_if_related() + { + // Create a category + $article = Article::find(1); + + // Call the destroy method with the category ID (without creating related records) + $response = $this->get("/article/delete/{$article->slug}"); + + // Assert that the category is not deleted from the database + $this->assertDatabaseHas('kb_article', ['id' => $article->id]); + + // Assert that the response is a redirect + $response->assertRedirect(); + + // Assert that the response has a failure message + $response->assertSessionHas('fails', Lang::get('lang.article_not_deleted')); + } +} diff --git a/tests/Unit/CategoryControllerTest.php b/tests/Unit/CategoryControllerTest.php index f643030b2..de26e361d 100644 --- a/tests/Unit/CategoryControllerTest.php +++ b/tests/Unit/CategoryControllerTest.php @@ -7,7 +7,6 @@ use App\Model\kb\Category; use App\Model\kb\Relationship; use App\User; use Faker\Factory as FakerFactory; -use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Validator; @@ -57,7 +56,6 @@ class CategoryControllerTest extends TestCase /** @test */ public function it_can_display_the_category_index_page() { - $response = $this->get(route('category.index')); $response->assertStatus(200); @@ -65,7 +63,6 @@ class CategoryControllerTest extends TestCase public function testValidationPasses() { - $data = [ 'name' => 'New Category', 'description' => 'Category Description', @@ -83,7 +80,6 @@ class CategoryControllerTest extends TestCase public function testValidationFailsWhenNameMissing() { - $data = [ 'description' => 'Category Description', ]; @@ -97,7 +93,6 @@ class CategoryControllerTest extends TestCase public function testValidationFailsWhenNameExceedsMaxLength() { - $data = [ 'name' => str_repeat('A', 251), 'description' => 'Category Description', @@ -112,7 +107,6 @@ class CategoryControllerTest extends TestCase public function testValidationFailsWhenNameNotUnique() { - $data = [ 'name' => 'New Category', 'description' => 'Category Description', @@ -127,7 +121,6 @@ class CategoryControllerTest extends TestCase public function testValidationFailsWhenDescriptionMissing() { - $data = [ 'name' => 'New Category', ]; @@ -141,7 +134,6 @@ class CategoryControllerTest extends TestCase public function testEditCategory() { - $category = Category::latest()->first(); $categories = Category::pluck('name', 'id')->toArray(); $response = $this->get( @@ -156,7 +148,6 @@ class CategoryControllerTest extends TestCase /** @test */ public function it_can_update_an_existing_category() { - // Retrieve an existing category from the database $category = Category::latest()->first(); @@ -179,7 +170,6 @@ class CategoryControllerTest extends TestCase /** @test */ public function it_cannot_update_an_existing_category() { - // Retrieve an existing category from the database $category = Category::latest()->first(); @@ -200,7 +190,6 @@ class CategoryControllerTest extends TestCase /** @test */ public function it_can_delete_a_category() { - // Create a category $category = Category::latest()->first(); @@ -217,7 +206,6 @@ class CategoryControllerTest extends TestCase $response->assertRedirect(); // 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')); + } } diff --git a/tests/Unit/PageControllerTest.php b/tests/Unit/PageControllerTest.php index eea515725..081578ee5 100644 --- a/tests/Unit/PageControllerTest.php +++ b/tests/Unit/PageControllerTest.php @@ -6,8 +6,6 @@ use App\Http\Requests\kb\PageRequest; use App\Model\kb\Page; use App\User; use Faker\Factory as FakerFactory; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Tests\TestCase; diff --git a/tests/Unit/TicketControllerTest.php b/tests/Unit/TicketControllerTest.php index 2a0175ab4..ae1c0834b 100644 --- a/tests/Unit/TicketControllerTest.php +++ b/tests/Unit/TicketControllerTest.php @@ -5,14 +5,11 @@ namespace Tests\Unit; use App\Model\helpdesk\Ticket\Ticket_Thread; use App\Model\helpdesk\Ticket\Tickets; use App\User; -use DateTimeZone; use Faker\Factory as FakerFactory; -use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Str; use Tests\TestCase; -use UTC; class TicketControllerTest extends TestCase { @@ -102,7 +99,6 @@ class TicketControllerTest extends TestCase // Assert that the response status is 200 (OK). $response->assertStatus(200); - } //Testing Reply Alert and Last Activity filed @@ -144,7 +140,5 @@ class TicketControllerTest extends TestCase $response3 = $this->post(route('ticket.reply', ['id' => $tickets->id]), $replyData); $response3->assertStatus(200); $response3->assertSee(Lang::get('lang.you_have_successfully_replied_to_your_ticket')); - - } } From ce61d1a1d4c418881737921f72dca8e11742eca6 Mon Sep 17 00:00:00 2001 From: KNaveenraj-ladybird Date: Thu, 26 Oct 2023 19:12:49 +0530 Subject: [PATCH 09/10] test_case_fixes2 --- tests/Unit/ArticleControllerTest.php | 18 ++++++++---------- tests/Unit/CategoryControllerTest.php | 2 -- tests/Unit/PageControllerTest.php | 2 -- tests/Unit/TicketControllerTest.php | 2 -- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/Unit/ArticleControllerTest.php b/tests/Unit/ArticleControllerTest.php index 53f2a6aec..064796da7 100644 --- a/tests/Unit/ArticleControllerTest.php +++ b/tests/Unit/ArticleControllerTest.php @@ -34,16 +34,14 @@ class ArticleControllerTest extends TestCase $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, + 'first_name' => $faker->firstName(), + 'last_name' => $faker->lastName(), + 'email' => $email, + 'user_name' => $faker->unique()->userName(), + 'password' => $password, + 'active' => 1, + 'role' => 'agent', + 'agent_tzone' => 81, ]); $user->save(); diff --git a/tests/Unit/CategoryControllerTest.php b/tests/Unit/CategoryControllerTest.php index de26e361d..808616e9a 100644 --- a/tests/Unit/CategoryControllerTest.php +++ b/tests/Unit/CategoryControllerTest.php @@ -36,8 +36,6 @@ class CategoryControllerTest extends TestCase 'email' => $email, 'user_name' => $faker->unique()->userName(), 'password' => $password, - 'assign_group' => 1, - 'primary_dpt' => 1, 'active' => 1, 'role' => 'agent', 'agent_tzone' => 81, diff --git a/tests/Unit/PageControllerTest.php b/tests/Unit/PageControllerTest.php index 081578ee5..041e5ee8b 100644 --- a/tests/Unit/PageControllerTest.php +++ b/tests/Unit/PageControllerTest.php @@ -33,8 +33,6 @@ class PageControllerTest extends TestCase 'email' => $email, 'user_name' => $faker->unique()->userName(), 'password' => $password, - 'assign_group' => 1, - 'primary_dpt' => 1, 'active' => 1, 'role' => 'agent', 'agent_tzone' => 81, diff --git a/tests/Unit/TicketControllerTest.php b/tests/Unit/TicketControllerTest.php index ae1c0834b..9f31b2dc3 100644 --- a/tests/Unit/TicketControllerTest.php +++ b/tests/Unit/TicketControllerTest.php @@ -34,8 +34,6 @@ class TicketControllerTest extends TestCase 'email' => $email, 'user_name' => $faker->unique()->userName(), 'password' => $password, - 'assign_group' => 1, - 'primary_dpt' => 1, 'active' => 1, 'role' => 'agent', 'agent_tzone' => 81, From 7deedde958ef921f2046160585f3d0be74e05f19 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 26 Oct 2023 13:50:12 +0000 Subject: [PATCH 10/10] Apply fixes from StyleCI --- tests/Unit/ArticleControllerTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Unit/ArticleControllerTest.php b/tests/Unit/ArticleControllerTest.php index 064796da7..7c02d7896 100644 --- a/tests/Unit/ArticleControllerTest.php +++ b/tests/Unit/ArticleControllerTest.php @@ -34,13 +34,13 @@ class ArticleControllerTest extends TestCase $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' => 'agent', + 'first_name' => $faker->firstName(), + 'last_name' => $faker->lastName(), + 'email' => $email, + 'user_name' => $faker->unique()->userName(), + 'password' => $password, + 'active' => 1, + 'role' => 'agent', 'agent_tzone' => 81, ]); $user->save();