Browse Source

Add edit form validation test

tags/1.0.3
Nafies Luthfi 8 years ago
parent
commit
45c238feba
  1. 42
      src/stubs/test-feature-full.stub
  2. 84
      tests/Generators/FeatureTestGeneratorTest.php

42
src/stubs/test-feature-full.stub

@ -66,6 +66,14 @@ class ManageMastersTest extends TestCase
$this->assertSessionHasErrors('description');
}
private function getEditFields(array $overrides = [])
{
return array_merge([
'name' => 'Master 1 name',
'description' => 'Master 1 description',
], $overrides);
}
/** @test */
public function user_can_edit_a_master()
{
@ -76,18 +84,36 @@ class ManageMastersTest extends TestCase
$this->click('edit-master-'.$singleMstr->id);
$this->seePageIs(route('masters.edit', $singleMstr));
$this->submitForm(trans('master.update'), [
'name' => 'Master 1 name',
'description' => 'Master 1 description',
]);
$this->submitForm(trans('master.update'), $this->getEditFields());
$this->seePageIs(route('masters.show', $singleMstr));
$this->seeInDatabase('masters', [
'id' => $singleMstr->id,
'name' => 'Master 1 name',
'description' => 'Master 1 description',
]);
'id' => $singleMstr->id,
] + $this->getEditFields());
}
/** @test */
public function edit_master_action_must_pass_validations()
{
$this->loginAsUser();
$master = factory(Master::class)->create(['name' => 'Testing 123']);
// Name empty
$this->patch(route('masters.update', $master), $this->getEditFields(['name' => '']));
$this->assertSessionHasErrors('name');
// Name 70 characters
$this->patch(route('masters.update', $master), $this->getEditFields([
'name' => str_repeat('Test Title', 7),
]));
$this->assertSessionHasErrors('name');
// Description 256 characters
$this->patch(route('masters.update', $master), $this->getEditFields([
'description' => str_repeat('Long description', 16),
]));
$this->assertSessionHasErrors('description');
}
/** @test */

84
tests/Generators/FeatureTestGeneratorTest.php

@ -117,6 +117,14 @@ class Manage{$this->plural_model_name}Test extends TestCase
\$this->assertSessionHasErrors('description');
}
private function getEditFields(array \$overrides = [])
{
return array_merge([
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
], \$overrides);
}
/** @test */
public function user_can_edit_a_{$this->lang_name}()
{
@ -127,18 +135,36 @@ class Manage{$this->plural_model_name}Test extends TestCase
\$this->click('edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id);
\$this->seePageIs(route('{$this->table_name}.edit', \${$this->single_model_var_name}));
\$this->submitForm(trans('{$this->lang_name}.update'), [
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
]);
\$this->submitForm(trans('{$this->lang_name}.update'), \$this->getEditFields());
\$this->seePageIs(route('{$this->table_name}.show', \${$this->single_model_var_name}));
\$this->seeInDatabase('{$this->table_name}', [
'id' => \${$this->single_model_var_name}->id,
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
]);
'id' => \${$this->single_model_var_name}->id,
] + \$this->getEditFields());
}
/** @test */
public function edit_{$this->lang_name}_action_must_pass_validations()
{
\$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');
// Name 70 characters
\$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([
'name' => str_repeat('Test Title', 7),
]));
\$this->assertSessionHasErrors('name');
// 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 */
@ -282,6 +308,14 @@ class Manage{$this->plural_model_name}Test extends TestCase
\$this->assertSessionHasErrors('description');
}
private function getEditFields(array \$overrides = [])
{
return array_merge([
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
], \$overrides);
}
/** @test */
public function user_can_edit_a_{$this->lang_name}()
{
@ -292,18 +326,36 @@ class Manage{$this->plural_model_name}Test extends TestCase
\$this->click('edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id);
\$this->seePageIs(route('{$this->table_name}.edit', \${$this->single_model_var_name}));
\$this->submitForm(trans('{$this->lang_name}.update'), [
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
]);
\$this->submitForm(trans('{$this->lang_name}.update'), \$this->getEditFields());
\$this->seePageIs(route('{$this->table_name}.show', \${$this->single_model_var_name}));
\$this->seeInDatabase('{$this->table_name}', [
'id' => \${$this->single_model_var_name}->id,
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
]);
'id' => \${$this->single_model_var_name}->id,
] + \$this->getEditFields());
}
/** @test */
public function edit_{$this->lang_name}_action_must_pass_validations()
{
\$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');
// Name 70 characters
\$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([
'name' => str_repeat('Test Title', 7),
]));
\$this->assertSessionHasErrors('name');
// 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 */

Loading…
Cancel
Save