mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-09 00:04:59 +00:00
Add CommentEmbeddable to Activity : remoke remark field (Ref #21)
This commit is contained in:
@@ -27,7 +27,7 @@ use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
@@ -38,19 +38,19 @@ class ActivityTypeTest extends KernelTestCase
|
||||
* @var \Symfony\Component\Form\FormBuilderInterface
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\MainBundle\Entity\Center
|
||||
@@ -60,26 +60,26 @@ class ActivityTypeTest extends KernelTestCase
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
|
||||
$this->container = self::$kernel->getContainer();
|
||||
|
||||
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
|
||||
|
||||
|
||||
|
||||
$this->formBuilder = $this->container
|
||||
->get('form.factory')
|
||||
->createBuilder(FormType::class, null, array(
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token'
|
||||
));
|
||||
|
||||
|
||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||
$request->setLocale('fr');
|
||||
|
||||
|
||||
self::$kernel->getContainer()
|
||||
->get('request_stack')
|
||||
->push($request);
|
||||
|
||||
|
||||
$this->user = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(array('username' => 'center a_social'));
|
||||
@@ -91,9 +91,9 @@ class ActivityTypeTest extends KernelTestCase
|
||||
$token->getUser()->willReturn($this->user);
|
||||
$this->container->get('security.token_storage')
|
||||
->setToken($token->reveal());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testForm()
|
||||
{
|
||||
$form = $this->formBuilder
|
||||
@@ -102,15 +102,15 @@ class ActivityTypeTest extends KernelTestCase
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE')
|
||||
))
|
||||
->getForm();
|
||||
|
||||
|
||||
$form->submit(array());
|
||||
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertTrue($form->isValid());
|
||||
$this->assertInstanceOf(Activity::class, $form->getData()['activity']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testFormSubmitting()
|
||||
{
|
||||
$form = $this->formBuilder
|
||||
@@ -119,35 +119,35 @@ class ActivityTypeTest extends KernelTestCase
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE')
|
||||
))
|
||||
->getForm();
|
||||
|
||||
|
||||
$form->submit(array( 'activity' => array(
|
||||
'date' => '9-3-2015',
|
||||
'durationTime' => 300,
|
||||
'remark' => 'blabla',
|
||||
// 'remark' => 'blabla',
|
||||
'attendee' => true
|
||||
)));
|
||||
|
||||
|
||||
// var_dump($form->getErrors()->count()); var_dump($form->isValid());
|
||||
// foreach($form->getErrors() as $e) { fwrite(STDOUT, var_dump($e->getMessage())); }
|
||||
// var_dump($form->getErrors());
|
||||
|
||||
|
||||
$this->assertTrue($form->isSynchronized(), "Test the form is synchronized");
|
||||
$this->assertTrue($form->isValid(), "test the form is valid");
|
||||
$this->assertInstanceOf(Activity::class, $form->getData()['activity']);
|
||||
|
||||
|
||||
// test the activity
|
||||
/* @var $activity Activity */
|
||||
$activity = $form->getData()['activity'];
|
||||
|
||||
|
||||
$this->assertEquals('09-03-2015', $activity->getDate()->format('d-m-Y'),
|
||||
"Test the date is correct");
|
||||
$this->assertEquals('00:05', $activity->getDurationTime()->format('H:i'),
|
||||
"Test the formatted hour is correct");
|
||||
$this->assertEquals(true, $activity->getAttendee());
|
||||
$this->assertEquals('blabla', $activity->getRemark());
|
||||
|
||||
// $this->assertEquals('blabla', $activity->getRemark());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test that the form correctly build even with a durationTime which is not in
|
||||
* the listed in the possible durationTime
|
||||
@@ -156,50 +156,50 @@ class ActivityTypeTest extends KernelTestCase
|
||||
{
|
||||
$activity = new Activity();
|
||||
$activity->setDurationTime(\DateTime::createFromFormat('U', 60));
|
||||
|
||||
|
||||
$builder = $this->container
|
||||
->get('form.factory')
|
||||
->createBuilder(FormType::class, array('activity' => $activity), array(
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token'
|
||||
));
|
||||
|
||||
|
||||
$form = $builder
|
||||
->add('activity', ActivityType::class, array(
|
||||
'center' => $this->center,
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE')
|
||||
))
|
||||
->getForm();
|
||||
|
||||
|
||||
|
||||
|
||||
$form->submit(array( 'activity' => array(
|
||||
'date' => '9-3-2015',
|
||||
'durationTime' => 60,
|
||||
'remark' => 'blabla',
|
||||
// 'remark' => 'blabla',
|
||||
'attendee' => true
|
||||
)));
|
||||
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertTrue($form->isValid());
|
||||
|
||||
|
||||
// test the activity
|
||||
/* @var $activity Activity */
|
||||
$activity = $form->getData()['activity'];
|
||||
|
||||
|
||||
$this->assertEquals('00:01', $activity->getDurationTime()->format('H:i'),
|
||||
"Test the formatted hour is correct");
|
||||
|
||||
|
||||
// test the view : we want to be sure that the entry with 60 seconds exists
|
||||
$view = $form->createView();
|
||||
|
||||
|
||||
$this->assertTrue(isset($view['activity']['durationTime']));
|
||||
|
||||
|
||||
// map all the values in an array
|
||||
$values = array_map(function($choice) { return $choice->value; },
|
||||
$values = array_map(function($choice) { return $choice->value; },
|
||||
$view['activity']['durationTime']->vars['choices']);
|
||||
|
||||
|
||||
$this->assertContains(60, $values);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user