/** * @param WishList $list */ public static function set_current($list) { if ($list) { $list->write(false, false, true); } // force LastEdited to change self::$current = $list; }
/** * @param array $data * @param Form $form * @return SS_HTTPResponse */ public function saveList(array $data, Form $form) { if (!isset($data['Title']) || trim($data['Title']) == '') { $this->wishList->Title = 'Wish List'; } else { $this->wishList->Title = $data['Title']; } $this->wishList->write(); $request = $this->getRequest(); $this->extend('updateSaveListResponse', $request, $response, $this->wishList, $data); return $response ? $response : $this->redirectBack(); }
public function testMultipleLists() { WishList::set_current(null); $m1 = $this->objFromFixture('Member', 'm1'); $m2 = $this->objFromFixture('Member', 'm2'); $m1->logIn(); $p1 = $this->objFromFixture('Product', 'p1'); $p2 = $this->objFromFixture('Product', 'p2'); $p3 = $this->objFromFixture('Product', 'p3'); // should be able to retrieve a list of lists $allLists = WishList::get_for_user(); $this->assertNotNull($allLists); $this->assertTrue($allLists instanceof DataList); // should initially be 0 lists $this->assertEquals(0, WishList::get_for_user()->count()); $this->assertEquals(0, WishList::get_for_user($m2)->count()); // current method should create one list $l1 = WishList::current(); $l1->write(); $l1->addBuyable($p1); //Debug::dump(array($l1, WishList::get_for_user()->sql(), WishList::get_for_user()->count(), WishList::get_for_user()->getIDList())); $this->assertEquals(1, WishList::get_for_user()->count()); $this->assertEquals(0, WishList::get_for_user($m2)->count()); // after manually creating a list there should be two lists $l2 = new WishList(array('OwnerID' => $m1->ID, 'Title' => 'Christmas')); $l2->write(); $this->assertEquals(2, WishList::get_for_user()->count()); // after adding a product to one list, it should not be present in the other one // but should still report that it is in a list $l2->addBuyable($p2); $this->assertTrue($p1->IsInWishList()); $this->assertTrue($l1->hasBuyable($p1)); $this->assertFalse($l2->hasBuyable($p1)); $this->assertTrue($p2->IsInWishList()); $this->assertFalse($l1->hasBuyable($p2)); $this->assertTrue($l2->hasBuyable($p2)); $this->assertFalse($p3->IsInWishList()); $this->assertFalse($l1->hasBuyable($p3)); $this->assertFalse($l2->hasBuyable($p3)); // after creating a list for the a different user and adding // an item to that list, the item should not report that it is // in a list and should not be present in any of the other lists $l3 = new WishList(array('OwnerID' => $m2->ID, 'Title' => 'Christmas for someone else')); $l3->write(); $l3->addBuyable($p3); $this->assertEquals(2, WishList::get_for_user()->count()); $this->assertEquals(1, WishList::get_for_user($m2)->count()); $this->assertFalse($p3->IsInWishList()); $this->assertFalse($l1->hasBuyable($p3)); $this->assertFalse($l2->hasBuyable($p3)); // Buyable should be able to exist in two lists at once $l2->addBuyable($p1); $this->assertTrue($p1->IsInWishList()); $this->assertTrue($l1->hasBuyable($p1)); $this->assertTrue($l2->hasBuyable($p1)); // removing an item from one list should not remove it from the other $l1->removeBuyable($p1); $this->assertTrue($p1->IsInWishList()); $this->assertFalse($l1->hasBuyable($p1)); $this->assertTrue($l2->hasBuyable($p1)); // after removing item from both lists it should report as not being in a list $l2->removeBuyable($p1); $this->assertFalse($p1->IsInWishList()); $this->assertFalse($l1->hasBuyable($p1)); $this->assertFalse($l2->hasBuyable($p1)); }