Easier creation of Tasks/Projects/User (#230)

This commit is contained in:
Kevin Papst
2018-07-22 23:18:47 +02:00
committed by GitHub
parent 2cf7d976d3
commit f41eea2768
13 changed files with 297 additions and 10 deletions

View File

@@ -153,7 +153,15 @@ class ActivityController extends AbstractController
$this->flashSuccess('action.updated_successfully');
return $this->redirectToRoute('admin_activity', ['id' => $activity->getId()]);
if ($editForm->has('create_more') && $editForm->get('create_more')->getData() === true) {
$newActivity = new Activity();
$newActivity->setProject($activity->getProject());
$editForm = $this->createEditForm($newActivity);
$editForm->get('create_more')->setData(true);
$activity = $newActivity;
} else {
return $this->redirectToRoute('admin_activity', ['id' => $activity->getId()]);
}
}
return $this->render(

View File

@@ -144,7 +144,15 @@ class ProjectController extends AbstractController
$this->flashSuccess('action.updated_successfully');
return $this->redirectToRoute('admin_project', ['id' => $project->getId()]);
if ($editForm->has('create_more') && $editForm->get('create_more')->getData() === true) {
$newProject = new Project();
$newProject->setCustomer($project->getCustomer());
$editForm = $this->createEditForm($newProject);
$editForm->get('create_more')->setData(true);
$project = $newProject;
} else {
return $this->redirectToRoute('admin_project', ['id' => $project->getId()]);
}
}
return $this->render('admin/project_edit.html.twig', [

View File

@@ -81,7 +81,13 @@ class UserController extends AbstractController
$this->flashSuccess('action.updated_successfully');
return $this->redirectToRoute('user_profile_edit', ['username' => $user->getUsername()]);
if ($editForm->get('create_more')->getData() !== true) {
return $this->redirectToRoute('user_profile_edit', ['username' => $user->getUsername()]);
}
$user = new User();
$editForm = $this->createEditForm($user);
$editForm->get('create_more')->setData(true);
}
return $this->render(

View File

@@ -14,6 +14,7 @@ use App\Form\Type\ProjectType;
use App\Form\Type\YesNoType;
use App\Repository\ProjectRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -59,6 +60,14 @@ class ActivityEditForm extends AbstractType
'label' => 'label.visible',
])
;
if ($entry->getId() === null) {
$builder->add('create_more', CheckboxType::class, [
'label' => 'label.create_more',
'required' => false,
'mapped' => false,
]);
}
}
/**

View File

@@ -15,6 +15,7 @@ use App\Form\Type\CustomerType;
use App\Form\Type\YesNoType;
use App\Repository\CustomerRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -66,6 +67,14 @@ class ProjectEditForm extends AbstractType
'required' => false,
])
;
if ($entry->getId() === null) {
$builder->add('create_more', CheckboxType::class, [
'label' => 'label.create_more',
'required' => false,
'mapped' => false,
]);
}
}
/**

View File

@@ -9,6 +9,7 @@
namespace App\Form;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -37,6 +38,12 @@ class UserCreateType extends UserEditType
]);
parent::buildForm($builder, $options);
$builder->add('create_more', CheckboxType::class, [
'label' => 'label.create_more',
'required' => false,
'mapped' => false,
]);
}
/**

View File

@@ -31,4 +31,94 @@ class ActivityControllerTest extends ControllerBaseTest
$this->assertAccessIsGranted($client, '/admin/activity/');
$this->assertHasDataTable($client);
}
public function testCreateAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/activity/create');
$form = $client->getCrawler()->filter('form[name=activity_edit_form]')->form();
$this->assertTrue($form->has('activity_edit_form[create_more]'));
$this->assertNull($form->get('activity_edit_form[create_more]')->getValue());
$client->submit($form, [
'activity_edit_form' => [
'name' => 'Test 2',
]
]);
$this->assertTrue($client->getResponse()->isRedirect());
$client->followRedirect();
$this->assertHasDataTable($client);
}
public function testCreateActionWithCreateMore()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/activity/create');
$form = $client->getCrawler()->filter('form[name=activity_edit_form]')->form();
$this->assertTrue($form->has('activity_edit_form[create_more]'));
$client->submit($form, [
'activity_edit_form' => [
'name' => 'Test create more',
'create_more' => true,
// TODO select random project
]
]);
$this->assertFalse($client->getResponse()->isRedirect());
$this->assertTrue($client->getResponse()->isSuccessful());
$form = $client->getCrawler()->filter('form[name=activity_edit_form]')->form();
$this->assertTrue($form->has('activity_edit_form[create_more]'));
$this->assertEquals(1, $form->get('activity_edit_form[create_more]')->getValue());
// TODO test that project is pre-selected
}
public function testEditAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/activity/1/edit');
$form = $client->getCrawler()->filter('form[name=activity_edit_form]')->form();
$this->assertFalse($form->has('activity_edit_form[create_more]'));
$this->assertEquals('Test', $form->get('activity_edit_form[name]')->getValue());
$client->submit($form, [
'activity_edit_form' => ['name' => 'Test 2']
]);
$this->assertTrue($client->getResponse()->isRedirect());
$client->followRedirect();
$this->assertHasDataTable($client);
$this->request($client, '/admin/activity/1/edit');
$editForm = $client->getCrawler()->filter('form[name=activity_edit_form]')->form();
$this->assertEquals('Test 2', $editForm->get('activity_edit_form[name]')->getValue());
}
/**
* @dataProvider getValidationTestData
*/
public function testValidationForCreateAction(array $formData, array $validationFields)
{
$this->assertFormHasValidationError(
User::ROLE_ADMIN,
'/admin/activity/create',
'form[name=activity_edit_form]',
$formData,
$validationFields
);
}
public function getValidationTestData()
{
return [
[
[
'activity_edit_form' => [
'name' => '',
'project' => 0,
'visible' => 3,
]
],
[
'#activity_edit_form_name',
'#activity_edit_form_project',
'#activity_edit_form_visible',
]
],
];
}
}

