BlockTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Cms\Test\Unit\Model\Config\Source;
  8. /**
  9. * Class BlockTest
  10. */
  11. class BlockTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Cms\Model\ResourceModel\Block\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $collectionFactory;
  17. /**
  18. * @var \Magento\Cms\Model\Config\Source\Block
  19. */
  20. protected $block;
  21. /**
  22. * Set up
  23. *
  24. * @return void
  25. */
  26. protected function setUp()
  27. {
  28. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  29. $this->collectionFactory = $this->createPartialMock(
  30. \Magento\Cms\Model\ResourceModel\Block\CollectionFactory::class,
  31. ['create']
  32. );
  33. $this->block = $objectManager->getObject(
  34. \Magento\Cms\Model\Config\Source\Block::class,
  35. [
  36. 'collectionFactory' => $this->collectionFactory,
  37. ]
  38. );
  39. }
  40. /**
  41. * Run test toOptionArray method
  42. *
  43. * @return void
  44. */
  45. public function testToOptionArray()
  46. {
  47. $blockCollectionMock = $this->createMock(\Magento\Cms\Model\ResourceModel\Block\Collection::class);
  48. $this->collectionFactory->expects($this->once())
  49. ->method('create')
  50. ->will($this->returnValue($blockCollectionMock));
  51. $blockCollectionMock->expects($this->once())
  52. ->method('toOptionIdArray')
  53. ->will($this->returnValue('return-value'));
  54. $this->assertEquals('return-value', $this->block->toOptionArray());
  55. }
  56. }