/** * @param int $integrationId * @param string[] $initialResources * @param string[] $newResources * @magentoDbIsolation enabled * @dataProvider changePermissionsProvider */ public function testChangePermissions($integrationId, $initialResources, $newResources) { $this->_service->grantPermissions($integrationId, $initialResources); /** Preconditions check */ $this->_ensurePermissionsAreGranted($integrationId, $initialResources); $this->_ensurePermissionsAreNotGranted($integrationId, $newResources); $this->_service->grantPermissions($integrationId, $newResources); /** Check the results of permissions change */ $this->_ensurePermissionsAreGranted($integrationId, $newResources); $this->_ensurePermissionsAreNotGranted($integrationId, $initialResources); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Error happened while granting permissions. Check exception log for details. */ public function testGrantPermissionsException() { $this->resources = ['Magento_Sales::sales', 'Magento_Sales::sales_operations', 'Magento_Cart::cart', 'Magento_Cart::manage']; $this->roleMock->expects($this->any())->method('getId')->will($this->returnValue(self::ROLE_ID)); $this->rulesMock->expects($this->any())->method('setRoleId')->with(self::ROLE_ID)->will($this->returnSelf()); $this->rulesMock->expects($this->any())->method('setResources')->with($this->resources)->will($this->returnSelf()); $this->rulesMock->expects($this->any())->method('saveRel')->will($this->throwException(new \Exception())); $this->integrationAuthorizationService->grantPermissions(self::INTEGRATION_ID, $this->resources); }