当前位置: 首页>>代码示例>>PHP>>正文


PHP WishList::hasBuyable方法代码示例

本文整理汇总了PHP中WishList::hasBuyable方法的典型用法代码示例。如果您正苦于以下问题:PHP WishList::hasBuyable方法的具体用法?PHP WishList::hasBuyable怎么用?PHP WishList::hasBuyable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WishList的用法示例。


在下文中一共展示了WishList::hasBuyable方法的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::hasBuyable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。