Example #1
0
 public function testRemoveRelationship()
 {
     $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();
     foreach ($this->product->getRelatedProducts() as $relatedProduct) {
         $this->product->removeFromRelatedProducts($relatedProduct, ProductRelationship::TYPE_CROSS);
     }
     $this->assertEqual(0, $this->product->getRelatedProducts()->getTotalRecordCount());
     // Relationships are not removed from database unless the product is saved
     //$this->assertEqual(2, $this->product->getRelatedProducts()->getTotalRecordCount());
     $this->product->save();
     // Now they are removed
     //$this->product->loadRelationships(false, 0, true);
     $this->assertEqual(0, $this->product->getRelatedProducts()->getTotalRecordCount());
 }