PlaceholderTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Migration\Handler;
  7. class PlaceholderTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @return void
  11. */
  12. public function testHandle()
  13. {
  14. $classMapData = ['catalog/product_widget_new' => \Magento\Catalog\Block\Product\Widget\NewWidget::class];
  15. $content = '<p>hello1 {{widget type="catalog/product_widget_new" display_type="all_products" '
  16. . 'products_count="10" template="catalog/product/widget/new/content/new_grid.phtml"}}</p>'
  17. . '<p>{{widget type="extensions/widget_1" anchor_text="widget1" '
  18. . 'template="extensions/widget/link/link_block.phtml" page_id="3"}}</p>';
  19. $contentConverted = '<p>hello1 {{widget type="Magento\\\\Catalog\\\\Block\\\\Product\\\\Widget\\\\NewWidget"'
  20. .' display_type="all_products" products_count="10" template="product/widget/new/content/new_grid.phtml"}}'
  21. . '</p><p></p>';
  22. $fieldName = 'fieldname';
  23. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $record */
  24. $record = $this->createPartialMock(
  25. \Migration\ResourceModel\Record::class,
  26. ['getValue', 'setValue', 'getFields']
  27. );
  28. $record->expects($this->once())->method('getValue')->with($fieldName)->willReturn($content);
  29. $record->expects($this->once())->method('setValue')->with($fieldName, $contentConverted);
  30. $record->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
  31. $classMap = $this->createPartialMock(
  32. \Migration\Reader\ClassMap::class,
  33. ['getMap']
  34. );
  35. $classMap->expects($this->once())->method('getMap')->willReturn($classMapData);
  36. $record2 = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  37. ->disableOriginalConstructor()
  38. ->getMock();
  39. $handler = new \Migration\Handler\Placeholder($classMap);
  40. $handler->setField($fieldName);
  41. $handler->handle($record, $record2);
  42. }
  43. }