Browse Source

Merge pull request #3 from nafiesl/validation-tests

Add more validation tests on feature test stubs
tags/1.2.9 1.2.6
Nafies Luthfi 7 years ago
committed by GitHub
parent
commit
e26b3ef71b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 121
      src/stubs/testcases/feature/api.stub
  2. 30
      src/stubs/testcases/feature/full.stub
  3. 87
      src/stubs/testcases/feature/simple.stub
  4. 242
      tests/Generators/Api/ApiFeatureTestGeneratorTest.php
  5. 90
      tests/Generators/FeatureTestGeneratorTest.php
  6. 174
      tests/Generators/Simple/FeatureTestGeneratorTest.php

121
src/stubs/testcases/feature/api.stub

@ -48,6 +48,65 @@ class ManageMasterTest extends TestCase
]);
}
private function getCreateFields(array $overrides = [])
{
return array_merge([
'name' => 'Vehicle 1 name',
'description' => 'Vehicle 1 description',
], $overrides);
}
/** @test */
public function validate_master_name_is_required()
{
$user = $this->createUser();
// Name empty
$requestBody = $this->getCreateFields(['name' => '']);
$this->postJson(
route('api.masters.store'),
$requestBody,
['Authorization' => 'Bearer '.$user->api_token]
);
$this->seeStatusCode(422);
$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_master_name_is_not_more_than_60_characters()
{
$user = $this->createUser();
// Name 70 characters
$requestBody = $this->getCreateFields(['name' => str_repeat('Test Title', 7)]);
$this->postJson(
route('api.masters.store'),
$requestBody,
['Authorization' => 'Bearer '.$user->api_token]
);
$this->seeStatusCode(422);
$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_master_description_is_not_more_than_255_characters()
{
$user = $this->createUser();
// Description 256 characters
$requestBody = $this->getCreateFields(['description' => str_repeat('Long description', 16)]);
$this->postJson(
route('api.masters.store'),
$requestBody,
['Authorization' => 'Bearer '.$user->api_token]
);
$this->seeStatusCode(422);
$this->seeJsonSubset(['errors' => ['description' => []]]);
}
/** @test */
public function user_can_get_a_master_detail()
{
@ -87,6 +146,68 @@ class ManageMasterTest extends TestCase
]);
}
private function getEditFields(array $overrides = [])
{
return array_merge([
'name' => 'Vehicle 1 name',
'description' => 'Vehicle 1 description',
], $overrides);
}
/** @test */
public function validate_master_name_update_is_required()
{
$user = $this->createUser();
$singleMstr = factory(Vehicle::class)->create();
// Name empty
$requestBody = $this->getEditFields(['name' => '']);
$this->patchJson(
route('api.masters.update', $singleMstr),
$requestBody,
['Authorization' => 'Bearer '.$user->api_token]
);
$this->seeStatusCode(422);
$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_master_name_update_is_not_more_than_60_characters()
{
$user = $this->createUser();
$singleMstr = factory(Vehicle::class)->create();
// Name 70 characters
$requestBody = $this->getEditFields(['name' => str_repeat('Test Title', 7)]);
$this->patchJson(
route('api.masters.update', $singleMstr),
$requestBody,
['Authorization' => 'Bearer '.$user->api_token]
);
$this->seeStatusCode(422);
$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_master_description_update_is_not_more_than_255_characters()
{
$user = $this->createUser();
$singleMstr = factory(Vehicle::class)->create(['name' => 'Testing 123']);
// Description 256 characters
$requestBody = $this->getEditFields(['description' => str_repeat('Long description', 16)]);
$this->patchJson(
route('api.masters.update', $singleMstr),
$requestBody,
['Authorization' => 'Bearer '.$user->api_token]
);
$this->seeStatusCode(422);
$this->seeJsonSubset(['errors' => ['description' => []]]);
}
/** @test */
public function user_can_delete_a_master()
{

30
src/stubs/testcases/feature/full.stub

@ -45,19 +45,31 @@ class ManageMasterTest extends TestCase
}
/** @test */
public function create_master_action_must_pass_validations()
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([
@ -94,7 +106,7 @@ class ManageMasterTest extends TestCase
}
/** @test */
public function edit_master_action_must_pass_validations()
public function validate_master_name_update_is_required()
{
$this->loginAsUser();
$master = factory(Master::class)->create(['name' => 'Testing 123']);
@ -102,12 +114,26 @@ class ManageMasterTest extends TestCase
// 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([

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

242
tests/Generators/Api/ApiFeatureTestGeneratorTest.php

@ -62,6 +62,65 @@ class Manage{$this->model_name}Test extends TestCase
]);
}
private function getCreateFields(array \$overrides = [])
{
return array_merge([
'name' => 'Vehicle 1 name',
'description' => 'Vehicle 1 description',
], \$overrides);
}
/** @test */
public function validate_{$this->lang_name}_name_is_required()
{
\$user = \$this->createUser();
// Name empty
\$requestBody = \$this->getCreateFields(['name' => '']);
\$this->postJson(
route('api.{$this->table_name}.store'),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_{$this->lang_name}_name_is_not_more_than_60_characters()
{
\$user = \$this->createUser();
// Name 70 characters
\$requestBody = \$this->getCreateFields(['name' => str_repeat('Test Title', 7)]);
\$this->postJson(
route('api.{$this->table_name}.store'),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_{$this->lang_name}_description_is_not_more_than_255_characters()
{
\$user = \$this->createUser();
// Description 256 characters
\$requestBody = \$this->getCreateFields(['description' => str_repeat('Long description', 16)]);
\$this->postJson(
route('api.{$this->table_name}.store'),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['description' => []]]);
}
/** @test */
public function user_can_get_a_{$this->lang_name}_detail()
{
@ -101,6 +160,68 @@ class Manage{$this->model_name}Test extends TestCase
]);
}
private function getEditFields(array \$overrides = [])
{
return array_merge([
'name' => 'Vehicle 1 name',
'description' => 'Vehicle 1 description',
], \$overrides);
}
/** @test */
public function validate_{$this->lang_name}_name_update_is_required()
{
\$user = \$this->createUser();
\${$this->single_model_var_name} = factory(Vehicle::class)->create();
// Name empty
\$requestBody = \$this->getEditFields(['name' => '']);
\$this->patchJson(
route('api.{$this->table_name}.update', \${$this->single_model_var_name}),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters()
{
\$user = \$this->createUser();
\${$this->single_model_var_name} = factory(Vehicle::class)->create();
// Name 70 characters
\$requestBody = \$this->getEditFields(['name' => str_repeat('Test Title', 7)]);
\$this->patchJson(
route('api.{$this->table_name}.update', \${$this->single_model_var_name}),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters()
{
\$user = \$this->createUser();
\${$this->single_model_var_name} = factory(Vehicle::class)->create(['name' => 'Testing 123']);
// Description 256 characters
\$requestBody = \$this->getEditFields(['description' => str_repeat('Long description', 16)]);
\$this->patchJson(
route('api.{$this->table_name}.update', \${$this->single_model_var_name}),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['description' => []]]);
}
/** @test */
public function user_can_delete_a_{$this->lang_name}()
{
@ -186,6 +307,65 @@ class Manage{$this->model_name}Test extends TestCase
]);
}
private function getCreateFields(array \$overrides = [])
{
return array_merge([
'name' => 'Vehicle 1 name',
'description' => 'Vehicle 1 description',
], \$overrides);
}
/** @test */
public function validate_{$this->lang_name}_name_is_required()
{
\$user = \$this->createUser();
// Name empty
\$requestBody = \$this->getCreateFields(['name' => '']);
\$this->postJson(
route('api.{$this->table_name}.store'),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_{$this->lang_name}_name_is_not_more_than_60_characters()
{
\$user = \$this->createUser();
// Name 70 characters
\$requestBody = \$this->getCreateFields(['name' => str_repeat('Test Title', 7)]);
\$this->postJson(
route('api.{$this->table_name}.store'),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_{$this->lang_name}_description_is_not_more_than_255_characters()
{
\$user = \$this->createUser();
// Description 256 characters
\$requestBody = \$this->getCreateFields(['description' => str_repeat('Long description', 16)]);
\$this->postJson(
route('api.{$this->table_name}.store'),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['description' => []]]);
}
/** @test */
public function user_can_get_a_{$this->lang_name}_detail()
{
@ -225,6 +405,68 @@ class Manage{$this->model_name}Test extends TestCase
]);
}
private function getEditFields(array \$overrides = [])
{
return array_merge([
'name' => 'Vehicle 1 name',
'description' => 'Vehicle 1 description',
], \$overrides);
}
/** @test */
public function validate_{$this->lang_name}_name_update_is_required()
{
\$user = \$this->createUser();
\${$this->single_model_var_name} = factory(Vehicle::class)->create();
// Name empty
\$requestBody = \$this->getEditFields(['name' => '']);
\$this->patchJson(
route('api.{$this->table_name}.update', \${$this->single_model_var_name}),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters()
{
\$user = \$this->createUser();
\${$this->single_model_var_name} = factory(Vehicle::class)->create();
// Name 70 characters
\$requestBody = \$this->getEditFields(['name' => str_repeat('Test Title', 7)]);
\$this->patchJson(
route('api.{$this->table_name}.update', \${$this->single_model_var_name}),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['name' => []]]);
}
/** @test */
public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters()
{
\$user = \$this->createUser();
\${$this->single_model_var_name} = factory(Vehicle::class)->create(['name' => 'Testing 123']);
// Description 256 characters
\$requestBody = \$this->getEditFields(['description' => str_repeat('Long description', 16)]);
\$this->patchJson(
route('api.{$this->table_name}.update', \${$this->single_model_var_name}),
\$requestBody,
['Authorization' => 'Bearer '.\$user->api_token]
);
\$this->seeStatusCode(422);
\$this->seeJsonSubset(['errors' => ['description' => []]]);
}
/** @test */
public function user_can_delete_a_{$this->lang_name}()
{

90
tests/Generators/FeatureTestGeneratorTest.php

@ -101,19 +101,31 @@ class Manage{$this->model_name}Test extends TestCase
}
/** @test */
public function create_{$this->lang_name}_action_must_pass_validations()
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([
@ -150,7 +162,7 @@ class Manage{$this->model_name}Test extends TestCase
}
/** @test */
public function edit_{$this->lang_name}_action_must_pass_validations()
public function validate_{$this->lang_name}_name_update_is_required()
{
\$this->loginAsUser();
\${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']);
@ -158,12 +170,26 @@ class Manage{$this->model_name}Test extends TestCase
// 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([
@ -298,19 +324,31 @@ class Manage{$this->model_name}Test extends TestCase
}
/** @test */
public function create_{$this->lang_name}_action_must_pass_validations()
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([
@ -347,7 +385,7 @@ class Manage{$this->model_name}Test extends TestCase
}
/** @test */
public function edit_{$this->lang_name}_action_must_pass_validations()
public function validate_{$this->lang_name}_name_update_is_required()
{
\$this->loginAsUser();
\${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']);
@ -355,12 +393,26 @@ class Manage{$this->model_name}Test extends TestCase
// 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([
@ -447,19 +499,31 @@ class Manage{$this->model_name}Test extends TestCase
}
/** @test */
public function create_{$this->lang_name}_action_must_pass_validations()
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([
@ -496,7 +560,7 @@ class Manage{$this->model_name}Test extends TestCase
}
/** @test */
public function edit_{$this->lang_name}_action_must_pass_validations()
public function validate_{$this->lang_name}_name_update_is_required()
{
\$this->loginAsUser();
\${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']);
@ -504,12 +568,26 @@ class Manage{$this->model_name}Test extends TestCase
// 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([

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