View File

@@ -15,6 +15,7 @@ use App\Tests\Controller\ControllerBaseTest;
/**
* @coversDefaultClass \App\Controller\Admin\ProjectController
* @group integration
* @group legacy
*/
class ProjectControllerTest extends ControllerBaseTest
{
@@ -30,4 +31,94 @@ class ProjectControllerTest extends ControllerBaseTest
$this->assertAccessIsGranted($client, '/admin/project/');
$this->assertHasDataTable($client);
}
public function testCreateAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/create');
$form = $client->getCrawler()->filter('form[name=project_edit_form]')->form();
$this->assertTrue($form->has('project_edit_form[create_more]'));
$this->assertNull($form->get('project_edit_form[create_more]')->getValue());
$client->submit($form, [
'project_edit_form' => [
'name' => 'Test 2',
]
]);
$this->assertTrue($client->getResponse()->isRedirect());
$client->followRedirect();
$this->assertHasDataTable($client);
}
public function testCreateActionWithCreateMore()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/create');
$form = $client->getCrawler()->filter('form[name=project_edit_form]')->form();
$this->assertTrue($form->has('project_edit_form[create_more]'));
$client->submit($form, [
'project_edit_form' => [
'name' => 'Test create more',
'create_more' => true,
// TODO select random customer
]
]);
$this->assertFalse($client->getResponse()->isRedirect());
$this->assertTrue($client->getResponse()->isSuccessful());
$form = $client->getCrawler()->filter('form[name=project_edit_form]')->form();
$this->assertTrue($form->has('project_edit_form[create_more]'));
$this->assertEquals(1, $form->get('project_edit_form[create_more]')->getValue());
// TODO test that customer is pre-selected
}
public function testEditAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/1/edit');
$form = $client->getCrawler()->filter('form[name=project_edit_form]')->form();
$this->assertFalse($form->has('project_edit_form[create_more]'));
$this->assertEquals('Test', $form->get('project_edit_form[name]')->getValue());
$client->submit($form, [
'project_edit_form' => ['name' => 'Test 2']
]);
$this->assertTrue($client->getResponse()->isRedirect());
$client->followRedirect();
$this->assertHasDataTable($client);
$this->request($client, '/admin/project/1/edit');
$editForm = $client->getCrawler()->filter('form[name=project_edit_form]')->form();
$this->assertEquals('Test 2', $editForm->get('project_edit_form[name]')->getValue());
}
/**
* @dataProvider getValidationTestData
*/
public function testValidationForCreateAction(array $formData, array $validationFields)
{
$this->assertFormHasValidationError(
User::ROLE_ADMIN,
'/admin/project/create',
'form[name=project_edit_form]',
$formData,
$validationFields
);
}
public function getValidationTestData()
{
return [
[
[
'project_edit_form' => [
'name' => '',
'customer' => 0,
'visible' => 3,
]
],
[
'#project_edit_form_name',
'#project_edit_form_customer',
'#project_edit_form_visible',
]
],
];
}
}

View File

