Browse Source

Add validation tests on simple feature test

tags/1.2.9
Nafies Luthfi 7 years ago
parent
commit
5cc2fc6cdb
  1. 87
      src/stubs/testcases/feature/simple.stub
  2. 174
      tests/Generators/Simple/FeatureTestGeneratorTest.php

87
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()
{

174
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}()
{

Loading…
Cancel
Save