|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Cms\Test\Unit\Model\Config\Source; |
| 7 | + |
| 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 | + /** |
| 19 | + * @var \Magento\Cms\Model\Config\Source\Block |
| 20 | + */ |
| 21 | + protected $block; |
| 22 | + |
| 23 | + /** |
| 24 | + * Set up |
| 25 | + * |
| 26 | + * @return void |
| 27 | + */ |
| 28 | + protected function setUp() |
| 29 | + { |
| 30 | + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 31 | + |
| 32 | + $this->collectionFactory = $this->createPartialMock( |
| 33 | + \Magento\Cms\Model\ResourceModel\Block\CollectionFactory::class, |
| 34 | + ['create'] |
| 35 | + ); |
| 36 | + |
| 37 | + $this->block = $objectManager->getObject( |
| 38 | + \Magento\Cms\Model\Config\Source\Block::class, |
| 39 | + [ |
| 40 | + 'collectionFactory' => $this->collectionFactory, |
| 41 | + ] |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Run test toOptionArray method |
| 47 | + * |
| 48 | + * @return void |
| 49 | + */ |
| 50 | + public function testToOptionArray() |
| 51 | + { |
| 52 | + $blockCollectionMock = $this->createMock(\Magento\Cms\Model\ResourceModel\Block\Collection::class); |
| 53 | + |
| 54 | + $this->collectionFactory->expects($this->once()) |
| 55 | + ->method('create') |
| 56 | + ->will($this->returnValue($blockCollectionMock)); |
| 57 | + |
| 58 | + $blockCollectionMock->expects($this->once()) |
| 59 | + ->method('toOptionIdArray') |
| 60 | + ->will($this->returnValue('return-value')); |
| 61 | + |
| 62 | + $this->assertEquals('return-value', $this->block->toOptionArray()); |
| 63 | + } |
| 64 | +} |
0 commit comments