PageRenderTime 24ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/dev/tests/functional/tests/app/Mage/Catalog/Test/Block/Product/View.php

https://bitbucket.org/ttphong2612/billigastamplar-new.se
PHP | 400 lines | 150 code | 38 blank | 212 comment | 7 complexity | df6bea774505ee8adef00d082f95edfa MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Tests
  22. * @package Tests_Functional
  23. * @copyright Copyright (c) 2006-2018 Magento, Inc. (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. namespace Mage\Catalog\Test\Block\Product;
  27. use Magento\Mtf\Client\Locator;
  28. use Magento\Mtf\Fixture\InjectableFixture;
  29. use Mage\Catalog\Test\Fixture\CatalogProductSimple;
  30. use Mage\Catalog\Test\Block\AbstractConfigureBlock;
  31. /**
  32. * Product view block on the product page.
  33. *
  34. * @SuppressWarnings(PHPMD.TooManyFields)
  35. * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  36. * @SuppressWarnings(PHPMD.NPathComplexity)
  37. */
  38. class View extends AbstractConfigureBlock
  39. {
  40. /**
  41. * Custom options CSS selector.
  42. *
  43. * @var string
  44. */
  45. protected $customOptionsSelector = '.product-options-wrapper';
  46. /**
  47. * 'Add to Cart' button.
  48. *
  49. * @var string
  50. */
  51. protected $addToCart = '.button.btn-cart';
  52. /**
  53. * Quantity input id.
  54. *
  55. * @var string
  56. */
  57. protected $qty = '#qty';
  58. /**
  59. * Product name element.
  60. *
  61. * @var string
  62. */
  63. protected $productName = 'div.product-name span.h1';
  64. /**
  65. * Product description element.
  66. *
  67. * @var string
  68. */
  69. protected $productDescription = '.tab-content .std';
  70. /**
  71. * Product short-description element.
  72. *
  73. * @var string
  74. */
  75. protected $productShortDescription = '.short-description .std';
  76. /**
  77. * Stock Availability control.
  78. *
  79. * @var string
  80. */
  81. protected $stockAvailability = '.availability span.value';
  82. /**
  83. * Selector for price block.
  84. *
  85. * @var string
  86. */
  87. protected $priceBlock = "//*[@class='price-info']/*[@class='price-box']";
  88. /**
  89. * This member holds the class name of the tier price block.
  90. *
  91. * @var string
  92. */
  93. protected $tierPricesSelector = "//ul[contains(@class,'tier')]/li[%d]";
  94. /**
  95. * "Add to Wishlist" button.
  96. *
  97. * @var string
  98. */
  99. protected $addToWishlist = '.link-wishlist';
  100. /**
  101. * Css selector for 'Update Wishlist' button.
  102. *
  103. * @var string
  104. */
  105. protected $updateWishlist = '[href*="wishlist/index/updateItemOptions"]';
  106. /**
  107. * Messages block locator.
  108. *
  109. * @var string
  110. */
  111. protected $messageBlock = '.messages';
  112. /**
  113. * 'Add to Compare' button.
  114. *
  115. * @var string
  116. */
  117. protected $clickAddToCompare = '.link-compare';
  118. /**
  119. * Selector for custom information tab's title.
  120. *
  121. * @var string
  122. */
  123. protected $customInformationTab = '//ul/li/span[text()="%s"]';
  124. /**
  125. * Get block price.
  126. *
  127. * @return Price
  128. */
  129. public function getPriceBlock()
  130. {
  131. return $this->blockFactory->create(
  132. 'Mage\Catalog\Test\Block\Product\Price',
  133. ['element' => $this->_rootElement->find($this->priceBlock, Locator::SELECTOR_XPATH)]
  134. );
  135. }
  136. /**
  137. * Add product to shopping cart.
  138. *
  139. * @param InjectableFixture $product
  140. * @return void
  141. */
  142. public function addToCart(InjectableFixture $product)
  143. {
  144. $this->configureProduct($product);
  145. $this->clickAddToCart();
  146. }
  147. /**
  148. * Configure product.
  149. *
  150. * @param InjectableFixture $product
  151. * @return void
  152. */
  153. protected function configureProduct(InjectableFixture $product)
  154. {
  155. /** @var CatalogProductSimple $product */
  156. $checkoutData = $product->getCheckoutData();
  157. if (isset($checkoutData['options'])) {
  158. $this->fillOptions($product);
  159. }
  160. if (isset($checkoutData['qty'])) {
  161. $this->setQty($checkoutData['qty']);
  162. }
  163. }
  164. /**
  165. * Fill in the option specified for the product.
  166. *
  167. * @param InjectableFixture $product
  168. * @return void
  169. *
  170. * @SuppressWarnings(PHPMD.NPathComplexity)
  171. */
  172. public function fillOptions(InjectableFixture $product)
  173. {
  174. $dataConfig = $product->getDataConfig();
  175. $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
  176. $checkoutData = null;
  177. /** @var CatalogProductSimple $product */
  178. if ($this->hasRender($typeId)) {
  179. $this->callRender($typeId, 'fillOptions', ['product' => $product]);
  180. }
  181. /** @var CatalogProductSimple $product */
  182. $checkoutData = $product->getCheckoutData();
  183. if (!isset($checkoutData['options']['custom_options'])) {
  184. return;
  185. }
  186. $customOptions = $product->getCustomOptions();
  187. if (isset($customOptions)) {
  188. $checkoutCustomOptions = $this->prepareCheckoutData(
  189. $customOptions,
  190. $checkoutData['options']['custom_options']
  191. );
  192. $this->getCustomOptionsBlock()->fillCustomOptions($checkoutCustomOptions);
  193. }
  194. }
  195. /**
  196. * Return product options.
  197. *
  198. * @param InjectableFixture $product
  199. * @return array
  200. */
  201. public function getOptions(InjectableFixture $product)
  202. {
  203. $dataConfig = $product->getDataConfig();
  204. $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
  205. return $this->hasRender($typeId)
  206. ? $this->callRender($typeId, 'getOptions', ['product' => $product])
  207. : $this->getCustomOptionsBlock()->getOptions($product);
  208. }
  209. /**
  210. * Click add to card button.
  211. *
  212. * @return void
  213. */
  214. public function clickAddToCart()
  215. {
  216. $this->_rootElement->find($this->addToCart)->click();
  217. }
  218. /**
  219. * Check add to card button.
  220. *
  221. * @return bool
  222. */
  223. public function checkAddToCartButton()
  224. {
  225. return $this->_rootElement->find($this->addToCart)->isVisible();
  226. }
  227. /**
  228. * Set quantity.
  229. *
  230. * @param int $qty
  231. * @return void
  232. */
  233. public function setQty($qty)
  234. {
  235. $this->browser->selectWindow();
  236. $this->_rootElement->find($this->qty)->setValue($qty);
  237. $this->_rootElement->click();
  238. }
  239. /**
  240. * Get product name displayed on page.
  241. *
  242. * @return string
  243. */
  244. public function getProductName()
  245. {
  246. return $this->_rootElement->find($this->productName)->getText();
  247. }
  248. /**
  249. * Return product short description on page.
  250. *
  251. * @return string|null
  252. */
  253. public function getProductShortDescription()
  254. {
  255. if ($this->_rootElement->find($this->productShortDescription)->isVisible()) {
  256. return $this->_rootElement->find($this->productShortDescription)->getText();
  257. }
  258. return null;
  259. }
  260. /**
  261. * Return product description on page.
  262. *
  263. * @return string|null
  264. */
  265. public function getProductDescription()
  266. {
  267. if ($this->_rootElement->find($this->productDescription)->isVisible()) {
  268. return $this->_rootElement->find($this->productDescription)->getText();
  269. }
  270. return null;
  271. }
  272. /**
  273. * Get text of Stock Availability control.
  274. *
  275. * @param InjectableFixture $product
  276. * @return string
  277. */
  278. public function getStockAvailability(InjectableFixture $product)
  279. {
  280. $dataConfig = $product->getDataConfig();
  281. $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
  282. return $this->hasRender($typeId)
  283. ? $this->callRender($typeId, 'get' . ucfirst($typeId) . 'StockAvailability')
  284. : strtolower($this->_rootElement->find($this->stockAvailability)->getText());
  285. }
  286. /**
  287. * This method return array tier prices.
  288. *
  289. * @param int $lineNumber [optional]
  290. * @return array
  291. */
  292. public function getTierPrices($lineNumber = 1)
  293. {
  294. return $this->_rootElement->find(sprintf($this->tierPricesSelector, $lineNumber), Locator::SELECTOR_XPATH)
  295. ->getText();
  296. }
  297. /**
  298. * Add product to Wishlist.
  299. *
  300. * @param InjectableFixture $product
  301. * @return void
  302. */
  303. public function addToWishlist(InjectableFixture $product)
  304. {
  305. $this->configureProduct($product);
  306. $this->clickAddToWishlist();
  307. }
  308. /**
  309. * Update product in Wishlist.
  310. *
  311. * @param InjectableFixture $product
  312. * @return void
  313. */
  314. public function updateWishlist(InjectableFixture $product)
  315. {
  316. $this->configureProduct($product);
  317. $this->clickUpdateWishlist();
  318. }
  319. /**
  320. * Click "Add to Wishlist" button.
  321. *
  322. * @return void
  323. */
  324. public function clickAddToWishlist()
  325. {
  326. $this->_rootElement->find($this->addToWishlist)->click();
  327. }
  328. /**
  329. * Click "Update Wishlist" button.
  330. *
  331. * @return void
  332. */
  333. protected function clickUpdateWishlist()
  334. {
  335. $this->_rootElement->find($this->updateWishlist)->click();
  336. }
  337. /**
  338. * Click "Add to Compare" button.
  339. *
  340. * @return void
  341. */
  342. public function clickAddToCompare()
  343. {
  344. /** @var \Mage\Core\Test\Block\Messages $messageBlock */
  345. $messageBlock = $this->blockFactory->create(
  346. 'Mage\Core\Test\Block\Messages',
  347. ['element' => $this->browser->find($this->messageBlock)]
  348. );
  349. $this->_rootElement->find($this->clickAddToCompare, Locator::SELECTOR_CSS)->click();
  350. $messageBlock->waitSuccessMessage();
  351. }
  352. /**
  353. * Open custom information tab.
  354. *
  355. * @param string $tabName
  356. * @return void
  357. */
  358. public function openCustomInformationTab($tabName)
  359. {
  360. $this->_rootElement->find(sprintf($this->customInformationTab, $tabName), Locator::SELECTOR_XPATH)->click();
  361. }
  362. }