* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ class RetailcrmCatalogTest extends RetailcrmTestCase { protected $data; protected function setUp() { parent::setUp(); $catalog = new RetailcrmCatalog(); $this->data = $catalog->getData(); } public function testCatalog() { $this->assertInternalType('array', $this->data); $this->assertCount(2, $this->data); $categories = $this->data[0]; $products = $this->data[1]; $this->assertNotEmpty($categories); $this->assertTrue($products->valid()); foreach ($categories as $category) { $this->assertNotEmpty($category); $this->assertArrayHasKey('id', $category); $this->assertArrayHasKey('parentId', $category); $this->assertArrayHasKey('name', $category); } foreach ($products as $product) { $this->assertNotEmpty($product); $this->assertArrayHasKey('id', $product); $this->assertArrayHasKey('productId', $product); $this->assertArrayHasKey('name', $product); $this->assertArrayHasKey('productName', $product); $this->assertArrayHasKey('url', $product); $this->assertRegExp('/http/', $product['url']); $this->assertArrayHasKey('price', $product); } } public function testIsPricesWithTax() { $products = $this->data[1]; $productsPresta = []; $productsPrestaList = Product::getProducts( (int) Configuration::get('PS_LANG_DEFAULT'), 0, 0, 'name', 'asc' ); foreach ($productsPrestaList as $productData) { $productsPresta[$productData['id_product']] = $productData; } unset($productsPrestaList); foreach ($products as $product) { $this->assertArrayHasKey('productId', $product); $this->assertArrayHasKey('price', $product); $prestaProduct = $productsPresta[$product['productId']]; $price = !empty($prestaProduct['rate']) ? round($prestaProduct['price'], 2) + (round($prestaProduct['price'], 2) * $prestaProduct['rate'] / 100) : round($prestaProduct['price'], 2); if (false !== strpos($product['id'], '#')) { $offerId = explode('#', $product['id']); $offerId = $offerId[1]; $offerCombination = new Combination($offerId); $offerCombinationPrice = !empty($prestaProduct['rate']) ? round($offerCombination->price, 2) + (round($offerCombination->price, 2) * $prestaProduct['rate'] / 100) : round($offerCombination->price, 2); $offerPrice = round($offerCombinationPrice, 2) + $price; $offerPrice = 0 < $offerPrice ? $offerPrice : $price; $this->assertEquals(round($offerPrice, 2), round($product['price'], 2)); } else { $this->assertEquals(round($price, 2), round($product['price'], 2)); } } } public function testIcmlGenerate() { $icml = new RetailcrmIcml(Configuration::get('PS_SHOP_NAME'), _PS_ROOT_DIR_ . '/retailcrm.xml'); $offers = []; foreach ($this->data[1] as $offer) { $offer['features'] = $this->getFeaturesData(); $offers[] = $offer; } $icml->generate($this->data[0], $offers); $this->assertFileExists(_PS_ROOT_DIR_ . '/retailcrm.xml'); $xml = simplexml_load_file(_PS_ROOT_DIR_ . '/retailcrm.xml'); $this->assertNotFalse($xml); } private function getFeaturesData() { return [ [ 'id_feature' => 1, 'name' => 'test', 'value' => 'value1', ], [ 'id_feature' => 1, 'name' => 'test', 'value' => 'value2', ], [ 'id_feature' => 1, 'name' => 'test', 'value' => 'value3', ], [ 'id_feature' => 2, 'name' => 'test', 'value' => 'value1', ], [ 'id_feature' => 2, 'name' => 'test', 'value' => 'value2', ], ]; } }