Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractReview.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Block\Block;
10 use Magento\Mtf\Client\Locator;
11 use Magento\Mtf\Block\BlockFactory;
12 use Magento\Mtf\Client\BrowserInterface;
13 use Magento\Mtf\Client\Element\SimpleElement;
14 
20 abstract class AbstractReview extends Block
21 {
27  protected $productItemByName = './/li[contains(@class,"product-item") and contains(.,"%s")]';
28 
34  protected $grandTotal = '[class="grand totals"] td>strong';
35 
41  protected $grandTotalExclTax = '.grand.totals.excl .price';
42 
48  protected $grandTotalInclTax = '.grand.totals.incl .price';
49 
55  protected $subtotal = '.totals.sub .price';
56 
62  protected $subtotalExclTax = '.totals.sub.excl .price';
63 
69  protected $subtotalInclTax = '.totals.sub.incl .price';
70 
76  protected $tax = '.totals-tax .price';
77 
83  protected $discount = '.totals.discount .price';
84 
90  protected $shippingExclTax = '.totals.shipping.excl .price';
91 
97  protected $shippingInclTax = '.totals.shipping.incl .price';
98 
104  protected $itemExclTax = '.price-excluding-tax .price';
105 
111  protected $itemInclTax = '.price-including-tax .price';
112 
113  // @codingStandardsIgnoreStart
119  protected $itemSubExclTax = '.subtotal .price-excluding-tax .price';
120 
126  protected $itemSubInclTax = '.subtotal .price-including-tax .price';
127  // @codingStandardsIgnoreEnd
128 
134  protected $waitElement = '.loading-mask';
135 
141  protected $itemsBlock = '.block.items-in-cart > .title';
142 
148  protected $itemsCounterSelector = '.items-in-cart .title';
149 
155  protected $cartItemsContentSelector = '.content.minicart-items';
156 
163  public function __construct(SimpleElement $element, BlockFactory $blockFactory, BrowserInterface $browser)
164  {
165  parent::__construct($element, $blockFactory, $browser);
166  }
167 
173  public function getGrandTotal()
174  {
175  $grandTotal = $this->_rootElement->find($this->grandTotal)->getText();
176  return $this->escapeCurrency($grandTotal);
177  }
178 
185  public function getItemPriceExclTax($productName)
186  {
187  $productItem = $this->_rootElement->find(
188  sprintf($this->productItemByName, $productName),
189  Locator::SELECTOR_XPATH
190  );
191  $price = $productItem->find($this->itemExclTax);
192  return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null;
193  }
194 
201  public function getItemPriceInclTax($productName)
202  {
203  $productItem = $this->_rootElement->find(
204  sprintf($this->productItemByName, $productName),
205  Locator::SELECTOR_XPATH
206  );
207  $price = $productItem->find($this->itemInclTax);
208  return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null;
209  }
210 
217  public function getItemSubExclTax($productName)
218  {
219  $productItem = $this->_rootElement->find(
220  sprintf($this->productItemByName, $productName),
221  Locator::SELECTOR_XPATH
222  );
223  $price = $productItem->find($this->itemSubExclTax);
224  return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null;
225  }
226 
233  public function getItemSubInclTax($productName)
234  {
235  $productItem = $this->_rootElement->find(
236  sprintf($this->productItemByName, $productName),
237  Locator::SELECTOR_XPATH
238  );
239  $price = $productItem->find($this->itemSubInclTax);
240  return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null;
241  }
242 
249  public function getItemElement($productName)
250  {
251  return $this->_rootElement->find(
252  sprintf($this->productItemByName, $productName),
253  Locator::SELECTOR_XPATH
254  );
255  }
256 
262  public function expandItemsBlock()
263  {
264  if (!$this->_rootElement->find($this->cartItemsContentSelector)->isVisible()) {
265  $this->browser->find($this->itemsBlock)->click();
266  }
267  }
268 
274  public function getVisibleItemsCounter()
275  {
276  return $this->_rootElement->find($this->itemsCounterSelector)->getText();
277  }
278 
284  public function getGoToCartLink()
285  {
286  return $this->_rootElement->find('.action.viewcart');
287  }
288 
294  public function getGrandTotalExclTax()
295  {
296  $grandTotal = $this->_rootElement->find($this->grandTotalExclTax)->getText();
297  return $this->escapeCurrency($grandTotal);
298  }
299 
305  public function getGrandTotalInclTax()
306  {
307  $grandTotal = $this->_rootElement->find($this->grandTotalInclTax)->getText();
308  return $this->escapeCurrency($grandTotal);
309  }
310 
316  public function getTax()
317  {
318  $tax = $this->_rootElement->find($this->tax, Locator::SELECTOR_CSS);
319  return $tax->isVisible() ? $this->escapeCurrency($tax->getText()) : null;
320  }
321 
327  public function getDiscount()
328  {
329  $discount = $this->_rootElement->find($this->discount);
330  return $discount->isVisible() ? $this->escapeCurrency($discount->getText()) : null;
331  }
332 
338  public function getSubtotal()
339  {
340  $subTotal = $this->_rootElement->find($this->subtotal)->getText();
341  return $this->escapeCurrency($subTotal);
342  }
343 
349  public function getSubtotalExclTax()
350  {
351  $subTotal = $this->_rootElement->find($this->subtotalExclTax)->getText();
352  return $this->escapeCurrency($subTotal);
353  }
354 
360  public function getSubtotalInclTax()
361  {
362  $subTotal = $this->_rootElement->find($this->subtotalInclTax)->getText();
363  return $this->escapeCurrency($subTotal);
364  }
365 
371  public function getShippingInclTax()
372  {
373  $subTotal = $this->_rootElement->find($this->shippingInclTax);
374  return $subTotal->isVisible() ? $this->escapeCurrency($subTotal->getText()) : null;
375  }
376 
382  public function getShippingExclTax()
383  {
384  $subTotal = $this->_rootElement->find($this->shippingExclTax);
385  return $subTotal->isVisible() ? $this->escapeCurrency($subTotal->getText()) : null;
386  }
387 
394  protected function escapeCurrency($price)
395  {
396  preg_match("/^\\D*\\s*([\\d,\\.]+)\\s*\\D*$/", $price, $matches);
397  return (isset($matches[1])) ? $matches[1] : null;
398  }
399 }
$price
__construct(SimpleElement $element, BlockFactory $blockFactory, BrowserInterface $browser)
$element
Definition: element.phtml:12