/** * @dataProvider roleNameProvider */ public function testRoleName($roleName, $expected) { // Arrange $a = new Role(); // Act $a->setName($roleName); // Assert $this->assertEquals($expected, $a->getName()); }
public static function setUpBeforeClass() { static::$entityCollection = array(); $roles = array(array("role___test", "ROLE_TEST"), array("role___test", "ROLE_TEST"), array("tèst tèst", "ROLE_TEST_TEST")); foreach ($roles as $value) { $role = Kernel::getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Role')->findOneByName($value[1]); if (null === $role) { $a = new Role(); $a->setName($value[0]); Kernel::getService('em')->persist($a); } } Kernel::getService('em')->flush(); }
/** * @param array $data * @param RZ\Roadiz\Core\Entities\Role $role * * @return RZ\Roadiz\Core\Entities\Role */ protected function editRole(array $data, Role $role) { if ($role->required()) { throw new EntityRequiredException($this->getTranslator()->trans("role.required.cannot_be_updated"), 1); } if (isset($data['name'])) { $existing = $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Role')->findOneBy(['name' => $data['name']]); if ($existing !== null && $existing->getId() != $role->getId()) { throw new EntityAlreadyExistsException($this->getTranslator()->trans("role.name.already.exists"), 1); } $role->setName($data['name']); $this->getService('em')->flush(); // Clear result cache $cacheDriver = $this->getService('em')->getConfiguration()->getResultCacheImpl(); if ($cacheDriver !== null) { $cacheDriver->deleteAll(); } return $role; } else { throw new \RuntimeException("Role name is not defined", 1); } return null; }