/**
  * @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();
 }
 /**
  * @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']]]];
 }
 public function testNotEmptyRole()
 {
     $name = 'another test role';
     $role = new AccountUserRole($name);
     $this->assertEquals(AccountUserRole::PREFIX_ROLE . 'ANOTHER_TEST_ROLE', $role->getRole());
 }
 /**
  * @param ObjectManager $manager
  * @param AccountUserRole $role
  */
 protected function setWebsiteDefaultRoles(ObjectManager $manager, AccountUserRole $role)
 {
     $websites = $manager->getRepository('OroB2BWebsiteBundle:Website')->findAll();
     foreach ($websites as $website) {
         $role->addWebsite($website);
     }
 }