mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
use random activityType, activityReason, scope in test
This commit is contained in:
parent
e79ca23f2c
commit
fee5b00e35
@ -3,6 +3,7 @@
|
|||||||
namespace Chill\ActivityBundle\Tests\Controller;
|
namespace Chill\ActivityBundle\Tests\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
|
||||||
class ActivityControllerTest extends WebTestCase
|
class ActivityControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
@ -41,9 +42,9 @@ class ActivityControllerTest extends WebTestCase
|
|||||||
'minute' => '30'
|
'minute' => '30'
|
||||||
),
|
),
|
||||||
'remark' => 'blabla',
|
'remark' => 'blabla',
|
||||||
'scope' => 1,
|
'scope' => $this->getRandomScope('center a_social', 'Center A')->getId(),
|
||||||
'reason' => 2,
|
'reason' => $this->getRandomActivityReason()->getId(),
|
||||||
'type' => 3
|
'type' => $this->getRandomActivityType()->getId()
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -115,4 +116,63 @@ class ActivityControllerTest extends WebTestCase
|
|||||||
|
|
||||||
return $person;
|
return $person;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
|
||||||
|
$reachableScopes = static::$kernel->getContainer()
|
||||||
|
->get('chill.main.security.authorization.helper')
|
||||||
|
->getReachableScopes($user, new Role('CHILL_ACTIVITY_UPDATE'),
|
||||||
|
$center);
|
||||||
|
|
||||||
|
return $reachableScopes[array_rand($reachableScopes)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return \Chill\ActivityBundle\Entity\ActivityReason
|
||||||
|
*/
|
||||||
|
private function getRandomActivityReason()
|
||||||
|
{
|
||||||
|
$reasons = static::$kernel->getContainer()
|
||||||
|
->get('doctrine.orm.entity_manager')
|
||||||
|
->getRepository('ChillActivityBundle:ActivityReason')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $reasons[array_rand($reasons)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user