1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test class for \Magento\Payment\Block\Form\Container
*/
namespace Magento\Payment\Test\Unit\Block\Form;
class ContainerTest extends \PHPUnit\Framework\TestCase
{
/**
* @covers \Magento\Payment\Block\Form\Container::getChildBlock
*/
public function testSetMethodFormTemplate()
{
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$childBlockA = $objectManagerHelper->getObject(\Magento\Framework\View\Element\Template::class);
$childBlockB = $objectManagerHelper->getObject(\Magento\Framework\View\Element\Template::class);
$func = function ($blockName) use ($childBlockA, $childBlockB) {
switch ($blockName) {
case 'payment.method.a':
return $childBlockA;
case 'payment.method.b':
return $childBlockB;
}
return null;
};
$block = $this->createPartialMock(\Magento\Payment\Block\Form\Container::class, ['getChildBlock']);
$block->expects($this->atLeastOnce())->method('getChildBlock')->will($this->returnCallback($func));
$template = 'any_template.phtml';
$this->assertNotEquals($template, $childBlockA->getTemplate());
$this->assertNotEquals($template, $childBlockB->getTemplate());
$block->setMethodFormTemplate('a', $template);
$this->assertEquals($template, $childBlockA->getTemplate()); // Template is set to the block
$this->assertNotEquals($template, $childBlockB->getTemplate()); // Template is not propagated to other blocks
}
}