@@ -32,6 +32,48 @@ class UserControllerTest extends ControllerBaseTest
$this->assertHasDataTable($client);
}
public function testCreateAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
$this->assertAccessIsGranted($client, '/admin/user/create');
$form = $client->getCrawler()->filter('form[name=user_create]')->form();
$this->assertTrue($form->has('user_create[create_more]'));
$this->assertNull($form->get('user_create[create_more]')->getValue());
$client->submit($form, [
'user_create' => [
'username' => 'foobar@example.com',
'plainPassword' => ['first' => 'abcdef', 'second' => 'abcdef'],
'email' => 'foobar@example.com',
'enabled' => 1,
]
]);
$this->assertTrue($client->getResponse()->isRedirect($this->createUrl('/profile/foobar@example.com/edit')));
$client->followRedirect();
// TODO test that this is the users profile
}
public function testCreateActionWithCreateMore()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
$this->assertAccessIsGranted($client, '/admin/user/create');
$form = $client->getCrawler()->filter('form[name=user_create]')->form();
$this->assertTrue($form->has('user_create[create_more]'));
$client->submit($form, [
'user_create' => [
'username' => 'foobar@example.com',
'plainPassword' => ['first' => 'abcdef', 'second' => 'abcdef'],
'email' => 'foobar@example.com',
'enabled' => 1,
'create_more' => true,
]
]);
$this->assertFalse($client->getResponse()->isRedirect());
$this->assertTrue($client->getResponse()->isSuccessful());
$form = $client->getCrawler()->filter('form[name=user_create]')->form();
$this->assertTrue($form->has('user_create[create_more]'));
$this->assertEquals(1, $form->get('user_create[create_more]')->getValue());
}
/**
* @dataProvider getValidationTestData
*/
@@ -71,12 +113,12 @@ class UserControllerTest extends ControllerBaseTest
[
[
'user_create' => [
'username' => '',
'username' => 'Test',
'plainPassword' => ['first' => 'sdfsdf', 'second' => 'sdfxxx'],
'alias' => 'ycvyxcb',
'title' => '34rtwrtewrt',
'avatar' => 'asdfawer',
'email' => 'ydfbvsdfgs', // email is not working
'email' => 'ydfbvsdfgs',
'enabled' => '3',
]
],

View File

@@ -65,6 +65,15 @@ abstract class ControllerBaseTest extends WebTestCase
return $client;
}
/**
* @param string $url
* @return string
*/
protected function createUrl($url)
{
return '/' . self::DEFAULT_LANGUAGE . '/' . ltrim($url, '/');
}
/**
* @param Client $client
* @param string $url
@@ -73,7 +82,7 @@ abstract class ControllerBaseTest extends WebTestCase
*/
protected function request(Client $client, string $url, $method = 'GET')
{
return $client->request($method, '/' . self::DEFAULT_LANGUAGE . $url);
return $client->request($method, $this->createUrl($url));
}
/**
@@ -83,7 +92,7 @@ abstract class ControllerBaseTest extends WebTestCase
*/
protected function assertRequestIsSecured(Client $client, string $url, $method = 'GET')
{
$client->request($method, '/' . self::DEFAULT_LANGUAGE . $url);
$client->request($method, $this->createUrl($url));
/* @var RedirectResponse $response */
$response = $client->getResponse();
@@ -94,7 +103,7 @@ abstract class ControllerBaseTest extends WebTestCase
);
$this->assertEquals(
'http://localhost/' . self::DEFAULT_LANGUAGE . '/login',
'http://localhost' . $this->createUrl('/login'),
$response->getTargetUrl(),
sprintf('The secure URL %s does not redirect to the login form.', $url)
);
@@ -118,7 +127,7 @@ abstract class ControllerBaseTest extends WebTestCase
protected function assertUrlIsSecuredForRole(string $role, string $url, string $method = 'GET')
{
$client = $this->getClientForAuthenticatedUser($role);
$client->request($method, '/' . self::DEFAULT_LANGUAGE . $url);
$client->request($method, $this->createUrl($url));
$this->assertFalse(
$client->getResponse()->isSuccessful(),
sprintf('The secure URL %s is not protected for role %s', $url, $role)
@@ -174,7 +183,7 @@ abstract class ControllerBaseTest extends WebTestCase
protected function assertFormHasValidationError($role, $url, $formSelector, array $formData, array $fieldNames, $disableValidation = true)
{
$client = $this->getClientForAuthenticatedUser($role);
$crawler = $client->request('GET', '/' . self::DEFAULT_LANGUAGE . $url);
$crawler = $client->request('GET', $this->createUrl($url));
$form = $crawler->filter($formSelector)->form();
if ($disableValidation) {
$form->disableValidation();

View File

@@ -203,6 +203,10 @@
<source>label.email</source>
<target>Email</target>
</trans-unit>
<trans-unit id="label.create_more">
<source>label.create_more</source>
<target>Weitere Einträge erstellen</target>
</trans-unit>
<!--
Buttons & Actions

View File

@@ -211,6 +211,10 @@
<source>label.email</source>
<target>Email</target>
</trans-unit>
<trans-unit id="label.create_more">
<source>label.create_more</source>
<target>Create further entries</target>
</trans-unit>
<!--
Buttons & Actions

Binary file not shown.