public function testUpdateFromPredefined()
 {
     //TODO: see BB-1134
     $this->markTestSkipped('Must be fixed in scope with BB-1134');
     $currentUserRoles = $this->currentUser->getRoles();
     $oldRoleId = $this->predefinedRole->getId();
     $crawler = $this->client->request('GET', $this->getUrl('orob2b_account_frontend_account_user_role_update', ['id' => $oldRoleId]));
     $form = $crawler->selectButton('Save and Close')->form();
     $token = $this->getContainer()->get('security.csrf.token_manager')->getToken('orob2b_account_frontend_account_user_role')->getValue();
     $this->client->followRedirects(true);
     $crawler = $this->client->request($form->getMethod(), $form->getUri(), ['input_action' => '', 'orob2b_account_frontend_account_user_role' => ['_token' => $token, 'label' => self::CUSTOMIZED_ROLE, 'appendUsers' => $this->currentUser->getId()]]);
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
     $content = $crawler->html();
     $this->assertContains('Account User Role has been saved', $content);
     // Find id of new role
     $response = $this->requestFrontendGrid('frontend-account-account-user-roles-grid', ['frontend-account-account-user-roles-grid[_filter][label][value]' => self::CUSTOMIZED_ROLE]);
     $result = $this->getJsonResponseContent($response, 200);
     $result = reset($result['data']);
     $newRoleId = $result['id'];
     $this->assertNotEquals($newRoleId, $oldRoleId);
     /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountUserRole $role */
     $role = $this->getUserRoleRepository()->find($newRoleId);
     $this->assertNotNull($role);
     $this->assertEquals(self::CUSTOMIZED_ROLE, $role->getLabel());
     $this->assertNotEmpty($role->getRole());
     /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountUser $user */
     $user = $this->getCurrentUser();
     // Add new role
     $this->assertCount(count($currentUserRoles) + 1, $user->getRoles());
     $this->assertEquals($user->getRole($role->getRole()), $role);
 }
 /**
  * @param AccountUserRole|AbstractRole $role
  * @param EntityManager                $manager
  */
 protected function removeOriginalRoleFromUsers(AccountUserRole $role, EntityManager $manager)
 {
     if (!$role->getId() || $role->getId() === $this->newRole->getId()) {
         return;
     }
     array_map(function (AccountUser $accountUser) use($role, $manager) {
         if ($accountUser->getAccount()->getId() === $this->loggedAccountUser->getAccount()->getId()) {
             $accountUser->removeRole($role);
             $manager->persist($accountUser);
         }
     }, $this->appendUsers);
 }
 public function testRole()
 {
     $name = 'test role#$%';
     $role = new AccountUserRole();
     $account = new Account();
     $organization = new Organization();
     $this->assertEmpty($role->getId());
     $this->assertEmpty($role->getLabel());
     $this->assertEmpty($role->getRole());
     $this->assertEmpty($role->getOrganization());
     $this->assertEmpty($role->getAccount());
     $role->setAccount($account);
     $role->setOrganization($organization);
     $this->assertEquals($organization, $role->getOrganization());
     $this->assertEquals($account, $role->getAccount());
     $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);
 }
 /**
  * @Route("/delete/{id}", requirements={"id"="\d+"})
  * @ApiDoc(
  *      description="Delete account user role",
  *      resource=true
  * )
  * @Acl(
  *      id="orob2b_account_frontend_account_user_role_delete_action",
  *      type="entity",
  *      class="OroB2BAccountBundle:AccountUserRole",
  *      permission="FRONTEND_ACCOUNT_ROLE_DELETE",
  *      group_name="commerce"
  * )
  *
  * @param AccountUserRole $id
  * @return Response
  */
 public function deleteAction(AccountUserRole $id)
 {
     return $this->handleDeleteRequest($id->getId());
 }