コード例 #1
0
 public function testGetByIdentifierNamespace()
 {
     $userId = 1;
     $namespace = 'some_namespace';
     $identifier = 'current';
     $this->userContext->expects($this->once())->method('getUserId')->willReturn($userId);
     $fieldUserId = new Filter([Filter::KEY_FIELD => 'user_id', Filter::KEY_VALUE => $userId, Filter::KEY_CONDITION_TYPE => 'eq']);
     $fieldIdentifier = new Filter([Filter::KEY_FIELD => 'identifier', Filter::KEY_VALUE => $identifier, Filter::KEY_CONDITION_TYPE => 'eq']);
     $fieldNamespace = new Filter([Filter::KEY_FIELD => 'namespace', Filter::KEY_VALUE => $namespace, Filter::KEY_CONDITION_TYPE => 'eq']);
     $bookmarkId = 1;
     $bookmark = $this->getMockBuilder('Magento\\Ui\\Api\\Data\\BookmarkInterface')->getMockForAbstractClass();
     $bookmark->expects($this->once())->method('getId')->willReturn($bookmarkId);
     $searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\SearchCriteriaInterface')->getMockForAbstractClass();
     $this->filterBuilder->expects($this->at(0))->method('create')->willReturn($fieldUserId);
     $this->filterBuilder->expects($this->at(1))->method('create')->willReturn($fieldIdentifier);
     $this->filterBuilder->expects($this->at(2))->method('create')->willReturn($fieldNamespace);
     $this->searchCriteriaBuilder->expects($this->once())->method('addFilters')->with([$fieldUserId, $fieldIdentifier, $fieldNamespace]);
     $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
     $searchResult = $this->getMockBuilder('Magento\\Ui\\Api\\Data\\BookmarkSearchResultsInterface')->getMockForAbstractClass();
     $searchResult->expects($this->once())->method('getTotalCount')->willReturn(1);
     $searchResult->expects($this->once())->method('getItems')->willReturn([$bookmark]);
     $this->bookmarkRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($searchResult);
     $this->bookmarkRepository->expects($this->once())->method('getById')->with($bookmarkId)->willReturn($bookmark);
     $this->assertEquals($bookmark, $this->bookmarkManagement->getByIdentifierNamespace($identifier, $namespace));
 }
コード例 #2
0
 protected function setUp()
 {
     $this->_objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $userId = 'userId';
     $userType = 'userType';
     $this->userContext = $this->getMockBuilder('Magento\\Authorization\\Model\\CompositeUserContext')->disableOriginalConstructor()->setMethods(['getUserId', 'getUserType'])->getMock();
     $this->userContext->expects($this->once())->method('getUserId')->will($this->returnValue($userId));
     $this->userContext->expects($this->once())->method('getUserType')->will($this->returnValue($userType));
     $this->roleCollectionFactory = $this->getMockBuilder('Magento\\Authorization\\Model\\Resource\\Role\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->roleCollection = $this->getMockBuilder('Magento\\Authorization\\Model\\Resource\\Role\\Collection')->disableOriginalConstructor()->setMethods(['setUserFilter', 'getFirstItem'])->getMock();
     $this->roleCollectionFactory->expects($this->once())->method('create')->will($this->returnValue($this->roleCollection));
     $this->roleCollection->expects($this->once())->method('setUserFilter')->with($userId, $userType)->will($this->returnValue($this->roleCollection));
     $this->role = $this->getMockBuilder('Magento\\Authorization\\Model\\Role')->disableOriginalConstructor()->setMethods(['getId', '__wakeup'])->getMock();
     $this->roleCollection->expects($this->once())->method('getFirstItem')->will($this->returnValue($this->role));
     $this->locator = $this->_objectManager->getObject('Magento\\Webapi\\Model\\WebapiRoleLocator', ['userContext' => $this->userContext, 'roleCollectionFactory' => $this->roleCollectionFactory]);
 }
コード例 #3
0
 /**
  * Check if access to the specified resources is prohibited to the user.
  *
  * @param int $integrationId
  * @param string[] $resources
  */
 protected function _ensurePermissionsAreNotGranted($integrationId, $resources)
 {
     $this->userContextMock->expects($this->any())->method('getUserId')->will($this->returnValue($integrationId));
     foreach ($resources as $resource) {
         $this->assertFalse($this->libAuthorization->isAllowed($resource), "Access to resource '{$resource}' is expected to be prohibited.");
     }
 }
コード例 #4
0
 /**
  * @param array $requestData Data from the request
  * @param array $parameters Data from config about which parameters to override
  * @param array $expectedOverriddenParams Result of overriding $requestData when applying rules from $parameters
  * @param int $userId The id of the user invoking the request
  * @param int $userType The type of user invoking the request
  *
  * @dataProvider overrideParmasDataProvider
  */
 public function testOverrideParams($requestData, $parameters, $expectedOverriddenParams, $userId, $userType)
 {
     $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue($parameters));
     $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
     $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue($requestData));
     $this->userContextMock->expects($this->any())->method('getUserId')->will($this->returnValue($userId));
     $this->userContextMock->expects($this->any())->method('getUserType')->will($this->returnValue($userType));
     // serializer should expect overridden params
     $this->serializerMock->expects($this->once())->method('getInputData')->with($this->equalTo('Magento\\Webapi\\Controller\\TestService'), $this->equalTo('testMethod'), $this->equalTo($expectedOverriddenParams));
     $this->_restController->dispatch($this->_requestMock);
 }
コード例 #5
0
 public function testGetOverriddenValueIsNotCustomer()
 {
     $this->userContext->expects($this->once())->method('getUserType')->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN));
     $this->assertNull($this->model->getOverriddenValue());
 }