From 5cc2fc6cdb35a6552d4976a4f7c712724df78091 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 7 Oct 2018 16:18:41 +0800 Subject: [PATCH] Add validation tests on simple feature test --- src/stubs/testcases/feature/simple.stub | 87 +++++++++++ .../Generators/Simple/FeatureTestGeneratorTest.php | 174 +++++++++++++++++++++ 2 files changed, 261 insertions(+) diff --git a/src/stubs/testcases/feature/simple.stub b/src/stubs/testcases/feature/simple.stub index 6503141..988d381 100644 --- a/src/stubs/testcases/feature/simple.stub +++ b/src/stubs/testcases/feature/simple.stub @@ -42,6 +42,48 @@ class ManageMasterTest extends TestCase ]); } + private function getCreateFields(array $overrides = []) + { + return array_merge([ + 'name' => 'Master 1 name', + 'description' => 'Master 1 description', + ], $overrides); + } + + /** @test */ + public function validate_master_name_is_required() + { + $this->loginAsUser(); + + // Name empty + $this->post(route('masters.store'), $this->getCreateFields(['name' => ''])); + $this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_master_name_is_not_more_than_60_characters() + { + $this->loginAsUser(); + + // Name 70 characters + $this->post(route('masters.store'), $this->getCreateFields([ + 'name' => str_repeat('Test Title', 7), + ])); + $this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_master_description_is_not_more_than_255_characters() + { + $this->loginAsUser(); + + // Description 256 characters + $this->post(route('masters.store'), $this->getCreateFields([ + 'description' => str_repeat('Long description', 16), + ])); + $this->assertSessionHasErrors('description'); + } + /** @test */ public function user_can_edit_a_master_within_search_query() { @@ -65,6 +107,51 @@ class ManageMasterTest extends TestCase ]); } + private function getEditFields(array $overrides = []) + { + return array_merge([ + 'name' => 'Master 1 name', + 'description' => 'Master 1 description', + ], $overrides); + } + + /** @test */ + public function validate_master_name_update_is_required() + { + $this->loginAsUser(); + $master = factory(Master::class)->create(['name' => 'Testing 123']); + + // Name empty + $this->patch(route('masters.update', $master), $this->getEditFields(['name' => ''])); + $this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_master_name_update_is_not_more_than_60_characters() + { + $this->loginAsUser(); + $master = factory(Master::class)->create(['name' => 'Testing 123']); + + // Name 70 characters + $this->patch(route('masters.update', $master), $this->getEditFields([ + 'name' => str_repeat('Test Title', 7), + ])); + $this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_master_description_update_is_not_more_than_255_characters() + { + $this->loginAsUser(); + $master = factory(Master::class)->create(['name' => 'Testing 123']); + + // Description 256 characters + $this->patch(route('masters.update', $master), $this->getEditFields([ + 'description' => str_repeat('Long description', 16), + ])); + $this->assertSessionHasErrors('description'); + } + /** @test */ public function user_can_delete_a_master() { diff --git a/tests/Generators/Simple/FeatureTestGeneratorTest.php b/tests/Generators/Simple/FeatureTestGeneratorTest.php index 0a1cbbd..ed1f68a 100644 --- a/tests/Generators/Simple/FeatureTestGeneratorTest.php +++ b/tests/Generators/Simple/FeatureTestGeneratorTest.php @@ -98,6 +98,48 @@ class Manage{$this->model_name}Test extends TestCase ]); } + private function getCreateFields(array \$overrides = []) + { + return array_merge([ + 'name' => '{$this->model_name} 1 name', + 'description' => '{$this->model_name} 1 description', + ], \$overrides); + } + + /** @test */ + public function validate_{$this->lang_name}_name_is_required() + { + \$this->loginAsUser(); + + // Name empty + \$this->post(route('{$this->table_name}.store'), \$this->getCreateFields(['name' => ''])); + \$this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_{$this->lang_name}_name_is_not_more_than_60_characters() + { + \$this->loginAsUser(); + + // Name 70 characters + \$this->post(route('{$this->table_name}.store'), \$this->getCreateFields([ + 'name' => str_repeat('Test Title', 7), + ])); + \$this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_{$this->lang_name}_description_is_not_more_than_255_characters() + { + \$this->loginAsUser(); + + // Description 256 characters + \$this->post(route('{$this->table_name}.store'), \$this->getCreateFields([ + 'description' => str_repeat('Long description', 16), + ])); + \$this->assertSessionHasErrors('description'); + } + /** @test */ public function user_can_edit_a_{$this->lang_name}_within_search_query() { @@ -121,6 +163,51 @@ class Manage{$this->model_name}Test extends TestCase ]); } + private function getEditFields(array \$overrides = []) + { + return array_merge([ + 'name' => '{$this->model_name} 1 name', + 'description' => '{$this->model_name} 1 description', + ], \$overrides); + } + + /** @test */ + public function validate_{$this->lang_name}_name_update_is_required() + { + \$this->loginAsUser(); + \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + + // Name empty + \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields(['name' => ''])); + \$this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() + { + \$this->loginAsUser(); + \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + + // Name 70 characters + \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ + 'name' => str_repeat('Test Title', 7), + ])); + \$this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() + { + \$this->loginAsUser(); + \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + + // Description 256 characters + \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ + 'description' => str_repeat('Long description', 16), + ])); + \$this->assertSessionHasErrors('description'); + } + /** @test */ public function user_can_delete_a_{$this->lang_name}() { @@ -248,6 +335,48 @@ class Manage{$this->model_name}Test extends TestCase ]); } + private function getCreateFields(array \$overrides = []) + { + return array_merge([ + 'name' => '{$this->model_name} 1 name', + 'description' => '{$this->model_name} 1 description', + ], \$overrides); + } + + /** @test */ + public function validate_{$this->lang_name}_name_is_required() + { + \$this->loginAsUser(); + + // Name empty + \$this->post(route('{$this->table_name}.store'), \$this->getCreateFields(['name' => ''])); + \$this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_{$this->lang_name}_name_is_not_more_than_60_characters() + { + \$this->loginAsUser(); + + // Name 70 characters + \$this->post(route('{$this->table_name}.store'), \$this->getCreateFields([ + 'name' => str_repeat('Test Title', 7), + ])); + \$this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_{$this->lang_name}_description_is_not_more_than_255_characters() + { + \$this->loginAsUser(); + + // Description 256 characters + \$this->post(route('{$this->table_name}.store'), \$this->getCreateFields([ + 'description' => str_repeat('Long description', 16), + ])); + \$this->assertSessionHasErrors('description'); + } + /** @test */ public function user_can_edit_a_{$this->lang_name}_within_search_query() { @@ -271,6 +400,51 @@ class Manage{$this->model_name}Test extends TestCase ]); } + private function getEditFields(array \$overrides = []) + { + return array_merge([ + 'name' => '{$this->model_name} 1 name', + 'description' => '{$this->model_name} 1 description', + ], \$overrides); + } + + /** @test */ + public function validate_{$this->lang_name}_name_update_is_required() + { + \$this->loginAsUser(); + \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + + // Name empty + \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields(['name' => ''])); + \$this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() + { + \$this->loginAsUser(); + \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + + // Name 70 characters + \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ + 'name' => str_repeat('Test Title', 7), + ])); + \$this->assertSessionHasErrors('name'); + } + + /** @test */ + public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() + { + \$this->loginAsUser(); + \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + + // Description 256 characters + \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ + 'description' => str_repeat('Long description', 16), + ])); + \$this->assertSessionHasErrors('description'); + } + /** @test */ public function user_can_delete_a_{$this->lang_name}() {