/**
  * @param string $type
  * @param AccountUser $accountUser
  *
  * @return bool
  */
 public function isAccountUserAddressGranted($type, AccountUser $accountUser = null)
 {
     if ($this->isManualEditGranted($type)) {
         return true;
     }
     $hasPermissions = $this->securityFacade->isGranted($this->getClassPermission('VIEW', $this->accountUserAddressClass)) && $this->securityFacade->isGranted($this->getTypedPermission($type));
     if (!$hasPermissions) {
         return false;
     }
     if (!$accountUser) {
         return false;
     }
     return (bool) $this->orderAddressProvider->getAccountUserAddresses($accountUser, $type);
 }
 /**
  * @dataProvider accountUserAddressPermissions
  * @param string $type
  * @param array $expectedCalledPermissions
  * @param string $calledRepositoryMethod
  * @param array $addresses
  * @param object $loggedUser
  */
 public function testGetAccountUserAddresses($type, array $expectedCalledPermissions, $calledRepositoryMethod, array $addresses, $loggedUser)
 {
     $this->securityFacade->expects($this->any())->method('getLoggedUser')->will($this->returnValue($loggedUser));
     $accountUser = new AccountUser();
     $permissionsValueMap = [];
     foreach ($expectedCalledPermissions as $permission => $decision) {
         $permissionsValueMap[] = [$permission, null, $decision];
     }
     $this->securityFacade->expects($this->exactly(count($expectedCalledPermissions)))->method('isGranted')->will($this->returnValueMap($permissionsValueMap));
     $repository = $this->assertAccountUserAddressRepositoryCall();
     if ($calledRepositoryMethod) {
         $repository->expects($this->once())->method($calledRepositoryMethod)->with($accountUser, $type, $this->aclHelper)->will($this->returnValue($addresses));
     } else {
         $repository->expects($this->never())->method($this->anything());
     }
     $this->assertEquals($addresses, $this->provider->getAccountUserAddresses($accountUser, $type));
     // cache
     $this->assertEquals($addresses, $this->provider->getAccountUserAddresses($accountUser, $type));
 }
 /**
  * @param Order $order
  * @param string $type
  * @return array
  */
 public function getGroupedAddresses(Order $order, $type)
 {
     $addresses = [];
     $account = $order->getAccount();
     if ($account) {
         $accountAddresses = $this->orderAddressProvider->getAccountAddresses($account, $type);
         foreach ($accountAddresses as $accountAddress) {
             $addresses[self::ACCOUNT_LABEL][$this->getIdentifier($accountAddress)] = $accountAddress;
         }
     }
     $accountUser = $order->getAccountUser();
     if ($accountUser) {
         $accountUserAddresses = $this->orderAddressProvider->getAccountUserAddresses($accountUser, $type);
         if ($accountUserAddresses) {
             foreach ($accountUserAddresses as $accountUserAddress) {
                 $addresses[self::ACCOUNT_USER_LABEL][$this->getIdentifier($accountUserAddress)] = $accountUserAddress;
             }
         }
     }
     return $addresses;
 }