Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EmulatedAdminhtmlAreaProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
12 use PHPUnit_Framework_MockObject_MockObject as MockObject;
13 
14 class EmulatedAdminhtmlAreaProcessorTest extends \PHPUnit\Framework\TestCase
15 {
21  private $scopeMock;
22 
28  private $stateMock;
29 
35  private $emulatedAdminhtmlProcessorArea;
36 
37  protected function setUp()
38  {
39  $this->scopeMock = $this->getMockBuilder(ScopeInterface::class)
40  ->getMockForAbstractClass();
41  $this->stateMock = $this->getMockBuilder(State::class)
42  ->disableOriginalConstructor()
43  ->setMethods(['emulateAreaCode'])
44  ->getMock();
45 
46  $this->emulatedAdminhtmlProcessorArea = new EmulatedAdminhtmlAreaProcessor(
47  $this->scopeMock,
48  $this->stateMock
49  );
50  }
51 
52  public function testProcess()
53  {
54  $currentScope = 'currentScope';
55  $callback = function () {
56  };
57  $this->scopeMock->expects($this->once())
58  ->method('getCurrentScope')
59  ->willReturn($currentScope);
60 
61  $this->scopeMock->expects($this->once())
62  ->method('setCurrentScope')
63  ->with($currentScope);
64 
65  $this->stateMock->expects($this->once())
66  ->method('emulateAreaCode')
67  ->with(Area::AREA_ADMINHTML, $callback)
68  ->willReturn('result');
69 
70  $this->assertEquals('result', $this->emulatedAdminhtmlProcessorArea->process($callback));
71  }
72 
77  public function testProcessWithException()
78  {
79  $currentScope = 'currentScope';
80  $this->scopeMock->expects($this->once())
81  ->method('getCurrentScope')
82  ->willReturn($currentScope);
83 
84  $this->scopeMock->expects($this->once())
85  ->method('setCurrentScope')
86  ->with($currentScope);
87 
88  $this->stateMock->expects($this->once())
89  ->method('emulateAreaCode')
90  ->willThrowException(new \Exception('Some Message'));
91 
92  $this->emulatedAdminhtmlProcessorArea->process(function () {
93  });
94  }
95 }