當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WishList::addBuyable方法代碼示例

本文整理匯總了PHP中WishList::addBuyable方法的典型用法代碼示例。如果您正苦於以下問題:PHP WishList::addBuyable方法的具體用法?PHP WishList::addBuyable怎麽用?PHP WishList::addBuyable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WishList的用法示例。


在下文中一共展示了WishList::addBuyable方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testMultipleLists

 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));
 }
開發者ID:markguinn,項目名稱:silverstripe-wishlist,代碼行數:66,代碼來源:WishListTest.php


注:本文中的WishList::addBuyable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。