AccessValidatorTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Test\Unit\Model;
  7. class AccessValidatorTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\AsynchronousOperations\Model\AccessValidator
  11. */
  12. private $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. private $userContextMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $entityManagerMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $bulkSummaryFactoryMock;
  25. protected function setUp()
  26. {
  27. $this->userContextMock = $this->createMock(\Magento\Authorization\Model\UserContextInterface::class);
  28. $this->entityManagerMock = $this->createMock(\Magento\Framework\EntityManager\EntityManager::class);
  29. $this->bulkSummaryFactoryMock = $this->createPartialMock(
  30. \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory::class,
  31. ['create']
  32. );
  33. $this->model = new \Magento\AsynchronousOperations\Model\AccessValidator(
  34. $this->userContextMock,
  35. $this->entityManagerMock,
  36. $this->bulkSummaryFactoryMock
  37. );
  38. }
  39. /**
  40. * @dataProvider summaryDataProvider
  41. * @param string $bulkUserId
  42. * @param bool $expectedResult
  43. */
  44. public function testIsAllowed($bulkUserId, $expectedResult)
  45. {
  46. $adminId = 1;
  47. $uuid = 'test-001';
  48. $bulkSummaryMock = $this->createMock(\Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface::class);
  49. $this->bulkSummaryFactoryMock->expects($this->once())->method('create')->willReturn($bulkSummaryMock);
  50. $this->entityManagerMock->expects($this->once())
  51. ->method('load')
  52. ->with($bulkSummaryMock, $uuid)
  53. ->willReturn($bulkSummaryMock);
  54. $bulkSummaryMock->expects($this->once())->method('getUserId')->willReturn($bulkUserId);
  55. $this->userContextMock->expects($this->once())->method('getUserId')->willReturn($adminId);
  56. $this->assertEquals($this->model->isAllowed($uuid), $expectedResult);
  57. }
  58. /**
  59. * @return array
  60. */
  61. public static function summaryDataProvider()
  62. {
  63. return [
  64. [2, false],
  65. [1, true]
  66. ];
  67. }
  68. }