public function WishlistTest::testDefaultWishlist in Commerce Wishlist 8.3
Tests the default wishlist functionality.
File
- tests/
src/ Kernel/ Entity/ WishlistTest.php, line 134
Class
- WishlistTest
- Tests the wishlist entity.
Namespace
Drupal\Tests\commerce_wishlist\Kernel\EntityCode
public function testDefaultWishlist() {
$wishlist_type = WishlistType::create([
'id' => 'test_defaults',
'label' => 'test_defaults',
]);
$wishlist_type
->save();
/** @var \Drupal\commerce_wishlist\Entity\WishlistInterface $wishlist1 */
$wishlist1 = Wishlist::create([
'type' => $wishlist_type
->id(),
'uid' => $this->user
->id(),
]);
$wishlist1
->save();
// Confirm that the wishlist was set as default.
$this
->assertTrue($wishlist1
->isDefault());
/** @var \Drupal\commerce_wishlist\Entity\WishlistInterface $wishlist2 */
$wishlist2 = Wishlist::create([
'type' => $wishlist_type
->id(),
'uid' => $this->user
->id(),
]);
$wishlist2
->setDefault(TRUE);
$wishlist2
->save();
// Confirm that setting the second wishlist as default removed the
// flag from the first wishlist.
$wishlist2 = $this
->reloadEntity($wishlist2);
$wishlist1 = $this
->reloadEntity($wishlist1);
$this
->assertTrue($wishlist2
->isDefault());
$this
->assertFalse($wishlist1
->isDefault());
}