PageRenderTime 102ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/Grid/Renderer/ItemTest.php

https://gitlab.com/crazybutterfly815/magento2
PHP | 155 lines | 131 code | 15 blank | 9 comment | 4 complexity | a891219593dc6370ecdcb86d631c3357 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Block\Adminhtml\Edit\Tab\View\Grid\Renderer;
  7. class ItemTest extends \PHPUnit_Framework_TestCase
  8. {
  9. /** @var \PHPUnit_Framework_MockObject_MockObject */
  10. protected $item;
  11. /** @var \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer\Item */
  12. protected $itemBlock;
  13. public function configure($amountOption, $withoutOptions = false)
  14. {
  15. $options = [];
  16. for ($i = 1; $i <= $amountOption; $i++) {
  17. $options[] = [
  18. 'label' => "testLabel{$i}",
  19. 'value' => ['1 x Configurable Product 49-option 3 <span class="price">$10.00</span>']
  20. ];
  21. }
  22. $product = $this->getMock(\Magento\Catalog\Model\Product::class, ['getTypeId', 'getName'], [], '', false);
  23. $product
  24. ->expects($this->once())
  25. ->method('getTypeId')
  26. ->will($this->returnValue(null));
  27. $product
  28. ->expects($this->once())
  29. ->method('getName')
  30. ->will($this->returnValue('testProductName'));
  31. $this->item = $this->getMock(\Magento\Wishlist\Model\Item::class, ['getProduct'], [], '', false);
  32. $this->item
  33. ->expects($this->atLeastOnce())
  34. ->method('getProduct')
  35. ->will($this->returnValue($product));
  36. $productConfig = $this->getMock(\Magento\Catalog\Helper\Product\Configuration::class, null, [], '', false);
  37. $productConfigPool = $this->getMock(
  38. \Magento\Catalog\Helper\Product\ConfigurationPool::class,
  39. ['get'],
  40. [],
  41. '',
  42. false
  43. );
  44. $helper = $this->getMock(
  45. \Magento\Bundle\Helper\Catalog\Product\Configuration::class,
  46. ['getOptions'],
  47. [],
  48. '',
  49. false
  50. );
  51. $escaper = $this->getMock(\Magento\Framework\Escaper::class, ['escapeHtml'], [], '', false);
  52. if ($withoutOptions) {
  53. $helper
  54. ->expects($this->once())
  55. ->method('getOptions')
  56. ->will($this->returnValue(null));
  57. $escaper
  58. ->expects($this->once())
  59. ->method('escapeHtml')
  60. ->with('testProductName')
  61. ->will($this->returnValue('testProductName'));
  62. } else {
  63. $helper
  64. ->expects($this->once())
  65. ->method('getOptions')
  66. ->will($this->returnValue($options));
  67. $escaper
  68. ->expects($this->at(0))
  69. ->method('escapeHtml')
  70. ->with('testProductName')
  71. ->will($this->returnValue('testProductName'));
  72. for ($i = 1; $i <= count($options); $i++) {
  73. $escaper
  74. ->expects($this->at($i))
  75. ->method('escapeHtml')
  76. ->will($this->returnValue("testLabel{$i}"));
  77. }
  78. }
  79. $context = $this->getMock(\Magento\Backend\Block\Context::class, ['getEscaper'], [], '', false);
  80. $context
  81. ->expects($this->once())
  82. ->method('getEscaper')
  83. ->will($this->returnValue($escaper));
  84. $productConfigPool
  85. ->expects($this->once())
  86. ->method('get')
  87. ->with(\Magento\Catalog\Helper\Product\Configuration::class)
  88. ->will($this->returnValue($helper));
  89. $this->itemBlock = new \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer\Item(
  90. $context,
  91. $productConfig,
  92. $productConfigPool
  93. );
  94. }
  95. public function testRenderWithoutOptions()
  96. {
  97. $this->configure(0, true);
  98. $this->itemBlock->render($this->item);
  99. }
  100. /**
  101. * @dataProvider optionHtmlProvider
  102. */
  103. public function testRender($amountOption, $expectedHtml)
  104. {
  105. $this->configure($amountOption);
  106. $realHtml = '<xhtml>' . $this->itemBlock->render($this->item) . '</xhtml>';
  107. $this->assertXmlStringEqualsXmlString($expectedHtml, $realHtml);
  108. }
  109. public function optionHtmlProvider()
  110. {
  111. return [
  112. [
  113. 2,
  114. <<<HTML
  115. <xhtml>
  116. <div class="product-title">testProductName</div>
  117. <dl class="item-options">
  118. <dt>testLabel1</dt>
  119. <dd>1 x Configurable Product 49-option 3 <span class="price">$10.00</span></dd>
  120. <dt>testLabel2</dt>
  121. <dd>1 x Configurable Product 49-option 3 <span class="price">$10.00</span></dd>
  122. </dl>
  123. </xhtml>
  124. HTML
  125. ],
  126. [
  127. 1,
  128. <<<HTML
  129. <xhtml>
  130. <div class="product-title">testProductName</div>
  131. <dl class="item-options">
  132. <dt>testLabel1</dt>
  133. <dd>1 x Configurable Product 49-option 3 <span class="price">$10.00</span></dd>
  134. </dl>
  135. </xhtml>
  136. HTML
  137. ],
  138. ];
  139. }
  140. }