mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-31 20:13:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,16 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Controller;
|
||||
|
||||
use RuntimeException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityControllerTest extends WebTestCase
|
||||
{
|
||||
public function getSecuredPagesAuthenticated()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$person = $this->getPersonFromFixtures();
|
||||
$activities = $this->getActivitiesForPerson($person);
|
||||
|
||||
$user = $this->createFakeUser();
|
||||
|
||||
return [
|
||||
[
|
||||
$this->getAuthenticatedClient('center b_social'),
|
||||
sprintf('fr/person/%d/activity/', $person->getId()),
|
||||
],
|
||||
[
|
||||
$this->getAuthenticatedClient('center b_social'),
|
||||
sprintf('fr/person/%d/activity/new', $person->getId()),
|
||||
],
|
||||
[
|
||||
$this->getAuthenticatedClient('center b_social'),
|
||||
sprintf('fr/person/%d/activity/%d/show', $person->getId(), $activities[0]->getId()),
|
||||
],
|
||||
[
|
||||
$this->getAuthenticatedClient('center b_social'),
|
||||
sprintf('fr/person/%d/activity/%d/edit', $person->getId(), $activities[0]->getId()),
|
||||
],
|
||||
[
|
||||
$this->getAuthenticatedClient($user->getUsername()),
|
||||
sprintf('fr/person/%d/activity/new', $person->getId()),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a client unauthenticated and.
|
||||
*/
|
||||
public function getSecuredPagesUnauthenticated()
|
||||
{
|
||||
static::bootKernel();
|
||||
$person = $this->getPersonFromFixtures();
|
||||
$activities = $this->getActivitiesForPerson($person);
|
||||
|
||||
return [
|
||||
[sprintf('fr/person/%d/activity/', $person->getId())],
|
||||
[sprintf('fr/person/%d/activity/new', $person->getId())],
|
||||
[sprintf('fr/person/%d/activity/%d/show', $person->getId(), $activities[0]->getId())],
|
||||
[sprintf('fr/person/%d/activity/%d/edit', $person->getId(), $activities[0]->getId())],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getSecuredPagesUnauthenticated
|
||||
*
|
||||
* @param mixed $url
|
||||
*/
|
||||
public function testAccessIsDeniedForUnauthenticated($url)
|
||||
{
|
||||
@@ -19,13 +81,15 @@ class ActivityControllerTest extends WebTestCase
|
||||
$client->request('GET', $url);
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
$this->assertTrue($client->getResponse()->isRedirect('http://localhost/login'),
|
||||
sprintf('the page "%s" does not redirect to http://localhost/login', $url));
|
||||
$this->assertTrue(
|
||||
$client->getResponse()->isRedirect('http://localhost/login'),
|
||||
sprintf('the page "%s" does not redirect to http://localhost/login', $url)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider getSecuredPagesAuthenticated
|
||||
*
|
||||
* @param type $client
|
||||
* @param type $url
|
||||
*/
|
||||
@@ -36,63 +100,6 @@ class ActivityControllerTest extends WebTestCase
|
||||
$this->assertEquals(403, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function getSecuredPagesAuthenticated()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$person = $this->getPersonFromFixtures();
|
||||
$activities = $this->getActivitiesForPerson($person);
|
||||
|
||||
|
||||
$user = $this->createFakeUser();
|
||||
|
||||
|
||||
|
||||
return array(
|
||||
array(
|
||||
$this->getAuthenticatedClient('center b_social'),
|
||||
sprintf('fr/person/%d/activity/', $person->getId())
|
||||
),
|
||||
array(
|
||||
$this->getAuthenticatedClient('center b_social'),
|
||||
sprintf('fr/person/%d/activity/new', $person->getId())
|
||||
),
|
||||
array(
|
||||
$this->getAuthenticatedClient('center b_social'),
|
||||
sprintf('fr/person/%d/activity/%d/show', $person->getId(), $activities[0]->getId())
|
||||
),
|
||||
array(
|
||||
$this->getAuthenticatedClient('center b_social'),
|
||||
sprintf('fr/person/%d/activity/%d/edit', $person->getId(), $activities[0]->getId())
|
||||
),
|
||||
array(
|
||||
$this->getAuthenticatedClient($user->getUsername()),
|
||||
sprintf('fr/person/%d/activity/new', $person->getId())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provide a client unauthenticated and
|
||||
*
|
||||
*/
|
||||
public function getSecuredPagesUnauthenticated()
|
||||
{
|
||||
static::bootKernel();
|
||||
$person = $this->getPersonFromFixtures();
|
||||
$activities = $this->getActivitiesForPerson($person);
|
||||
|
||||
return array(
|
||||
[ sprintf('fr/person/%d/activity/', $person->getId()) ],
|
||||
[ sprintf('fr/person/%d/activity/new', $person->getId()) ],
|
||||
[ sprintf('fr/person/%d/activity/%d/show', $person->getId(), $activities[0]->getId()) ],
|
||||
[ sprintf('fr/person/%d/activity/%d/edit', $person->getId(), $activities[0]->getId()) ],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
// Create a new client to browse the application
|
||||
@@ -100,27 +107,32 @@ class ActivityControllerTest extends WebTestCase
|
||||
$person = $this->getPersonFromFixtures();
|
||||
|
||||
// Create a new entry in the database
|
||||
$crawler = $client->request('GET', sprintf('en/person/%d/activity/',
|
||||
$person->getId()));
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(),
|
||||
"Unexpected HTTP status code for GET /activity/");
|
||||
$crawler = $client->request('GET', sprintf(
|
||||
'en/person/%d/activity/',
|
||||
$person->getId()
|
||||
));
|
||||
$this->assertEquals(
|
||||
200,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
'Unexpected HTTP status code for GET /activity/'
|
||||
);
|
||||
$crawler = $client->click($crawler->selectLink('Ajouter une nouvelle activité')
|
||||
->link());
|
||||
->link());
|
||||
|
||||
$reason1 = $this->getRandomActivityReason();
|
||||
$reason2 = $this->getRandomActivityReason(array($reason1->getId()));
|
||||
$reason2 = $this->getRandomActivityReason([$reason1->getId()]);
|
||||
|
||||
// Fill in the form and submit it
|
||||
$form = $crawler->selectButton('Ajouter une nouvelle activité')->form(array(
|
||||
'chill_activitybundle_activity'=> array(
|
||||
'date' => '15-01-2015',
|
||||
'durationTime' => 600,
|
||||
// 'remark' => 'blabla',
|
||||
'scope' => $this->getRandomScope('center a_social', 'Center A')->getId(),
|
||||
'type' => $this->getRandomActivityType()->getId()
|
||||
)
|
||||
));
|
||||
$form['chill_activitybundle_activity[reasons]']->select(array ($reason1->getId(), $reason2->getId()));
|
||||
$form = $crawler->selectButton('Ajouter une nouvelle activité')->form([
|
||||
'chill_activitybundle_activity' => [
|
||||
'date' => '15-01-2015',
|
||||
'durationTime' => 600,
|
||||
// 'remark' => 'blabla',
|
||||
'scope' => $this->getRandomScope('center a_social', 'Center A')->getId(),
|
||||
'type' => $this->getRandomActivityType()->getId(),
|
||||
],
|
||||
]);
|
||||
$form['chill_activitybundle_activity[reasons]']->select([$reason1->getId(), $reason2->getId()]);
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
@@ -128,18 +140,21 @@ class ActivityControllerTest extends WebTestCase
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check data in the show view
|
||||
$this->assertGreaterThan(0, $crawler->filter('dd:contains("January 15, 2015")')->count(),
|
||||
'Missing element dd:contains("January 15, 2015")');
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('dd:contains("January 15, 2015")')->count(),
|
||||
'Missing element dd:contains("January 15, 2015")'
|
||||
);
|
||||
|
||||
// Edit the entity
|
||||
$crawler = $client->click($crawler->selectLink("Modifier l'activité")->link());
|
||||
|
||||
$form = $crawler->selectButton("Sauver l'activité")->form(array(
|
||||
'chill_activitybundle_activity' => array(
|
||||
'date' => '25-01-2015',
|
||||
// 'remark' => 'Foo'
|
||||
)
|
||||
));
|
||||
$form = $crawler->selectButton("Sauver l'activité")->form([
|
||||
'chill_activitybundle_activity' => [
|
||||
'date' => '25-01-2015',
|
||||
// 'remark' => 'Foo'
|
||||
],
|
||||
]);
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
@@ -148,164 +163,33 @@ class ActivityControllerTest extends WebTestCase
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// check that new data are present
|
||||
$this->assertGreaterThan(0,
|
||||
$crawler->filter('dd:contains("January 25, 2015")')->count(),
|
||||
'Missing element dd:contains("January 25, 2015")');
|
||||
$this->assertGreaterThan(0,
|
||||
$crawler->filter('dd:contains("Foo")')->count(),
|
||||
'Missing element dd:contains("Foo")');
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('dd:contains("January 25, 2015")')->count(),
|
||||
'Missing element dd:contains("January 25, 2015")'
|
||||
);
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('dd:contains("Foo")')->count(),
|
||||
'Missing element dd:contains("Foo")'
|
||||
);
|
||||
|
||||
// delete the actvity
|
||||
$crawler = $client->click($crawler->selectLink("Supprimer")->link());
|
||||
$crawler = $client->click($crawler->selectLink('Supprimer')->link());
|
||||
|
||||
$button = $crawler->selectButton('Supprimer');
|
||||
$button = $crawler->selectButton('Supprimer');
|
||||
|
||||
$form = $button->form();
|
||||
$form = $button->form();
|
||||
|
||||
$client->submit($form);
|
||||
$this->assertTrue($client->getResponse()->isRedirect(sprintf('/en/person/%d/activity/',
|
||||
$person->getId())));
|
||||
$client->submit($form);
|
||||
$this->assertTrue($client->getResponse()->isRedirect(sprintf(
|
||||
'/en/person/%d/activity/',
|
||||
$person->getId()
|
||||
)));
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
$this->assertNotContains('January 25, 2015', $crawler->text());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
private function getAuthenticatedClient($username = 'center a_social')
|
||||
{
|
||||
return static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => $username,
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Chill\PersonBundle\Entity\Person
|
||||
*/
|
||||
private function getPersonFromFixtures()
|
||||
{
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')
|
||||
->findOneBy(array(
|
||||
'firstName' => 'Depardieu',
|
||||
'lastName' => 'Gérard'
|
||||
));
|
||||
|
||||
if ($person === NULL) {
|
||||
throw new \RuntimeException("We need a person with firstname Gérard and"
|
||||
. " lastname Depardieu. Did you add fixtures ?");
|
||||
}
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
private function getActivitiesForPerson(\Chill\PersonBundle\Entity\Person $person)
|
||||
{
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$activities = $em->getRepository('ChillActivityBundle:Activity')
|
||||
->findBy(array('person' => $person));
|
||||
|
||||
if (count($activities) === 0) {
|
||||
throw new \RuntimeException("We need activities associated with this "
|
||||
. "person. Did you forget to add fixtures ?");
|
||||
}
|
||||
|
||||
return $activities;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $centerName
|
||||
* @return \Chill\MainBundle\Entity\Scope
|
||||
*/
|
||||
private function getRandomScope($username, $centerName)
|
||||
{
|
||||
$user = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneByUsername($username);
|
||||
|
||||
if ($user === NULL) {
|
||||
throw new \RuntimeException("The user with username $username "
|
||||
. "does not exists in database. Did you add fixtures ?");
|
||||
}
|
||||
|
||||
$center = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:Center')
|
||||
->findOneByName($centerName);
|
||||
|
||||
// get scope reachable by both role UPDATE and DELETE
|
||||
$reachableScopesUpdate = static::$kernel->getContainer()
|
||||
->get('chill.main.security.authorization.helper')
|
||||
->getReachableScopes($user, new Role('CHILL_ACTIVITY_UPDATE'),
|
||||
$center);
|
||||
$reachableScopesDelete = static::$kernel->getContainer()
|
||||
->get('chill.main.security.authorization.helper')
|
||||
->getReachableScopes($user, new Role('CHILL_ACTIVITY_DELETE'),
|
||||
$center);
|
||||
$reachableScopesId = array_intersect(
|
||||
array_map(function ($s) { return $s->getId(); }, $reachableScopesDelete),
|
||||
array_map(function ($s) { return $s->getId(); }, $reachableScopesUpdate)
|
||||
);
|
||||
if (count($reachableScopesId) === 0) {
|
||||
throw new \RuntimeException("there are not scope reachable for "
|
||||
. "both CHILL_ACTIVITY_UPDATE and CHILL_ACTIVITY_DELETE");
|
||||
}
|
||||
|
||||
foreach($reachableScopesUpdate as $scope) {
|
||||
if (in_array($scope->getId(), $reachableScopesId)) {
|
||||
$reachableScopes[] = $scope;
|
||||
}
|
||||
}
|
||||
|
||||
return $reachableScopes[array_rand($reachableScopes)];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int[] $excludeIds An array of id to exclude
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityReason
|
||||
*/
|
||||
private function getRandomActivityReason(array $excludeIds = array())
|
||||
{
|
||||
$reasons = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillActivityBundle:ActivityReason')
|
||||
->findAll();
|
||||
|
||||
$reason = $reasons[array_rand($reasons)];
|
||||
|
||||
if (in_array($reason->getId(), $excludeIds)) {
|
||||
return $this->getRandomActivityReason($excludeIds);
|
||||
}
|
||||
|
||||
return $reason;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityType
|
||||
*/
|
||||
private function getRandomActivityType()
|
||||
{
|
||||
$types = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillActivityBundle:ActivityType')
|
||||
->findAll();
|
||||
|
||||
return $types[array_rand($types)];
|
||||
$this->assertNotContains('January 25, 2015', $crawler->text());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,10 +205,10 @@ class ActivityControllerTest extends WebTestCase
|
||||
|
||||
//get the social PermissionGroup, and remove CHILL_ACTIVITY_*
|
||||
$socialPermissionGroup = $em
|
||||
->getRepository('ChillMainBundle:PermissionsGroup')
|
||||
->findOneByName('social');
|
||||
->getRepository('ChillMainBundle:PermissionsGroup')
|
||||
->findOneByName('social');
|
||||
$withoutActivityPermissionGroup = (new \Chill\MainBundle\Entity\PermissionsGroup())
|
||||
->setName('social without activity');
|
||||
->setName('social without activity');
|
||||
//copy role scopes where ACTIVITY is not present
|
||||
foreach ($socialPermissionGroup->getRoleScopes() as $roleScope) {
|
||||
if (!strpos($roleScope->getRole(), 'ACTIVITY')) {
|
||||
@@ -334,8 +218,8 @@ class ActivityControllerTest extends WebTestCase
|
||||
//create groupCenter
|
||||
$groupCenter = new \Chill\MainBundle\Entity\GroupCenter();
|
||||
$groupCenter->setCenter($em->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A')))
|
||||
->setPermissionsGroup($withoutActivityPermissionGroup);
|
||||
->findOneBy(['name' => 'Center A']))
|
||||
->setPermissionsGroup($withoutActivityPermissionGroup);
|
||||
$em->persist($withoutActivityPermissionGroup);
|
||||
$em->persist($groupCenter);
|
||||
|
||||
@@ -344,10 +228,10 @@ class ActivityControllerTest extends WebTestCase
|
||||
$username = $faker->name;
|
||||
$user = new \Chill\MainBundle\Entity\User();
|
||||
$user
|
||||
->setPassword($container->get('security.password_encoder')
|
||||
->encodePassword($user, 'password'))
|
||||
->setUsername($username)
|
||||
->addGroupCenter($groupCenter);
|
||||
->setPassword($container->get('security.password_encoder')
|
||||
->encodePassword($user, 'password'))
|
||||
->setUsername($username)
|
||||
->addGroupCenter($groupCenter);
|
||||
|
||||
$em->persist($user);
|
||||
|
||||
@@ -355,4 +239,146 @@ class ActivityControllerTest extends WebTestCase
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function getActivitiesForPerson(\Chill\PersonBundle\Entity\Person $person)
|
||||
{
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$activities = $em->getRepository('ChillActivityBundle:Activity')
|
||||
->findBy(['person' => $person]);
|
||||
|
||||
if (count($activities) === 0) {
|
||||
throw new RuntimeException('We need activities associated with this '
|
||||
. 'person. Did you forget to add fixtures ?');
|
||||
}
|
||||
|
||||
return $activities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $username
|
||||
*
|
||||
* @return \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
private function getAuthenticatedClient($username = 'center a_social')
|
||||
{
|
||||
return static::createClient([], [
|
||||
'PHP_AUTH_USER' => $username,
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Chill\PersonBundle\Entity\Person
|
||||
*/
|
||||
private function getPersonFromFixtures()
|
||||
{
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')
|
||||
->findOneBy([
|
||||
'firstName' => 'Depardieu',
|
||||
'lastName' => 'Gérard',
|
||||
]);
|
||||
|
||||
if (null === $person) {
|
||||
throw new RuntimeException('We need a person with firstname Gérard and'
|
||||
. ' lastname Depardieu. Did you add fixtures ?');
|
||||
}
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $excludeIds An array of id to exclude
|
||||
*
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityReason
|
||||
*/
|
||||
private function getRandomActivityReason(array $excludeIds = [])
|
||||
{
|
||||
$reasons = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillActivityBundle:ActivityReason')
|
||||
->findAll();
|
||||
|
||||
$reason = $reasons[array_rand($reasons)];
|
||||
|
||||
if (in_array($reason->getId(), $excludeIds)) {
|
||||
return $this->getRandomActivityReason($excludeIds);
|
||||
}
|
||||
|
||||
return $reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityType
|
||||
*/
|
||||
private function getRandomActivityType()
|
||||
{
|
||||
$types = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillActivityBundle:ActivityType')
|
||||
->findAll();
|
||||
|
||||
return $types[array_rand($types)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $centerName
|
||||
*
|
||||
* @return \Chill\MainBundle\Entity\Scope
|
||||
*/
|
||||
private function getRandomScope($username, $centerName)
|
||||
{
|
||||
$user = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneByUsername($username);
|
||||
|
||||
if (null === $user) {
|
||||
throw new RuntimeException("The user with username {$username} "
|
||||
. 'does not exists in database. Did you add fixtures ?');
|
||||
}
|
||||
|
||||
$center = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:Center')
|
||||
->findOneByName($centerName);
|
||||
|
||||
// get scope reachable by both role UPDATE and DELETE
|
||||
$reachableScopesUpdate = static::$kernel->getContainer()
|
||||
->get('chill.main.security.authorization.helper')
|
||||
->getReachableScopes(
|
||||
$user,
|
||||
new Role('CHILL_ACTIVITY_UPDATE'),
|
||||
$center
|
||||
);
|
||||
$reachableScopesDelete = static::$kernel->getContainer()
|
||||
->get('chill.main.security.authorization.helper')
|
||||
->getReachableScopes(
|
||||
$user,
|
||||
new Role('CHILL_ACTIVITY_DELETE'),
|
||||
$center
|
||||
);
|
||||
$reachableScopesId = array_intersect(
|
||||
array_map(function ($s) { return $s->getId(); }, $reachableScopesDelete),
|
||||
array_map(function ($s) { return $s->getId(); }, $reachableScopesUpdate)
|
||||
);
|
||||
|
||||
if (count($reachableScopesId) === 0) {
|
||||
throw new RuntimeException('there are not scope reachable for '
|
||||
. 'both CHILL_ACTIVITY_UPDATE and CHILL_ACTIVITY_DELETE');
|
||||
}
|
||||
|
||||
foreach ($reachableScopesUpdate as $scope) {
|
||||
if (in_array($scope->getId(), $reachableScopesId)) {
|
||||
$reachableScopes[] = $scope;
|
||||
}
|
||||
}
|
||||
|
||||
return $reachableScopes[array_rand($reachableScopes)];
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityReasonCategoryControllerTest extends WebTestCase
|
||||
{
|
||||
public function testToWrite()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/*
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
@@ -55,5 +67,5 @@ class ActivityReasonCategoryControllerTest extends WebTestCase
|
||||
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
@@ -1,15 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityReasonControllerTest extends WebTestCase
|
||||
{
|
||||
public function testToWrite()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/*
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
@@ -55,5 +67,5 @@ class ActivityReasonControllerTest extends WebTestCase
|
||||
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
@@ -1,15 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityTypeControllerTest extends WebTestCase
|
||||
{
|
||||
public function testToWrite()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/*
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
@@ -55,5 +67,5 @@ class ActivityTypeControllerTest extends WebTestCase
|
||||
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Aggregator;
|
||||
@@ -22,59 +12,59 @@ namespace Chill\ActivityBundle\Tests\Aggregator;
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
|
||||
/**
|
||||
* Add tests for ActivityReasonAggregator
|
||||
* Add tests for ActivityReasonAggregator.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityReasonAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\ActivityBundle\Export\Aggregator\ActivityReasonAggregator
|
||||
*/
|
||||
private $aggregator;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.activity.export.reason_aggregator');
|
||||
|
||||
|
||||
$this->aggregator = $container->get('chill.activity.export.reason_aggregator');
|
||||
|
||||
// add a fake request with a default locale (used in translatable string)
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$prophet = new \Prophecy\Prophet();
|
||||
$request = $prophet->prophesize();
|
||||
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
|
||||
$request->getLocale()->willReturn('fr');
|
||||
|
||||
|
||||
$container->get('request_stack')
|
||||
->push($request->reveal());
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
|
||||
public function getAggregator()
|
||||
{
|
||||
return $this->aggregator;
|
||||
}
|
||||
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array('level' => 'reasons'),
|
||||
array('level' => 'categories')
|
||||
);
|
||||
return [
|
||||
['level' => 'reasons'],
|
||||
['level' => 'categories'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
if (null === static::$kernel) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
||||
return [
|
||||
$em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity'),
|
||||
@@ -86,8 +76,7 @@ class ActivityReasonAggregatorTest extends AbstractAggregatorTest
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity')
|
||||
->join('activity.reasons', 'reasons')
|
||||
->join('reasons.category', 'category')
|
||||
);
|
||||
->join('reasons.category', 'category'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Aggregator;
|
||||
@@ -22,58 +12,58 @@ namespace Chill\ActivityBundle\Tests\Aggregator;
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
|
||||
/**
|
||||
* Add tests for ActivityTypeAggregator
|
||||
* Add tests for ActivityTypeAggregator.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityTypeAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\ActivityBundle\Export\Aggregator\ActivityReasonAggregator
|
||||
*/
|
||||
private $aggregator;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.activity.export.type_aggregator');
|
||||
|
||||
|
||||
$this->aggregator = $container->get('chill.activity.export.type_aggregator');
|
||||
|
||||
// add a fake request with a default locale (used in translatable string)
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$prophet = new \Prophecy\Prophet();
|
||||
$request = $prophet->prophesize();
|
||||
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
|
||||
$request->getLocale()->willReturn('fr');
|
||||
|
||||
|
||||
$container->get('request_stack')
|
||||
->push($request->reveal());
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
|
||||
public function getAggregator()
|
||||
{
|
||||
return $this->aggregator;
|
||||
}
|
||||
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array()
|
||||
);
|
||||
return [
|
||||
[],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
if (null === static::$kernel) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
||||
return [
|
||||
$em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity'),
|
||||
@@ -85,8 +75,7 @@ class ActivityTypeAggregatorTest extends AbstractAggregatorTest
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity')
|
||||
->join('activity.reasons', 'reasons')
|
||||
->join('reasons.category', 'category')
|
||||
);
|
||||
->join('reasons.category', 'category'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Aggregator;
|
||||
@@ -22,57 +12,58 @@ namespace Chill\ActivityBundle\Tests\Aggregator;
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
|
||||
/**
|
||||
* Add tests for ActivityUsernAggregator
|
||||
* Add tests for ActivityUsernAggregator.
|
||||
*
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityUserAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\ActivityBundle\Export\Aggregator\ActivityUserAggregator
|
||||
*/
|
||||
private $aggregator;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.activity.export.user_aggregator');
|
||||
|
||||
|
||||
$this->aggregator = $container->get('chill.activity.export.user_aggregator');
|
||||
|
||||
// add a fake request with a default locale (used in translatable string)
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$prophet = new \Prophecy\Prophet();
|
||||
$request = $prophet->prophesize();
|
||||
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
|
||||
$request->getLocale()->willReturn('fr');
|
||||
|
||||
|
||||
$container->get('request_stack')
|
||||
->push($request->reveal());
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
|
||||
public function getAggregator()
|
||||
{
|
||||
return $this->aggregator;
|
||||
}
|
||||
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array()
|
||||
);
|
||||
return [
|
||||
[],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
if (null === static::$kernel) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
||||
return [
|
||||
$em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity'),
|
||||
@@ -84,8 +75,7 @@ class ActivityUserAggregatorTest extends AbstractAggregatorTest
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity')
|
||||
->join('activity.reasons', 'reasons')
|
||||
->join('reasons.category', 'category')
|
||||
);
|
||||
->join('reasons.category', 'category'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,32 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Export\Export;
|
||||
|
||||
use Chill\MainBundle\Test\Export\AbstractExportTest;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CountActivityTest extends AbstractExportTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var
|
||||
* @var
|
||||
*/
|
||||
private $export;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
/* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
|
||||
$this->export = $container->get('chill.activity.export.count_activity');
|
||||
}
|
||||
|
||||
|
||||
public function getExport()
|
||||
{
|
||||
return $this->export;
|
||||
@@ -34,17 +39,16 @@ class CountActivityTest extends AbstractExportTest
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array()
|
||||
);
|
||||
return [
|
||||
[],
|
||||
];
|
||||
}
|
||||
|
||||
public function getModifiersCombination()
|
||||
{
|
||||
return array(
|
||||
array('activity'),
|
||||
array('activity', 'person')
|
||||
);
|
||||
return [
|
||||
['activity'],
|
||||
['activity', 'person'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Export\Export;
|
||||
@@ -22,67 +12,33 @@ namespace Chill\ActivityBundle\Tests\Export\Export;
|
||||
use Chill\MainBundle\Test\Export\AbstractExportTest;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ListActivityTest extends AbstractExportTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\ActivityBundle\Export\Export\ListActivity
|
||||
*/
|
||||
private $export;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
/* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
|
||||
$this->export = $container->get('chill.activity.export.list_activity');
|
||||
|
||||
|
||||
// add a fake request with a default locale (used in translatable string)
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$prophet = new \Prophecy\Prophet();
|
||||
$request = $prophet->prophesize();
|
||||
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
|
||||
$request->getLocale()->willReturn('fr');
|
||||
|
||||
|
||||
$container->get('request_stack')
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array('fields' => array(
|
||||
'id',
|
||||
'date',
|
||||
'durationTime',
|
||||
'attendee',
|
||||
'user_username',
|
||||
'circle_name',
|
||||
'type_name',
|
||||
'person_firstname',
|
||||
'person_lastname',
|
||||
'person_id'
|
||||
)),
|
||||
array('fields' => array(
|
||||
'id',
|
||||
'list_reasons'
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
public function getModifiersCombination()
|
||||
{
|
||||
return array(
|
||||
array('activity'),
|
||||
array('activity', 'person')
|
||||
);
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
public function getExport()
|
||||
@@ -90,4 +46,33 @@ class ListActivityTest extends AbstractExportTest
|
||||
return $this->export;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return [
|
||||
['fields' => [
|
||||
'id',
|
||||
'date',
|
||||
'durationTime',
|
||||
'attendee',
|
||||
'user_username',
|
||||
'circle_name',
|
||||
'type_name',
|
||||
'person_firstname',
|
||||
'person_lastname',
|
||||
'person_id',
|
||||
]],
|
||||
['fields' => [
|
||||
'id',
|
||||
'list_reasons',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
public function getModifiersCombination()
|
||||
{
|
||||
return [
|
||||
['activity'],
|
||||
['activity', 'person'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -1,32 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Export\Export;
|
||||
|
||||
use Chill\MainBundle\Test\Export\AbstractExportTest;
|
||||
|
||||
/**
|
||||
* Test the "sum" part of StatActivityDuration
|
||||
* Test the "sum" part of StatActivityDuration.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class StatActivityDurationSumTest extends AbstractExportTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\ActivityBundle\Export\Export\StatActivityDuration
|
||||
*/
|
||||
private $export;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
/* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
|
||||
$this->export = $container->get('chill.activity.export.sum_activity_duration');
|
||||
}
|
||||
|
||||
|
||||
public function getExport()
|
||||
{
|
||||
return $this->export;
|
||||
@@ -34,17 +41,16 @@ class StatActivityDurationSumTest extends AbstractExportTest
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array()
|
||||
);
|
||||
return [
|
||||
[],
|
||||
];
|
||||
}
|
||||
|
||||
public function getModifiersCombination()
|
||||
{
|
||||
return array(
|
||||
array('activity'),
|
||||
array('activity', 'person')
|
||||
);
|
||||
return [
|
||||
['activity'],
|
||||
['activity', 'person'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Filter;
|
||||
@@ -23,37 +13,34 @@ use Chill\MainBundle\Test\Export\AbstractFilterTest;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityReasonFilterTest extends AbstractFilterTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Export\Filter\GenderFilter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
|
||||
$this->filter = $container->get('chill.activity.export.reason_filter');
|
||||
|
||||
|
||||
// add a fake request with a default locale (used in translatable string)
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$prophet = new \Prophecy\Prophet();
|
||||
$request = $prophet->prophesize();
|
||||
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
|
||||
$request->getLocale()->willReturn('fr');
|
||||
|
||||
|
||||
$container->get('request_stack')
|
||||
->push($request->reveal());
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getFilter()
|
||||
{
|
||||
return $this->filter;
|
||||
@@ -61,36 +48,35 @@ class ActivityReasonFilterTest extends AbstractFilterTest
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
if (null === static::$kernel) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
;
|
||||
|
||||
$reasons = $em->createQuery("SELECT reason "
|
||||
. "FROM ChillActivityBundle:ActivityReason reason")
|
||||
->getResult();
|
||||
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$reasons = $em->createQuery('SELECT reason '
|
||||
. 'FROM ChillActivityBundle:ActivityReason reason')
|
||||
->getResult();
|
||||
|
||||
// generate an array of 5 different combination of results
|
||||
for ($i=0; $i < 5; $i++) {
|
||||
$r[] = array('reasons' => new ArrayCollection(array_splice($reasons, ($i + 1) * -1)));
|
||||
for ($i = 0; 5 > $i; ++$i) {
|
||||
$r[] = ['reasons' => new ArrayCollection(array_splice($reasons, ($i + 1) * -1))];
|
||||
}
|
||||
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
if (null === static::$kernel) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
||||
return [
|
||||
$em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity'),
|
||||
@@ -102,8 +88,7 @@ class ActivityReasonFilterTest extends AbstractFilterTest
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity')
|
||||
->join('activity.reasons', 'reasons')
|
||||
->join('reasons.category', 'category')
|
||||
);
|
||||
->join('reasons.category', 'category'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,56 +1,47 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Filter;
|
||||
|
||||
use Chill\MainBundle\Test\Export\AbstractFilterTest;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Export\Filter\PersonHavingActivityBetweenDateFilter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
|
||||
$this->filter = $container->get('chill.activity.export.'
|
||||
. 'person_having_an_activity_between_date_filter');
|
||||
|
||||
|
||||
// add a fake request with a default locale (used in translatable string)
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$prophet = new \Prophecy\Prophet();
|
||||
$request = $prophet->prophesize();
|
||||
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
|
||||
$request->getLocale()->willReturn('fr');
|
||||
|
||||
|
||||
$container->get('request_stack')
|
||||
->push($request->reveal());
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
|
||||
public function getFilter()
|
||||
{
|
||||
return $this->filter;
|
||||
@@ -58,49 +49,33 @@ class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
$date_from = \DateTime::createFromFormat('Y-m-d', '2015-01-15');
|
||||
$date_to = new \DateTime(); // today
|
||||
$date_from = DateTime::createFromFormat('Y-m-d', '2015-01-15');
|
||||
$date_to = new DateTime(); // today
|
||||
$reasons = $this->getActivityReasons();
|
||||
|
||||
|
||||
$data = array();
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$data[] = array(
|
||||
$data = [];
|
||||
|
||||
for ($i = 0; 4 > $i; ++$i) {
|
||||
$data[] = [
|
||||
'date_from' => $date_from,
|
||||
'date_to' => $date_to,
|
||||
'reasons' => array_slice($reasons, 0, 1 + $i)
|
||||
);
|
||||
'date_to' => $date_to,
|
||||
'reasons' => array_slice($reasons, 0, 1 + $i),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all activity reasons
|
||||
*
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityReason[]
|
||||
*/
|
||||
private function getActivityReasons()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
return static::$kernel->getContainer()
|
||||
->get('chill_activity.repository.reason')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
if (null === static::$kernel) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
||||
return [
|
||||
$em->createQueryBuilder()
|
||||
->select('count(person.id)')
|
||||
->from('ChillPersonBundle:Person', 'person')
|
||||
@@ -112,6 +87,22 @@ class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
|
||||
->join('activity.person', 'person')
|
||||
// add a fake where clause
|
||||
->where('person.id > 0'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all activity reasons.
|
||||
*
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityReason[]
|
||||
*/
|
||||
private function getActivityReasons()
|
||||
{
|
||||
if (null === static::$kernel) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
return static::$kernel->getContainer()
|
||||
->get('chill_activity.repository.reason')
|
||||
->findAll();
|
||||
}
|
||||
}
|
||||
|
@@ -1,183 +1,170 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Form;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Chill\ActivityBundle\Form\ActivityType;
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\ActivityBundle\Form\ActivityType;
|
||||
use DateTime;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityTypeTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Form\FormBuilderInterface
|
||||
* @var \Chill\MainBundle\Entity\Center
|
||||
*/
|
||||
protected $formBuilder;
|
||||
protected $center;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Form\FormBuilderInterface
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\MainBundle\Entity\Center
|
||||
*/
|
||||
protected $center;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->container = self::$kernel->getContainer();
|
||||
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
|
||||
$prophet = new \Prophecy\Prophet();
|
||||
|
||||
$this->formBuilder = $this->container
|
||||
->get('form.factory')
|
||||
->createBuilder(FormType::class, null, array(
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token'
|
||||
));
|
||||
->get('form.factory')
|
||||
->createBuilder(FormType::class, null, [
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token',
|
||||
]);
|
||||
|
||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||
$request->setLocale('fr');
|
||||
|
||||
self::$kernel->getContainer()
|
||||
->get('request_stack')
|
||||
->push($request);
|
||||
->get('request_stack')
|
||||
->push($request);
|
||||
|
||||
$this->user = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(array('username' => 'center a_social'));
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(['username' => 'center a_social']);
|
||||
$this->center = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(['name' => 'Center A']);
|
||||
$token = $prophet->prophesize();
|
||||
$token->willExtend(AbstractToken::class);
|
||||
$token->getUser()->willReturn($this->user);
|
||||
$this->container->get('security.token_storage')
|
||||
->setToken($token->reveal());
|
||||
|
||||
->setToken($token->reveal());
|
||||
}
|
||||
|
||||
public function testForm()
|
||||
{
|
||||
$form = $this->formBuilder
|
||||
->add('activity', ActivityType::class, array(
|
||||
'center' => $this->center,
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE')
|
||||
))
|
||||
->getForm();
|
||||
->add('activity', ActivityType::class, [
|
||||
'center' => $this->center,
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE'),
|
||||
])
|
||||
->getForm();
|
||||
|
||||
$form->submit(array());
|
||||
$form->submit([]);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertTrue($form->isValid());
|
||||
$this->assertInstanceOf(Activity::class, $form->getData()['activity']);
|
||||
|
||||
}
|
||||
|
||||
public function testFormSubmitting()
|
||||
{
|
||||
$form = $this->formBuilder
|
||||
->add('activity', ActivityType::class, array(
|
||||
'center' => $this->center,
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE')
|
||||
))
|
||||
->getForm();
|
||||
->add('activity', ActivityType::class, [
|
||||
'center' => $this->center,
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE'),
|
||||
])
|
||||
->getForm();
|
||||
|
||||
$form->submit(array( 'activity' => array(
|
||||
$form->submit(['activity' => [
|
||||
'date' => '9-3-2015',
|
||||
'durationTime' => 300,
|
||||
// 'remark' => 'blabla',
|
||||
'attendee' => true
|
||||
)));
|
||||
// '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->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(
|
||||
'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
|
||||
* the listed in the possible durationTime.
|
||||
*/
|
||||
public function testFormWithActivityHavingDifferentTime()
|
||||
{
|
||||
$activity = new Activity();
|
||||
$activity->setDurationTime(\DateTime::createFromFormat('U', 60));
|
||||
$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'
|
||||
));
|
||||
->get('form.factory')
|
||||
->createBuilder(FormType::class, ['activity' => $activity], [
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token',
|
||||
]);
|
||||
|
||||
$form = $builder
|
||||
->add('activity', ActivityType::class, array(
|
||||
'center' => $this->center,
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE')
|
||||
))
|
||||
->getForm();
|
||||
->add('activity', ActivityType::class, [
|
||||
'center' => $this->center,
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE'),
|
||||
])
|
||||
->getForm();
|
||||
|
||||
|
||||
$form->submit(array( 'activity' => array(
|
||||
$form->submit(['activity' => [
|
||||
'date' => '9-3-2015',
|
||||
'durationTime' => 60,
|
||||
// 'remark' => 'blabla',
|
||||
'attendee' => true
|
||||
)));
|
||||
// 'remark' => 'blabla',
|
||||
'attendee' => true,
|
||||
]]);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertTrue($form->isValid());
|
||||
@@ -186,8 +173,11 @@ class ActivityTypeTest extends KernelTestCase
|
||||
/* @var $activity Activity */
|
||||
$activity = $form->getData()['activity'];
|
||||
|
||||
$this->assertEquals('00:01', $activity->getDurationTime()->format('H:i'),
|
||||
"Test the formatted hour is correct");
|
||||
$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();
|
||||
@@ -195,11 +185,11 @@ class ActivityTypeTest extends KernelTestCase
|
||||
$this->assertTrue(isset($view['activity']['durationTime']));
|
||||
|
||||
// map all the values in an array
|
||||
$values = array_map(function($choice) { return $choice->value; },
|
||||
$view['activity']['durationTime']->vars['choices']);
|
||||
$values = array_map(
|
||||
function ($choice) { return $choice->value; },
|
||||
$view['activity']['durationTime']->vars['choices']
|
||||
);
|
||||
|
||||
$this->assertContains(60, $values);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,110 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 Champs Libres <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
use Chill\ActivityBundle\Form\Type\TranslatableActivityReason;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Component\Form\PreloadedExtension;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
/**
|
||||
* Test translatableActivityReason
|
||||
* Test translatableActivityReason.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class TranslatableActivityReasonTest extends TypeTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Prophecy\Prophet
|
||||
* @var Prophecy\Prophet
|
||||
*/
|
||||
private static $prophet;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function getExtensions()
|
||||
{
|
||||
$entityType = $this->getEntityType();
|
||||
|
||||
return array(new PreloadedExtension(array(
|
||||
'entity' => $entityType
|
||||
), array()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testSimple()
|
||||
{
|
||||
$translatableActivityReasonType = new TranslatableActivityReason(
|
||||
$this->getTranslatableStringHelper()
|
||||
);
|
||||
|
||||
$this->markTestSkipped("See issue 651");
|
||||
$this->getTranslatableStringHelper()
|
||||
);
|
||||
|
||||
$this->markTestSkipped('See issue 651');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $fallbackLocale
|
||||
* @return TranslatableStringHelper
|
||||
*/
|
||||
protected function getTranslatableStringHelper($locale = 'en',
|
||||
$fallbackLocale = 'en')
|
||||
{
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$requestStack = $prophet->prophesize();
|
||||
$request = $prophet->prophesize();
|
||||
$translator = $prophet->prophesize();
|
||||
|
||||
$request->willExtend('Symfony\Component\HttpFoundation\Request');
|
||||
$request->getLocale()->willReturn($fallbackLocale);
|
||||
|
||||
$requestStack->willExtend('Symfony\Component\HttpFoundation\RequestStack');
|
||||
$requestStack->getCurrentRequest()->will(function () use ($request) {
|
||||
return $request;
|
||||
});
|
||||
|
||||
$translator->willExtend('Symfony\Component\Translation\Translator');
|
||||
$translator->getFallbackLocales()->willReturn($locale);
|
||||
|
||||
return new TranslatableStringHelper($requestStack->reveal(),
|
||||
$translator->reveal());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Bridge\Doctrine\Form\Type\EntityType
|
||||
*/
|
||||
protected function getEntityType()
|
||||
{
|
||||
$managerRegistry = (new \Prophecy\Prophet())->prophesize();
|
||||
|
||||
|
||||
$managerRegistry->willImplement('Doctrine\Common\Persistence\ManagerRegistry');
|
||||
|
||||
|
||||
return new \Symfony\Bridge\Doctrine\Form\Type\EntityType($managerRegistry->reveal());
|
||||
}
|
||||
|
||||
protected function getExtensions()
|
||||
{
|
||||
$entityType = $this->getEntityType();
|
||||
|
||||
return [new PreloadedExtension([
|
||||
'entity' => $entityType,
|
||||
], [])];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @param string $fallbackLocale
|
||||
*
|
||||
* @return TranslatableStringHelper
|
||||
*/
|
||||
protected function getTranslatableStringHelper(
|
||||
$locale = 'en',
|
||||
$fallbackLocale = 'en'
|
||||
)
|
||||
{
|
||||
$prophet = new \Prophecy\Prophet();
|
||||
$requestStack = $prophet->prophesize();
|
||||
$request = $prophet->prophesize();
|
||||
$translator = $prophet->prophesize();
|
||||
|
||||
$request->willExtend('Symfony\Component\HttpFoundation\Request');
|
||||
$request->getLocale()->willReturn($fallbackLocale);
|
||||
|
||||
$requestStack->willExtend('Symfony\Component\HttpFoundation\RequestStack');
|
||||
$requestStack->getCurrentRequest()->will(function () use ($request) {
|
||||
return $request;
|
||||
});
|
||||
|
||||
$translator->willExtend('Symfony\Component\Translation\Translator');
|
||||
$translator->getFallbackLocales()->willReturn($locale);
|
||||
|
||||
return new TranslatableStringHelper(
|
||||
$requestStack->reveal(),
|
||||
$translator->reveal()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,116 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Form\Type;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Chill\ActivityBundle\Form\Type\TranslatableActivityType;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class TranslatableActivityTypeTest extends KernelTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Form\FormBuilderInterface
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
|
||||
$this->container = self::$kernel->getContainer();
|
||||
|
||||
|
||||
$this->builder = $this->container
|
||||
->get('form.factory')
|
||||
->createBuilder(FormType::class, null, array(
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token'
|
||||
));
|
||||
|
||||
->get('form.factory')
|
||||
->createBuilder(FormType::class, null, [
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token',
|
||||
]);
|
||||
|
||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||
$request->setLocale('fr');
|
||||
|
||||
|
||||
$this->container->get('request_stack')
|
||||
->push($request);
|
||||
->push($request);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityType
|
||||
*/
|
||||
protected function getRandomType($active = true)
|
||||
{
|
||||
$types = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillActivityBundle:ActivityType')
|
||||
->findBy(array('active' => $active));
|
||||
|
||||
return $types[array_rand($types)];
|
||||
}
|
||||
|
||||
|
||||
public function testForm()
|
||||
{
|
||||
$type = $this->getRandomType();
|
||||
$form = $this->builder->add('type', TranslatableActivityType::class)
|
||||
->getForm();
|
||||
|
||||
$form->submit(array(
|
||||
'type' => $type->getId()
|
||||
));
|
||||
|
||||
->getForm();
|
||||
|
||||
$form->submit([
|
||||
'type' => $type->getId(),
|
||||
]);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertInstanceOf(\Chill\ActivityBundle\Entity\ActivityType::class,
|
||||
$form->getData()['type'],
|
||||
"The data is an instance of Chill\ActivityBundle\Entity\ActivityType");
|
||||
$this->assertInstanceOf(
|
||||
\Chill\ActivityBundle\Entity\ActivityType::class,
|
||||
$form->getData()['type'],
|
||||
'The data is an instance of Chill\\ActivityBundle\\Entity\\ActivityType'
|
||||
);
|
||||
$this->assertEquals($type->getId(), $form->getData()['type']->getId());
|
||||
|
||||
|
||||
// test the ordering of the types in the form
|
||||
// since 2016-11-14 the types are not alphabetically ordered, skipping
|
||||
/*$view = $form->createView();
|
||||
|
||||
|
||||
$this->assertGreaterThan(0, count($view['type']->vars['choices']),
|
||||
"test that there are at least one choice");
|
||||
|
||||
|
||||
foreach($view['type']->vars['choices'] as $choice) {
|
||||
// initialize the previous value is not set (this is the first)
|
||||
if (!isset($previous)) {
|
||||
$previous = $choice->label;
|
||||
if (!isset($previous)) {
|
||||
$previous = $choice->label;
|
||||
} else {
|
||||
$this->assertTrue($previous < $choice->label);
|
||||
$previous = $choice->label;
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $active
|
||||
*
|
||||
* @return \Chill\ActivityBundle\Entity\ActivityType
|
||||
*/
|
||||
protected function getRandomType($active = true)
|
||||
{
|
||||
$types = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillActivityBundle:ActivityType')
|
||||
->findBy(['active' => $active]);
|
||||
|
||||
return $types[array_rand($types)];
|
||||
}
|
||||
}
|
||||
|
@@ -1,103 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Security\Authorization;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
use Chill\ActivityBundle\Test\PrepareActivityTrait;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Test\PrepareUserTrait;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Test\PrepareCenterTrait;
|
||||
use Chill\MainBundle\Test\PrepareScopeTrait;
|
||||
use Chill\MainBundle\Test\PrepareUserTrait;
|
||||
use Chill\PersonBundle\Test\PreparePersonTrait;
|
||||
use Chill\ActivityBundle\Test\PrepareActivityTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ActivityVoterTest extends KernelTestCase
|
||||
{
|
||||
use PrepareUserTrait, PrepareCenterTrait, PrepareScopeTrait,
|
||||
PreparePersonTrait, PrepareActivityTrait;
|
||||
|
||||
use PrepareUserTrait;
|
||||
use PrepareCenterTrait;
|
||||
use PrepareScopeTrait;
|
||||
use PreparePersonTrait;
|
||||
use PrepareActivityTrait;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Security\Authorization\PersonVoter
|
||||
*/
|
||||
protected $voter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Prophecy\Prophet
|
||||
*/
|
||||
protected $prophet;
|
||||
|
||||
|
||||
/**
|
||||
* @var \Chill\PersonBundle\Security\Authorization\PersonVoter
|
||||
*/
|
||||
protected $voter;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
$this->voter = static::$kernel->getContainer()
|
||||
->get('chill.activity.security.authorization.activity_voter');
|
||||
->get('chill.activity.security.authorization.activity_voter');
|
||||
$this->prophet = new \Prophecy\Prophet();
|
||||
}
|
||||
|
||||
public function testNullUser()
|
||||
{
|
||||
$token = $this->prepareToken();
|
||||
$center = $this->prepareCenter(1, 'center');
|
||||
$person = $this->preparePerson($center);
|
||||
$scope = $this->prepareScope(1, 'default');
|
||||
$activity = $this->prepareActivity($scope, $person);
|
||||
|
||||
$this->assertEquals(
|
||||
VoterInterface::ACCESS_DENIED,
|
||||
$this->voter->vote($token, $activity, array('CHILL_ACTIVITY_SEE')),
|
||||
"assert that a null user is not allowed to see"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider dataProvider_testVoteAction
|
||||
* @param type $expectedResult
|
||||
* @param User $user
|
||||
* @param Scope $scope
|
||||
* @param Center $center
|
||||
* @param string $attribute
|
||||
* @param string $message
|
||||
*/
|
||||
public function testVoteAction($expectedResult, User $user, Scope $scope,
|
||||
Center $center, $attribute, $message)
|
||||
{
|
||||
$token = $this->prepareToken($user);
|
||||
$activity = $this->prepareActivity($scope, $this->preparePerson($center));
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResult,
|
||||
$this->voter->vote($token, $activity, array($attribute)),
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function dataProvider_testVoteAction()
|
||||
{
|
||||
$centerA = $this->prepareCenter(1, 'center A');
|
||||
@@ -105,72 +57,112 @@ class ActivityVoterTest extends KernelTestCase
|
||||
$scopeA = $this->prepareScope(1, 'scope default');
|
||||
$scopeB = $this->prepareScope(2, 'scope B');
|
||||
$scopeC = $this->prepareScope(3, 'scope C');
|
||||
|
||||
$userA = $this->prepareUser(array(
|
||||
array(
|
||||
'center' => $centerA,
|
||||
'permissionsGroup' => array(
|
||||
|
||||
$userA = $this->prepareUser([
|
||||
[
|
||||
'center' => $centerA,
|
||||
'permissionsGroup' => [
|
||||
['scope' => $scopeB, 'role' => 'CHILL_ACTIVITY_CREATE'],
|
||||
['scope' => $scopeA, 'role' => 'CHILL_ACTIVITY_SEE']
|
||||
)
|
||||
),
|
||||
array(
|
||||
'center' => $centerB,
|
||||
'permissionsGroup' => array(
|
||||
['scope' => $scopeA, 'role' => 'CHILL_ACTIVITY_CREATE'],
|
||||
['scope' => $scopeC, 'role' => 'CHILL_ACTIVITY_CREATE']
|
||||
)
|
||||
)
|
||||
|
||||
));
|
||||
|
||||
return array(
|
||||
array(
|
||||
['scope' => $scopeA, 'role' => 'CHILL_ACTIVITY_SEE'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'center' => $centerB,
|
||||
'permissionsGroup' => [
|
||||
['scope' => $scopeA, 'role' => 'CHILL_ACTIVITY_CREATE'],
|
||||
['scope' => $scopeC, 'role' => 'CHILL_ACTIVITY_CREATE'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
return [
|
||||
[
|
||||
VoterInterface::ACCESS_GRANTED,
|
||||
$userA,
|
||||
$scopeB,
|
||||
$centerA,
|
||||
'CHILL_ACTIVITY_CREATE',
|
||||
'assert that a user granted with same rights'
|
||||
),
|
||||
array(
|
||||
'assert that a user granted with same rights',
|
||||
],
|
||||
[
|
||||
VoterInterface::ACCESS_GRANTED,
|
||||
$userA,
|
||||
$scopeB,
|
||||
$centerA,
|
||||
'CHILL_ACTIVITY_SEE',
|
||||
'assert that a user granted with inheritance rights'
|
||||
),
|
||||
array(
|
||||
'assert that a user granted with inheritance rights',
|
||||
],
|
||||
[
|
||||
VoterInterface::ACCESS_DENIED,
|
||||
$userA,
|
||||
$scopeC,
|
||||
$centerA,
|
||||
'CHILL_ACTIVITY_SEE',
|
||||
'assert that a suer is denied if he is not granted right on this center'
|
||||
|
||||
)
|
||||
'assert that a suer is denied if he is not granted right on this center',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testNullUser()
|
||||
{
|
||||
$token = $this->prepareToken();
|
||||
$center = $this->prepareCenter(1, 'center');
|
||||
$person = $this->preparePerson($center);
|
||||
$scope = $this->prepareScope(1, 'default');
|
||||
$activity = $this->prepareActivity($scope, $person);
|
||||
|
||||
$this->assertEquals(
|
||||
VoterInterface::ACCESS_DENIED,
|
||||
$this->voter->vote($token, $activity, ['CHILL_ACTIVITY_SEE']),
|
||||
'assert that a null user is not allowed to see'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* prepare a token interface with correct rights
|
||||
*
|
||||
* @dataProvider dataProvider_testVoteAction
|
||||
*
|
||||
* @param type $expectedResult
|
||||
* @param string $attribute
|
||||
* @param string $message
|
||||
*/
|
||||
public function testVoteAction(
|
||||
$expectedResult,
|
||||
User $user,
|
||||
Scope $scope,
|
||||
Center $center,
|
||||
$attribute,
|
||||
$message
|
||||
)
|
||||
{
|
||||
$token = $this->prepareToken($user);
|
||||
$activity = $this->prepareActivity($scope, $this->preparePerson($center));
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResult,
|
||||
$this->voter->vote($token, $activity, [$attribute]),
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare a token interface with correct rights.
|
||||
*
|
||||
* if $permissions = null, user will be null (no user associated with token
|
||||
*
|
||||
*
|
||||
* @return \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
|
||||
*/
|
||||
protected function prepareToken(User $user = null)
|
||||
{
|
||||
protected function prepareToken(?User $user = null)
|
||||
{
|
||||
$token = $this->prophet->prophesize();
|
||||
$token
|
||||
->willImplement('\Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
||||
if ($user === NULL) {
|
||||
|
||||
if (null === $user) {
|
||||
$token->getUser()->willReturn(null);
|
||||
} else {
|
||||
$token->getUser()->willReturn($user);
|
||||
}
|
||||
|
||||
|
||||
return $token->reveal();
|
||||
}
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Timeline;
|
||||
@@ -22,15 +12,13 @@ namespace Chill\ActivityBundle\Tests\Timeline;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class TimelineProviderTest extends WebTestCase
|
||||
{
|
||||
public function testAnActivityIsShownOnTimeline()
|
||||
{
|
||||
$this->markTestSkipped("we have to write fixtures before writing this tests");
|
||||
$this->markTestSkipped('we have to write fixtures before writing this tests');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user