function test_set_Null() { $this->installAndIncludeModels(array('Product' => 'id,reference int null')); $Product = new Product(array('reference' => 1)); $Product->save(); $Product->reload(); $this->assertEqual($Product->reference, 1); $Product->updateAttribute('reference', null); $this->assertNull($Product->reference); $Product->reload(); $this->assertNull($Product->reference); }
public function testEdit() { $prices = array(); $pricing = $this->product->getPricingHandler(); // Create new prices foreach (self::getApplication()->getCurrencyArray() as $currency) { $this->product->setPrice($currency, $prices[$currency] = rand(1, 1000) + rand(1, 100) / 100); } $this->product->save(); // Reload product $this->product->reload(); // Edit prices $this->product->loadSpecification(); foreach (self::getApplication()->getCurrencyArray() as $currency) { $this->product->setPrice($currency, $prices[$currency] = rand(1, 1000) + rand(1, 100) / 100); } $this->product->save(); // Prices should change (also note that to make prices change you should reload specifications too) $this->product->loadSpecification(); $pricing = $this->product->getPricingHandler(); $this->assertEqual($pricing->toArray(ProductPricing::CALCULATED), $prices); }
public function testGetRelationships() { $otherProducts = array(); foreach (range(1, 2) as $i) { $otherProducts[$i] = Product::getNewInstance($this->productCategory); $otherProducts[$i]->save(); $this->product->addRelatedProduct($otherProducts[$i]); } $this->product->save(); $this->product->reload(); $i = 1; $this->assertEqual(2, $this->product->getRelationships()->getTotalRecordCount()); foreach ($this->product->getRelationships() as $relationship) { $this->assertIsA($relationship, 'ProductRelationship'); $this->assertTrue($relationship->relatedProduct->get() === $otherProducts[$i]); $i++; } }