/**
  * @param ObjectManager $manager
  * @param string $roleLabel
  */
 protected function loadRoleWithoutUserAndWebsite(ObjectManager $manager, $roleLabel)
 {
     $entity = new AccountUserRole();
     $entity->setLabel($roleLabel);
     $this->setReference($entity->getLabel(), $entity);
     $manager->persist($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $userManager = $this->container->get('orob2b_account_user.manager');
     $locator = $this->container->get('file_locator');
     $filePath = $locator->locate('@OroB2BCustomerBundle/Migrations/Data/Demo/ORM/data/account-users.csv');
     if (is_array($filePath)) {
         $filePath = current($filePath);
     }
     $handler = fopen($filePath, 'r');
     $headers = fgetcsv($handler, 1000, ',');
     $organizations = $manager->getRepository('OroOrganizationBundle:Organization')->findAll();
     $organization = reset($organizations);
     $storageManager = $userManager->getStorageManager();
     $roles = [];
     while (($data = fgetcsv($handler, 1000, ',')) !== false) {
         $row = array_combine($headers, array_values($data));
         // create/get account user role
         $roleLabel = $row['role'];
         if (!array_key_exists($roleLabel, $roles)) {
             $newRole = new AccountUserRole();
             $newRole->setLabel($roleLabel)->setRole($roleLabel);
             $storageManager->persist($newRole);
             $roles[$roleLabel] = $newRole;
         }
         $role = $roles[$roleLabel];
         // create account user
         /** @var AccountUser $accountUser */
         $accountUser = $userManager->createUser();
         $accountUser->setUsername($row['email'])->setEmail($row['email'])->setPassword($row['email'])->setFirstName($row['firstName'])->setLastName($row['lastName'])->setPlainPassword(md5(uniqid(mt_rand(), true)))->setEnabled(true)->setOrganization($organization)->addOrganization($organization)->setLoginCount(0)->addRole($role);
         $userManager->updateUser($accountUser, false);
     }
     fclose($handler);
     $storageManager->flush();
 }
 public function testRole()
 {
     $name = 'test role#$%';
     $role = new AccountUserRole();
     $this->assertEmpty($role->getId());
     $this->assertEmpty($role->getLabel());
     $this->assertEmpty($role->getRole());
     $role->setLabel($name);
     $this->assertEquals($name, $role->getLabel());
     $this->assertEquals(AccountUserRole::PREFIX_ROLE, $role->getPrefix());
     $role->setRole($name);
     $this->assertStringStartsWith(AccountUserRole::PREFIX_ROLE . 'TEST_ROLE_', $role->getRole());
     $this->assertEquals($name, (string) $role);
 }
 /**
  * @return array
  */
 public function submitDataProvider()
 {
     $roleLabel = 'customer_role_label';
     $alteredRoleLabel = 'altered_role_label';
     $defaultRole = new AccountUserRole();
     $defaultRole->setLabel($roleLabel);
     /** @var AccountUserRole $existingRoleBefore */
     $existingRoleBefore = $this->getEntity(self::DATA_CLASS, 1);
     $existingRoleBefore->setLabel($roleLabel);
     $existingRoleBefore->setRole($roleLabel);
     $existingRoleAfter = clone $existingRoleBefore;
     $existingRoleAfter->setLabel($alteredRoleLabel);
     return ['empty' => ['options' => ['privilege_config' => $this->privilegeConfig], 'defaultData' => null, 'viewData' => null, 'submittedData' => ['label' => $roleLabel], 'expectedData' => $defaultRole, 'expectedFieldData' => ['entity' => [], 'action' => []]], 'existing' => ['options' => ['privilege_config' => $this->privilegeConfig], 'defaultData' => $existingRoleBefore, 'viewData' => $existingRoleBefore, 'submittedData' => ['label' => $alteredRoleLabel, 'entity' => ['first'], 'action' => ['second']], 'expectedData' => $existingRoleAfter, 'expectedFieldData' => ['entity' => ['first'], 'action' => ['second']]]];
 }
 /**
  * @param string $name
  * @param string $label
  * @return AccountUserRole
  */
 protected function createEntity($name, $label)
 {
     $role = new AccountUserRole(AccountUserRole::PREFIX_ROLE . $name);
     $role->setLabel($label);
     return $role;
 }