Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
ServicesTest.php
Go to the documentation of this file.
1 <?php
7 
8 class ServicesTest extends \PHPUnit\Framework\TestCase
9 {
16 
17  protected function setUp()
18  {
19  $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
20  }
21 
22  protected function tearDown()
23  {
24  unset($this->objectManagerHelper);
25  }
26 
27  public function testPrepareLayout()
28  {
29  $options = [['value' => 'value', 'label' => 'label']];
30  $service = 'service';
31 
32  $sourceServiceFactoryMock = $this->createPartialMock(
33  \Magento\Directory\Model\Currency\Import\Source\ServiceFactory::class,
34  ['create']
35  );
36  $sourceServiceMock = $this->createMock(\Magento\Directory\Model\Currency\Import\Source\Service::class);
37  $backendSessionMock = $this->createPartialMock(
38  \Magento\Backend\Model\Session::class,
39  ['getCurrencyRateService']
40  );
41 
43  $layoutMock = $this->getMockForAbstractClass(
44  \Magento\Framework\View\LayoutInterface::class,
45  [],
46  '',
47  false,
48  false,
49  true,
50  ['createBlock']
51  );
52 
53  $blockMock = $this->createPartialMock(
54  \Magento\Framework\View\Element\Html\Select::class,
55  ['setOptions', 'setId', 'setName', 'setValue', 'setTitle']
56  );
57 
58  $layoutMock->expects($this->once())->method('createBlock')->willReturn($blockMock);
59 
60  $sourceServiceFactoryMock->expects($this->once())->method('create')->willReturn($sourceServiceMock);
61  $sourceServiceMock->expects($this->once())->method('toOptionArray')->willReturn($options);
62  $backendSessionMock->expects($this->once())->method('getCurrencyRateService')->with(true)->willReturn($service);
63 
64  $blockMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf();
65  $blockMock->expects($this->once())->method('setId')->with('rate_services')->willReturnSelf();
66  $blockMock->expects($this->once())->method('setName')->with('rate_services')->willReturnSelf();
67  $blockMock->expects($this->once())->method('setValue')->with($service)->willReturnSelf();
68  $blockMock->expects($this->once())->method('setTitle')->with('Import Service')->willReturnSelf();
69 
71  $block = $this->objectManagerHelper->getObject(
72  \Magento\CurrencySymbol\Block\Adminhtml\System\Currency\Rate\Services::class,
73  [
74  'srcCurrencyFactory' => $sourceServiceFactoryMock,
75  'backendSession' => $backendSessionMock
76  ]
77  );
78  $block->setLayout($layoutMock);
79  }
80 }
$block
Definition: block.php:8