Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DownloadProductsReportEntityTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Customer\Test\Page\CustomerAccountIndex;
10 use Magento\Downloadable\Test\Page\DownloadableCustomerProducts;
11 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Mtf\Fixture\FixtureFactory;
13 use Magento\Mtf\TestCase\Injectable;
15 
32 class DownloadProductsReportEntityTest extends Injectable
33 {
34  /* tags */
35  const MVP = 'no';
36  /* end tags */
37 
43  protected $browser;
44 
50  protected $customerAccount;
51 
57  protected $customerProducts;
58 
64  private $fixtureFactory;
65 
75  public function __inject(
76  FixtureFactory $fixtureFactory,
77  CustomerAccountIndex $customerAccount,
78  DownloadableCustomerProducts $customerProducts,
79  BrowserInterface $browser
80  ) {
81  $this->fixtureFactory = $fixtureFactory;
82  $this->customerAccount = $customerAccount;
83  $this->customerProducts = $customerProducts;
84  $this->browser = $browser;
85  }
86 
94  public function test(OrderInjectable $order, $downloads)
95  {
96  // Preconditions
97  $order->persist();
98  $products = $order->getEntityId()['products'];
99  $cart['data']['items'] = ['products' => $products];
100  $cart = $this->fixtureFactory->createByCode('cart', $cart);
101  $invoice = $this->objectManager->create(
102  \Magento\Sales\Test\TestStep\CreateInvoiceStep::class,
103  ['order' => $order, 'cart' => $cart]
104  );
105  $invoice->run();
106  $this->openDownloadableLink($order, (int)$downloads);
107  }
108 
116  protected function openDownloadableLink(OrderInjectable $order, $downloads)
117  {
118  $customerLogin = $this->objectManager->create(
119  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
120  ['customer' => $order->getDataFieldConfig('customer_id')['source']->getCustomer()]
121  );
122  $customerLogin->run();
123  $this->customerAccount->getAccountMenuBlock()->openMenuItem('My Downloadable Products');
124  $downloadableProductsUrl = $this->browser->getUrl();
125  foreach ($order->getEntityId()['products'] as $product) {
126  foreach ($product->getDownloadableLinks()['downloadable']['link'] as $link) {
127  for ($i = 0; $i < $downloads; $i++) {
128  $this->browser->open($this->customerProducts->getMainBlock()->getLinkUrl($link['title']));
129  $this->browser->open($downloadableProductsUrl);
130  }
131  }
132  }
133  }
134 }
__inject(FixtureFactory $fixtureFactory, CustomerAccountIndex $customerAccount, DownloadableCustomerProducts $customerProducts, BrowserInterface $browser)
$order
Definition: order.php:55
$invoice
$i
Definition: gallery.phtml:31