Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BackendAuthenticationTest.php
Go to the documentation of this file.
1 <?php
7 
8 class BackendAuthenticationTest extends \PHPUnit\Framework\TestCase
9 {
10  public function testAroundDispatch()
11  {
13  $subject = $this->createMock(\Magento\Backend\App\AbstractAction::class);
14 
16  $response = $this->createMock(\Magento\Framework\App\ResponseInterface::class);
17 
18  $proceed = function () use ($response) {
19  return $response;
20  };
21 
23  $request = $this->createMock(\Magento\Framework\App\Request\Http::class);
24  $request->expects($this->atLeastOnce())->method('getControllerName')->will($this->returnValue('feed'));
25  $request->expects($this->atLeastOnce())->method('getActionName')->will($this->returnValue('index'));
26  $request->expects($this->once())->method('getParam')->with('type')->will($this->returnValue('notifystock'));
27 
29  $session = $this->createMock(\Magento\Backend\Model\Auth\StorageInterface::class);
30  $session->expects($this->at(0))->method('isLoggedIn')->will($this->returnValue(false));
31  $session->expects($this->at(1))->method('isLoggedIn')->will($this->returnValue(true));
32 
33  $username = 'admin';
34  $password = '123123qa';
35  $auth = $this->createMock(\Magento\Backend\Model\Auth::class);
36  $auth->expects($this->once())->method('getAuthStorage')->will($this->returnValue($session));
37  $auth->expects($this->once())->method('login')->with($username, $password);
38 
40  $httpAuthentication = $this->createMock(\Magento\Framework\HTTP\Authentication::class);
41  $httpAuthentication->expects($this->once())->method('getCredentials')
42  ->will($this->returnValue([$username, $password]));
43  $httpAuthentication->expects($this->once())->method('setAuthenticationFailed')->with('RSS Feeds');
44 
45  $authorization = $this->createMock(\Magento\Framework\AuthorizationInterface::class);
46  $authorization->expects($this->at(0))->method('isAllowed')->with('Magento_Rss::rss')
47  ->will($this->returnValue(true));
48  $authorization->expects($this->at(1))->method('isAllowed')->with('Magento_Catalog::catalog_inventory')
49  ->will($this->returnValue(false));
50 
51  $aclResources = [
52  'feed' => 'Magento_Rss::rss',
53  'notifystock' => 'Magento_Catalog::catalog_inventory',
54  'new_order' => 'Magento_Sales::actions_view',
55  'review' => 'Magento_Reports::review_product'
56  ];
57 
59  $plugin = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
60  ->getObject(
61  \Magento\Rss\App\Action\Plugin\BackendAuthentication::class,
62  [
63  'auth' => $auth,
64  'httpAuthentication' => $httpAuthentication,
65  'response' => $response,
66  'authorization' => $authorization,
67  'aclResources' => $aclResources
68  ]
69  );
70  $this->assertSame(
71  $response,
72  $plugin->aroundDispatch($subject, $proceed, $request)
73  );
74  }
75 }
$response
Definition: 404.php:11