public function testInvalidScopeNoSuchEntityException()
 {
     $scope = 'websites';
     $scopeId = 1;
     $this->scopeResolverPool->expects($this->once())->method('get')->with($scope)->willThrowException(new NoSuchEntityException(new Phrase('no such entity exception')));
     $this->assertFalse($this->model->isValidScope($scope, $scopeId));
 }
Beispiel #2
0
 /**
  * Return array of scope names
  *
  * @return array
  */
 public function toOptionArray()
 {
     $scopes = $this->scopeResolverPool->get($this->scope)->getScopes();
     $array = [];
     foreach ($scopes as $scope) {
         $array[] = ['value' => $scope->getId(), 'label' => $scope->getName()];
     }
     return $array;
 }
 /**
  * Retrieve scope title
  *
  * @return string
  */
 protected function getScopeTitle()
 {
     $scope = $this->getRequest()->getParam('scope');
     $scopeId = $this->getRequest()->getParam('scope_id');
     if ($scope != ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
         $scopeResolver = $this->scopeResolverPool->get($scope);
         $scopeObject = $scopeResolver->getScope($scopeId);
         return __('%1', $scopeObject->getName());
     }
     return __('Global');
 }
 public function testGetScopeTitle()
 {
     $scope = 'websites';
     $scopeId = 1;
     $scopeTypeName = 'Website';
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $scopeObject = $this->getMockBuilder('Magento\\Framework\\App\\ScopeInterface')->getMockForAbstractClass();
     $scopeObject->expects($this->once())->method('getScopeTypeName')->willReturn($scopeTypeName);
     $scopeResolver = $this->getMockBuilder('Magento\\Framework\\App\\ScopeResolverInterface')->getMockForAbstractClass();
     $scopeResolver->expects($this->once())->method('getScope')->with($scopeId)->willReturn($scopeObject);
     $this->scopeResolverPool->expects($this->once())->method('get')->with($scope)->willReturn($scopeResolver);
     $this->assertEquals(__('%1', $scopeTypeName), $this->block->getScopeTitle());
 }
Beispiel #5
0
 public function testToOptionArray()
 {
     $scopeId = 1;
     $scopeName = 'Scope Name';
     $scopeData = ['value' => $scopeId, 'label' => $scopeName];
     $result = [$scopeData, $scopeData];
     /** @var ScopeResolverInterface|\PHPUnit_Framework_MockObject_MockObject $scopeResolverMock */
     $scopeResolverMock = $this->getMockBuilder('Magento\\Framework\\App\\ScopeResolverInterface')->getMockForAbstractClass();
     /** @var ScopeInterface|\PHPUnit_Framework_MockObject_MockObject $scopeMock */
     $scopeMock = $this->getMockBuilder('Magento\\Framework\\App\\ScopeInterface')->getMockForAbstractClass();
     $this->scopeResolverPoolMock->expects($this->once())->method('get')->with($this->scope)->willReturn($scopeResolverMock);
     $scopeResolverMock->expects($this->once())->method('getScopes')->willReturn([$scopeMock, $scopeMock]);
     $scopeMock->expects($this->exactly(2))->method('getId')->willReturn($scopeId);
     $scopeMock->expects($this->exactly(2))->method('getName')->willReturn($scopeName);
     $this->assertEquals($result, $this->model->toOptionArray());
 }
 /**
  * @inheritDoc
  */
 public function isValidScope($scope, $scopeId = null)
 {
     if ($scope == ScopeConfigInterface::SCOPE_TYPE_DEFAULT && !$scopeId) {
         return true;
     }
     try {
         $scopeResolver = $this->scopeResolverPool->get($scope);
         if (!$scopeResolver->getScope($scopeId)->getId()) {
             return false;
         }
     } catch (\InvalidArgumentException $e) {
         return false;
     } catch (NoSuchEntityException $e) {
         return false;
     }
     return true;
 }
 /**
  * Retrieve scope code value
  *
  * @param string $scopeType
  * @param string|\Magento\Framework\DataObject|null $scopeCode
  * @return string
  */
 protected function _getScopeCode($scopeType, $scopeCode)
 {
     if (($scopeCode === null || is_numeric($scopeCode)) && $scopeType !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
         $scopeResolver = $this->_scopeResolverPool->get($scopeType);
         $scopeCode = $scopeResolver->getScope($scopeCode);
     }
     if ($scopeCode instanceof \Magento\Framework\App\ScopeInterface) {
         $scopeCode = $scopeCode->getCode();
     }
     return $scopeCode;
 }
 public function testScope()
 {
     $scope = 'websites';
     $scopeId = 1;
     $scopeName = 'Website Name';
     $this->request->expects($this->exactly(4))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->scopeValidator->expects($this->once())->method('isValidScope')->with($scope, $scopeId)->willReturn(true);
     $pageTitle = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
     $pageTitle->expects($this->once())->method('prepend')->with(__('%1', $scopeName))->willReturnSelf();
     $pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
     $pageConfig->expects($this->once())->method('getTitle')->willReturn($pageTitle);
     $scopeObject = $this->getMockBuilder('Magento\\Framework\\App\\ScopeInterface')->getMockForAbstractClass();
     $scopeObject->expects($this->once())->method('getName')->willReturn($scopeName);
     $scopeResolver = $this->getMockBuilder('Magento\\Framework\\App\\ScopeResolverInterface')->getMockForAbstractClass();
     $scopeResolver->expects($this->once())->method('getScope')->with($scopeId)->willReturn($scopeObject);
     $this->scopeResolverPool->expects($this->once())->method('get')->with($scope)->willReturn($scopeResolver);
     $this->resultPage->expects($this->once())->method('setActiveMenu')->with('Magento_Theme::design_config')->willReturnSelf();
     $this->resultPage->expects($this->once())->method('getConfig')->willReturn($pageConfig);
     $this->assertSame($this->resultPage, $this->controller->execute());
 }