public function load(ObjectManager $manager) { /** * addRole was commented due a ticket BAP-1675 */ $defaultBusinessUnit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneBy(['name' => LoadOrganizationAndBusinessUnitData::MAIN_BUSINESS_UNIT]); $administrators = new Group('Administrators'); //$administrators->addRole($this->getReference('administrator_role')); if ($defaultBusinessUnit) { $administrators->setOwner($defaultBusinessUnit); } $manager->persist($administrators); $sales = new Group('Sales'); //$sales->addRole($this->getReference('manager_role')); if ($defaultBusinessUnit) { $sales->setOwner($defaultBusinessUnit); } $manager->persist($sales); $marketing = new Group('Marketing'); //$marketing->addRole($this->getReference('manager_role')); if ($defaultBusinessUnit) { $marketing->setOwner($defaultBusinessUnit); } $manager->persist($marketing); $manager->flush(); }
/** * @param Group $group * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData(Group $group, $field, $data) { switch ($field) { case 'name': $group->setName($data); break; } }
/** * Build the group entity from data * * @param array $data * * @return Group */ protected function buildGroup(array $data) { $name = $data['name']; $group = new Group($name); $owner = isset($data['owner']) ? $data['owner'] : 'Main'; $owner = $this->getOwner($owner); $group->setOwner($owner); return $group; }
public function testGroups() { $user = $this->getUser(); $role = new Role('ROLE_FOO'); $group = new Group('Users'); $group->addRole($role); $this->assertNotContains($role, $user->getRoles()); $user->addGroup($group); $this->assertContains($group, $user->getGroups()); $this->assertContains('Users', $user->getGroupNames()); $this->assertTrue($user->hasRole($role)); $this->assertTrue($user->hasGroup('Users')); $user->removeGroup($group); $this->assertFalse($user->hasRole($role)); }
/** * Load sample groups * * @param \Doctrine\Common\Persistence\ObjectManager $manager */ public function load(ObjectManager $manager) { $entityManager = $this->container->get('doctrine.orm.entity_manager'); $organization = $this->getReference('default_organization'); $defaultCrmBU = $this->getBusinessUnit($manager, 'Acme, West'); $defaultCoreBU = $this->getBusinessUnit($manager, 'Acme, East'); $defaultMainBU = $this->getBusinessUnit($manager, 'Acme, General'); $groups = array('Marketing Manager' => $defaultCrmBU, 'Executive Marketing' => $defaultCrmBU, 'Sales Manager' => $defaultCoreBU, 'Executive Sales' => $defaultCoreBU, 'Promotion Manager' => $defaultMainBU, 'Executive Director' => $defaultMainBU); foreach ($groups as $group => $user) { $newGroup = new Group($group); $newGroup->setOwner($user); $newGroup->setOrganization($organization); $entityManager->persist($newGroup); } $entityManager->flush(); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage $roles must be an instance of Doctrine\Common\Collections\Collection or an array */ public function testSetRolesThrowsInvalidArgumentException() { $this->group->setRoles('roles'); }
public function testOrganization() { $entity = new Group(); $organization = new Organization(); $this->assertNull($entity->getOrganization()); $entity->setOrganization($organization); $this->assertSame($organization, $entity->getOrganization()); }
/** * {@inheritDoc} */ public function __toString() { $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array()); return parent::__toString(); }