FavoriteTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of ibrand/favorite.
  4. *
  5. * (c) GuoJiangClub <https://www.ibrand.cc>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace GuoJiangClub\Component\Favorite\Test;
  11. use GuoJiangClub\Component\Favorite\Favorite;
  12. class FavoriteTest extends BaseTest
  13. {
  14. public function testFavoriteModels()
  15. {
  16. //Obtaining a user collected
  17. $list_goods = $this->repository->getByUserAndType(1, 'goods', 15);
  18. $this->assertEquals(2, count($list_goods));
  19. $list_goods = $this->repository->getByUserAndType(2, 'goods', 15);
  20. $this->assertEquals('Illuminate\Pagination\LengthAwarePaginator', get_class($list_goods));
  21. $this->assertEquals(0, count($list_goods));
  22. $list_activity = $this->repository->getByUserAndType(2, 'activity', 15);
  23. $this->assertEquals(3, count($list_activity));
  24. $isFavorite = $this->repository->isFavorite(1, 1, 'goods');
  25. $this->assertEquals('GuoJiangClub\Component\Favorite\Favorite', get_class($isFavorite));
  26. $this->assertEquals('goods', $isFavorite->favoriteable_type);
  27. $this->assertEquals(1, $isFavorite->favoriteable_id);
  28. //Whether the judgment has been collected
  29. $isFavorite = $this->repository->isFavorite(1, 8, 'goods');
  30. $this->assertNull($isFavorite);
  31. //User delete or create a collected
  32. $store = $this->repository->add(1, 8, 'goods');
  33. $this->assertEquals(8, Favorite::all()->last()->favoriteable_id);
  34. $del = $this->repository->add(1, 1, 'goods');
  35. $isFavorite = $this->repository->isFavorite(1, 1, 'goods');
  36. $this->assertNotNull($isFavorite);
  37. //Batch deleting
  38. $isFavorite_2 = $this->repository->isFavorite(1, 2, 'goods');
  39. $this->assertEquals('GuoJiangClub\Component\Favorite\Favorite', get_class($isFavorite_2));
  40. $this->assertEquals('goods', $isFavorite_2->favoriteable_type);
  41. $this->assertEquals(2, $isFavorite_2->favoriteable_id);
  42. $batch_deleting = $this->repository->delFavorites('1', [2, 3]);
  43. $isFavorite_2 = $this->repository->isFavorite(1, 2, 'goods');
  44. $this->assertNull($isFavorite_2);
  45. $isFavorite_3 = $this->repository->isFavorite(1, 3, 'goods');
  46. $this->assertNull($isFavorite_3);
  47. }
  48. }