Exemple #1
0
 /**
  * @magentoDataFixture Magento/Reports/_files/viewed_products.php
  */
 public function testGetItems()
 {
     $expectedResult = array(1 => 3, 2 => 1, 21 => 2);
     $actualResult = array();
     /** @var \Magento\Reports\Model\Item $reportItem */
     foreach ($this->_collection->getItems() as $reportItem) {
         $actualResult[$reportItem->getData('product_id')] = $reportItem->getData('views_num');
     }
     $this->assertEquals($expectedResult, $actualResult);
 }
Exemple #2
0
 /**
  * @dataProvider tableForPeriodDataProvider
  *
  * @param $period
  * @param $expectedTable
  * @param $dateFrom
  * @param $dateTo
  * @param $isTotal
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function testTableSelection($period, $expectedTable, $dateFrom, $dateTo, $isTotal = false)
 {
     $dbTableName = $this->_collection->getTable($expectedTable);
     $this->_collection->setPeriod($period);
     if ($isTotal != false) {
         $this->_collection->setAggregatedColumns(['id']);
         $this->_collection->isTotals(true);
     }
     $this->_collection->setDateRange($dateFrom, $dateTo);
     $this->_collection->load();
     $from = $this->_collection->getSelect()->getPart('from');
     if ($isTotal != false) {
         $this->assertArrayHasKey('t', $from);
         $this->assertArrayHasKey('tableName', $from['t']);
     } elseif (!empty($from) && is_array($from)) {
         $this->assertArrayHasKey($dbTableName, $from);
         $actualTable = $from[$dbTableName]['tableName'];
         $this->assertEquals($dbTableName, $actualTable);
         $this->assertArrayHasKey('tableName', $from[$dbTableName]);
     } else {
         $union = $this->_collection->getSelect()->getPart('union');
         if ($period !== null && $dateFrom !== null && $dateTo !== null && $period != 'month') {
             $count = count($union);
             if ($period == 'year') {
                 if ($dbTableName == "report_viewed_product_aggregated_daily") {
                     $this->assertEquals($count, 2);
                 }
                 if ($dbTableName == "report_viewed_product_aggregated_yearly") {
                     $this->assertEquals($count, 3);
                 }
             } else {
                 $this->assertEquals($count, 3);
             }
         } else {
             $this->assertEquals(count($union), 2);
         }
     }
 }