ContainerTest.php 1.7 KB

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