/**
  * @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);
         }
     }
 }