Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ScopeValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class ScopeValidatorTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
23  protected $scopeResolverPool;
24 
25  protected function setUp()
26  {
27  $this->scopeResolverPool = $this->getMockBuilder(\Magento\Framework\App\ScopeResolverPool::class)
28  ->disableOriginalConstructor()
29  ->getMock();
30 
31  $this->model = new ScopeValidator(
32  $this->scopeResolverPool
33  );
34  }
35 
36  public function testScopeDefault()
37  {
38  $scope = 'default';
39  $scopeId = 0;
40 
41  $this->assertTrue($this->model->isValidScope($scope, $scopeId));
42  }
43 
44  public function testInvalidScope()
45  {
46  $scope = 'websites';
47  $scopeId = 1;
48 
49  $scopeObject = $this->getMockBuilder(\Magento\Framework\App\ScopeInterface::class)
50  ->getMockForAbstractClass();
51  $scopeObject->expects($this->once())
52  ->method('getId')
53  ->willReturn(false);
54 
55  $scopeResolver = $this->getMockBuilder(\Magento\Framework\App\ScopeResolverInterface::class)
56  ->getMockForAbstractClass();
57  $scopeResolver->expects($this->once())
58  ->method('getScope')
59  ->with($scopeId)
60  ->willReturn($scopeObject);
61 
62  $this->scopeResolverPool->expects($this->once())
63  ->method('get')
64  ->with($scope)
65  ->willReturn($scopeResolver);
66 
67  $this->assertFalse($this->model->isValidScope($scope, $scopeId));
68  }
69 
71  {
72  $scope = 'websites';
73  $scopeId = 1;
74 
75  $this->scopeResolverPool->expects($this->once())
76  ->method('get')
77  ->with($scope)
78  ->willThrowException(new \InvalidArgumentException());
79 
80  $this->assertFalse($this->model->isValidScope($scope, $scopeId));
81  }
82 
84  {
85  $scope = 'websites';
86  $scopeId = 1;
87 
88  $this->scopeResolverPool->expects($this->once())
89  ->method('get')
90  ->with($scope)
91  ->willThrowException(new NoSuchEntityException(new Phrase('no such entity exception')));
92 
93  $this->assertFalse($this->model->isValidScope($scope, $scopeId));
94  }
95 }