PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 204 lines | 109 code | 23 blank | 72 comment | 16 complexity | 4213b2617e7a24e868c9c6b9097b6f8c MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Catalog\Test\Constraint;
  7. use Magento\Catalog\Test\Page\Product\CatalogProductView;
  8. use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct;
  9. use Magento\Mtf\Client\BrowserInterface;
  10. use Magento\Mtf\Constraint\AbstractAssertForm;
  11. use Magento\Mtf\Fixture\FixtureInterface;
  12. /**
  13. * Class AssertProductPage
  14. * Assert that displayed product data on product page(front-end) equals passed from fixture.
  15. */
  16. class AssertProductPage extends AbstractAssertForm
  17. {
  18. /**
  19. * Product view block on frontend page
  20. *
  21. * @var \Magento\ConfigurableProduct\Test\Block\Product\View
  22. */
  23. protected $productView;
  24. /**
  25. * Product fixture
  26. *
  27. * @var ConfigurableProduct
  28. */
  29. protected $product;
  30. /**
  31. * Assert that displayed product data on product page(front-end) equals passed from fixture:
  32. * 1. Product Name
  33. * 2. Price
  34. * 3. Special price
  35. * 4. SKU
  36. * 5. Description
  37. * 6. Short Description
  38. *
  39. * @param BrowserInterface $browser
  40. * @param CatalogProductView $catalogProductView
  41. * @param FixtureInterface $product
  42. * @return void
  43. */
  44. public function processAssert(
  45. BrowserInterface $browser,
  46. CatalogProductView $catalogProductView,
  47. FixtureInterface $product
  48. ) {
  49. $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
  50. $this->product = $product;
  51. $this->productView = $catalogProductView->getViewBlock();
  52. $errors = $this->verify();
  53. \PHPUnit_Framework_Assert::assertEmpty(
  54. $errors,
  55. "\nFound the following errors:\n" . implode(" \n", $errors)
  56. );
  57. }
  58. /**
  59. * Verify displayed product data on product page(front-end) equals passed from fixture
  60. *
  61. * @return array
  62. */
  63. protected function verify()
  64. {
  65. $errors = [];
  66. $errors[] = $this->verifyName();
  67. $errors[] = $this->verifyPrice();
  68. $errors[] = $this->verifySpecialPrice();
  69. $errors[] = $this->verifySku();
  70. $errors[] = $this->verifyDescription();
  71. $errors[] = $this->verifyShortDescription();
  72. return array_filter($errors);
  73. }
  74. /**
  75. * Verify displayed product name on product page(front-end) equals passed from fixture
  76. *
  77. * @return string|null
  78. */
  79. protected function verifyName()
  80. {
  81. $fixtureProductName = $this->product->getName();
  82. $formProductName = $this->productView->getProductName();
  83. if ($fixtureProductName == $formProductName) {
  84. return null;
  85. }
  86. return "Displayed product name on product page(front-end) not equals passed from fixture. "
  87. . "Actual: {$formProductName}, expected: {$fixtureProductName}.";
  88. }
  89. /**
  90. * Verify displayed product price on product page(front-end) equals passed from fixture
  91. *
  92. * @return string|null
  93. */
  94. protected function verifyPrice()
  95. {
  96. if ($this->product->hasData('price') == false) {
  97. return null;
  98. }
  99. $priceBlock = $this->productView->getPriceBlock();
  100. $formPrice = $priceBlock->isOldPriceVisible() ? $priceBlock->getOldPrice() : $priceBlock->getPrice();
  101. $fixturePrice = number_format($this->product->getPrice(), 2, '.', '');
  102. if ($fixturePrice != $formPrice) {
  103. return "Displayed product price on product page(front-end) not equals passed from fixture. "
  104. . "Actual: {$fixturePrice}, expected: {$formPrice}.";
  105. }
  106. return null;
  107. }
  108. /**
  109. * Verify displayed product special price on product page(front-end) equals passed from fixture
  110. *
  111. * @return string|null
  112. */
  113. protected function verifySpecialPrice()
  114. {
  115. if (!$this->product->hasData('special_price')) {
  116. return null;
  117. }
  118. $fixtureProductSpecialPrice = $this->product->getSpecialPrice();
  119. $fixtureProductSpecialPrice = number_format($fixtureProductSpecialPrice, 2);
  120. $formProductSpecialPrice = $this->productView->getPriceBlock()->getSpecialPrice();
  121. if ($fixtureProductSpecialPrice == $formProductSpecialPrice) {
  122. return null;
  123. }
  124. return "Displayed product special price on product page(front-end) not equals passed from fixture. "
  125. . "Actual: {$formProductSpecialPrice}, expected: {$fixtureProductSpecialPrice}.";
  126. }
  127. /**
  128. * Verify displayed product sku on product page(front-end) equals passed from fixture
  129. *
  130. * @return string|null
  131. */
  132. protected function verifySku()
  133. {
  134. $fixtureProductSku = $this->product->getSku();
  135. $formProductSku = $this->productView->getProductSku();
  136. if ($fixtureProductSku === null || $fixtureProductSku == $formProductSku) {
  137. return null;
  138. }
  139. return "Displayed product sku on product page(front-end) not equals passed from fixture. "
  140. . "Actual: {$formProductSku}, expected: {$fixtureProductSku}.";
  141. }
  142. /**
  143. * Verify displayed product description on product page(front-end) equals passed from fixture
  144. *
  145. * @return string|null
  146. */
  147. protected function verifyDescription()
  148. {
  149. $fixtureProductDescription = $this->product->getDescription();
  150. $formProductDescription = $this->productView->getProductDescription();
  151. if ($fixtureProductDescription == $formProductDescription) {
  152. return null;
  153. }
  154. return "Displayed product description on product page(front-end) not equals passed from fixture. "
  155. . "Actual: {$formProductDescription}, expected: {$fixtureProductDescription}.";
  156. }
  157. /**
  158. * Verify displayed product short description on product page(front-end) equals passed from fixture
  159. *
  160. * @return string|null
  161. */
  162. protected function verifyShortDescription()
  163. {
  164. $fixtureProductShortDescription = $this->product->getShortDescription();
  165. $formProductShortDescription = $this->productView->getProductShortDescription();
  166. if ($fixtureProductShortDescription == $formProductShortDescription) {
  167. return null;
  168. }
  169. return "Displayed product short description on product page(front-end) not equals passed from fixture. "
  170. . "Actual: {$formProductShortDescription}, expected: {$fixtureProductShortDescription}.";
  171. }
  172. /**
  173. * Returns a string representation of the object
  174. *
  175. * @return string
  176. */
  177. public function toString()
  178. {
  179. return 'Product on product view page is correct.';
  180. }
  181. }