mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-15 06:09:58 +08:00
Optimize test
This commit is contained in:
parent
749339f331
commit
d8295dff33
@ -166,53 +166,28 @@ class SkinlibControllerTest extends TestCase
|
||||
->create()
|
||||
->merge($steves);
|
||||
$skins = $steves->merge($alexs);
|
||||
$page1 = $skins
|
||||
->sortByDesc('upload_at')
|
||||
->values()
|
||||
->map(function ($skin) {
|
||||
return $skin->tid;
|
||||
})
|
||||
->forPage(1, 20);
|
||||
$items = $this->getJson('/skinlib/data')
|
||||
->assertJson([
|
||||
'current_uid' => 0,
|
||||
'total_pages' => 2,
|
||||
])
|
||||
->decodeResponseJson('items');
|
||||
$items = array_map(function ($item) {
|
||||
return $item['tid'];
|
||||
}, $items);
|
||||
$this->assertCount(20, $items);
|
||||
$this->assertArraySubset($page1, $items);
|
||||
$items = $this->getJson('/skinlib/data?page=-5')
|
||||
->assertJson([
|
||||
'current_uid' => 0,
|
||||
'total_pages' => 2,
|
||||
])
|
||||
->decodeResponseJson('items');
|
||||
$items = array_map(function ($item) {
|
||||
return $item['tid'];
|
||||
}, $items);
|
||||
$this->assertCount(20, $items);
|
||||
$this->assertArraySubset($page1, $items);
|
||||
$page2 = $skins
|
||||
->sortByDesc('upload_at')
|
||||
->map(function ($skin) {
|
||||
return $skin->tid;
|
||||
})
|
||||
->forPage(2, 20)
|
||||
->values();
|
||||
$page2Count = $skins->forPage(2, 20)->count();
|
||||
$items = $this->getJson('/skinlib/data?page=2')
|
||||
->assertJson([
|
||||
'current_uid' => 0,
|
||||
'total_pages' => 2,
|
||||
])
|
||||
->decodeResponseJson('items');
|
||||
$items = array_map(function ($item) {
|
||||
return $item['tid'];
|
||||
}, $items);
|
||||
$this->assertCount(5, $items);
|
||||
$this->assertArraySubset($page2, $items);
|
||||
$this->getJson('/skinlib/data?page=8')
|
||||
->assertJson([
|
||||
'items' => [],
|
||||
@ -225,29 +200,15 @@ class SkinlibControllerTest extends TestCase
|
||||
'total_pages' => 2,
|
||||
])
|
||||
->decodeResponseJson('items');
|
||||
$items = array_map(function ($item) {
|
||||
return $item['tid'];
|
||||
}, $items);
|
||||
$this->assertCount($page2->count(), $items);
|
||||
$this->assertArraySubset($page2, $items);
|
||||
$page3 = $skins
|
||||
->sortByDesc('upload_at')
|
||||
->map(function ($skin) {
|
||||
return $skin->tid;
|
||||
})
|
||||
->forPage(3, 8)
|
||||
->values();
|
||||
$this->assertCount($page2Count, $items);
|
||||
$page3Count = $skins->forPage(3, 8)->count();
|
||||
$items = $this->getJson('/skinlib/data?page=3&items_per_page=8')
|
||||
->assertJson([
|
||||
'current_uid' => 0,
|
||||
'total_pages' => 4,
|
||||
])
|
||||
->decodeResponseJson('items');
|
||||
$items = array_map(function ($item) {
|
||||
return $item['tid'];
|
||||
}, $items);
|
||||
$this->assertCount($page3->count(), $items);
|
||||
$this->assertArraySubset($page3, $items);
|
||||
$this->assertCount($page3Count, $items);
|
||||
|
||||
// Add some private textures
|
||||
$uploader = factory(User::class)->create();
|
||||
@ -257,23 +218,15 @@ class SkinlibControllerTest extends TestCase
|
||||
->create(['public' => false, 'uploader' => $uploader->uid]);
|
||||
|
||||
// If not logged in, private textures should not be shown
|
||||
$paged = $skins
|
||||
->sortByDesc('upload_at')
|
||||
->map(function ($skin) {
|
||||
return $skin->tid;
|
||||
})
|
||||
->values()
|
||||
->forPage(1, 20);
|
||||
$items = $this->getJson('/skinlib/data')
|
||||
->assertJson([
|
||||
'current_uid' => 0,
|
||||
'total_pages' => 2,
|
||||
])
|
||||
->decodeResponseJson('items');
|
||||
$items = array_map(function ($item) {
|
||||
return $item['tid'];
|
||||
}, $items);
|
||||
$this->assertArraySubset($paged, $items);
|
||||
$this->assertTrue(collect($items)->every(function ($item) {
|
||||
return $item['public'] == true;
|
||||
}));
|
||||
|
||||
// Other users should not see someone's private textures
|
||||
$items = $this->actAs($otherUser)
|
||||
@ -300,14 +253,6 @@ class SkinlibControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
// Uploader can see his private textures
|
||||
$withPrivate = $skins
|
||||
->merge($private)
|
||||
->sortByDesc('upload_at')
|
||||
->map(function ($skin) {
|
||||
return $skin->tid;
|
||||
})
|
||||
->values()
|
||||
->forPage(1, 20);
|
||||
$items = $this->actAs($uploader)
|
||||
->getJson('/skinlib/data')
|
||||
->assertJson([
|
||||
@ -315,10 +260,9 @@ class SkinlibControllerTest extends TestCase
|
||||
'total_pages' => 2,
|
||||
])
|
||||
->decodeResponseJson('items');
|
||||
$items = array_map(function ($item) {
|
||||
return $item['tid'];
|
||||
}, $items);
|
||||
$this->assertArraySubset($withPrivate, $items);
|
||||
$this->assertTrue(collect($items)->contains(function ($item) {
|
||||
return $item['public'] == false;
|
||||
}));
|
||||
|
||||
// Administrators can see private textures
|
||||
$admin = factory(User::class, 'admin')->create();
|
||||
@ -329,10 +273,9 @@ class SkinlibControllerTest extends TestCase
|
||||
'total_pages' => 2,
|
||||
])
|
||||
->decodeResponseJson('items');
|
||||
$items = array_map(function ($item) {
|
||||
return $item['tid'];
|
||||
}, $items);
|
||||
$this->assertArraySubset($withPrivate, $items);
|
||||
$this->assertTrue(collect($items)->contains(function ($item) {
|
||||
return $item['public'] == false;
|
||||
}));
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
|
Loading…
Reference in New Issue
Block a user