OptionsTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\BulkDescription;
  7. class OptionsTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\AsynchronousOperations\Model\BulkDescription\Options
  11. */
  12. private $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. private $bulkCollectionFactoryMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $userContextMock;
  21. protected function setUp()
  22. {
  23. $this->bulkCollectionFactoryMock = $this->createPartialMock(
  24. \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\CollectionFactory::class,
  25. ['create']
  26. );
  27. $this->userContextMock = $this->createMock(\Magento\Authorization\Model\UserContextInterface::class);
  28. $this->model = new \Magento\AsynchronousOperations\Model\BulkDescription\Options(
  29. $this->bulkCollectionFactoryMock,
  30. $this->userContextMock
  31. );
  32. }
  33. public function testToOptionsArray()
  34. {
  35. $userId = 100;
  36. $collectionMock = $this->createMock(\Magento\AsynchronousOperations\Model\ResourceModel\Bulk\Collection::class);
  37. $selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
  38. $this->bulkCollectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
  39. $this->userContextMock->expects($this->once())->method('getUserId')->willReturn($userId);
  40. $collectionMock->expects($this->once())->method('getMainTable')->willReturn('table');
  41. $selectMock->expects($this->once())->method('reset')->willReturnSelf();
  42. $selectMock->expects($this->once())->method('distinct')->with(true)->willReturnSelf();
  43. $selectMock->expects($this->once())->method('from')->with('table', ['description'])->willReturnSelf();
  44. $selectMock->expects($this->once())->method('where')->with('user_id = ?', $userId)->willReturnSelf();
  45. $itemMock = $this->createPartialMock(
  46. \Magento\AsynchronousOperations\Model\BulkSummary::class,
  47. ['getDescription']
  48. );
  49. $itemMock->expects($this->exactly(2))->method('getDescription')->willReturn('description');
  50. $collectionMock->expects($this->once())->method('getSelect')->willReturn($selectMock);
  51. $collectionMock->expects($this->once())->method('getItems')->willReturn([$itemMock]);
  52. $expectedResult = [
  53. [
  54. 'value' => 'description',
  55. 'label' => 'description'
  56. ]
  57. ];
  58. $this->assertEquals($expectedResult, $this->model->toOptionArray());
  59. }
  60. }