From a5615eb0906f4e1bbab1a2628ec1f61c1ec7129f Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 26 Dec 2017 19:28:14 +0800 Subject: [PATCH] test(model): add tests for "Closet" model --- tests/ModelsTest/ClosetTest.php | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/ModelsTest/ClosetTest.php diff --git a/tests/ModelsTest/ClosetTest.php b/tests/ModelsTest/ClosetTest.php new file mode 100644 index 00000000..7609e56c --- /dev/null +++ b/tests/ModelsTest/ClosetTest.php @@ -0,0 +1,51 @@ +create(); + (new Closet($user->uid))->save(); + } + $this->assertCount(2, Closet::all()); + } + + public function testFilterInvalidTexture() + { + $other = factory(User::class)->create(); + $texture = factory(Texture::class)->create([ + 'uploader' => $other->uid, + 'public' => 0 + ]); + $user = factory(User::class)->create(); + $closet = new Closet($user->uid); + $closet->add(-1, ''); + $closet->add($texture->tid, ''); + $closet->save(); + + $this->assertCount(0, (new Closet($user->uid))->getItems()); + $this->assertEquals( + $user->score + 2 * option('score_per_closet_item'), + User::find($user->uid)->score + ); + + option(['return_score' => false]); + $closet = new Closet($user->uid); + $closet->add(-1, ''); + $closet->add($texture->tid, ''); + $closet->save(); + $user = User::find($user->uid); + $this->assertCount(0, (new Closet($user->uid))->getItems()); + $this->assertEquals($user->score, User::find($user->uid)->score); + } +}