public function testImportWorks() { // Export data $data = $this->exportHandler->buildData(Lang::getDefaultLanguage()); $compareData = array(); $currentData = $data->getData(); // Replace the prices foreach ($currentData as $key => &$entry) { // let 6/10 prices be changed. if (rand(1, 100) >= 60) { $compareData[$key] = $rand = rand(1, 1000); $entry["price"] = $rand; } else { $compareData[$key] = $entry["price"]; } } // Import new prices $this->importHandler->retrieveFromFormatterData($data->setData($currentData)); // Export once again $newData = $this->exportHandler->buildData(Lang::getDefaultLanguage()); $newDataEntries = $newData->getData(); // Check them foreach ($compareData as $key => $price) { $this->assertEquals($price, $newDataEntries[$key]["price"]); } }
public function testQuery() { new Translator(new Container()); $export = new ProductPricesExport(new Container()); $data = $export->buildData(Lang::getDefaultLanguage()); $keys = ["attributes", "currency", "ean", "id", "price", "product_id", "promo", "promo_price", "title"]; $rawData = $data->getData(); $max = count($rawData); /** * If there's more that 50 entries, * just pick 50, it would be faster and as tested as if we test 1000 entries. */ if ($max > 50) { $max = 50; } for ($i = 0; $i < $max; ++$i) { $row = $rawData[$i]; $rowKeys = array_keys($row); $this->assertTrue(sort($rowKeys)); $this->assertEquals($keys, $rowKeys); $pse = ProductSaleElementsQuery::create()->findPk($row["id"]); $this->assertNotNull($pse); $this->assertEquals($pse->getEanCode(), $row["ean"]); $this->assertEquals($pse->getPromo(), $row["promo"]); $currency = CurrencyQuery::create()->findOneByCode($row["currency"]); $this->assertNotNull($currency); $price = $pse->getPricesByCurrency($currency); // The substr is a patch for php 5.4 float round $this->assertEquals(round($price->getPrice(), 3), round($row["price"], 3)); $this->assertEquals(round($price->getPromoPrice(), 3), round($row["promo_price"], 3)); $this->assertEquals($pse->getProduct()->getTitle(), $row["title"]); $attributeCombinations = $pse->getAttributeCombinations(); $attributes = []; foreach ($attributeCombinations as $attributeCombination) { if (!in_array($attributeCombination->getAttributeAv()->getTitle(), $attributes)) { $attributes[] = $attributeCombination->getAttributeAv()->getTitle(); } } $rowAttributes = explode(",", $row["attributes"]); sort($rowAttributes); sort($attributes); $this->assertEquals($attributes, $rowAttributes); } }