fix tests of ClosetController
This commit is contained in:
parent
d859d9ce49
commit
d65d6e298e
|
|
@ -25,7 +25,7 @@ class ClosetControllerTest extends TestCase
|
||||||
|
|
||||||
public function testIndex()
|
public function testIndex()
|
||||||
{
|
{
|
||||||
$this->visit('/user/closet')->assertViewHas('user');
|
$this->get('/user/closet')->assertViewHas('user');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetClosetData()
|
public function testGetClosetData()
|
||||||
|
|
@ -38,30 +38,27 @@ class ClosetControllerTest extends TestCase
|
||||||
$closet->save();
|
$closet->save();
|
||||||
|
|
||||||
// Use default query parameters
|
// Use default query parameters
|
||||||
$this->get('/user/closet-data')
|
$this->getJson('/user/closet-data')
|
||||||
->seeJsonStructure([
|
->assertJsonStructure([
|
||||||
'category',
|
'category',
|
||||||
'total_pages',
|
'total_pages',
|
||||||
'items' => [['tid', 'name', 'type', 'add_at']]
|
'items' => [['tid', 'name', 'type', 'add_at']]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Responsive
|
// Responsive
|
||||||
$result = json_decode($this->call('get', '/user/closet-data?perPage=0')
|
$result = $this->json('get', '/user/closet-data?perPage=0')->json();
|
||||||
->getContent(), true);
|
$this->assertCount(6, $result['items']);
|
||||||
$this->assertEquals(6, count($result['items']));
|
$result = $this->json('get', '/user/closet-data?perPage=8')->json();
|
||||||
$result = json_decode($this->call('get', '/user/closet-data?perPage=8')
|
$this->assertCount(8, $result['items']);
|
||||||
->getContent(), true);
|
$result = $this->json('get', '/user/closet-data?perPage=8&page=2')->json();
|
||||||
$this->assertEquals(8, count($result['items']));
|
$this->assertCount(2, $result['items']);
|
||||||
$result = json_decode($this->call('get', '/user/closet-data?perPage=8&page=2')
|
|
||||||
->getContent(), true);
|
|
||||||
$this->assertEquals(2, count($result['items']));
|
|
||||||
|
|
||||||
// Get capes
|
// Get capes
|
||||||
$cape = factory(Texture::class, 'cape')->create();
|
$cape = factory(Texture::class, 'cape')->create();
|
||||||
$closet->add($cape->tid, 'custom_name');
|
$closet->add($cape->tid, 'custom_name');
|
||||||
$closet->save();
|
$closet->save();
|
||||||
$this->get('/user/closet-data?category=cape')
|
$this->getJson('/user/closet-data?category=cape')
|
||||||
->seeJson([
|
->assertJson([
|
||||||
'category' => 'cape',
|
'category' => 'cape',
|
||||||
'total_pages' => 1,
|
'total_pages' => 1,
|
||||||
'items' => [[
|
'items' => [[
|
||||||
|
|
@ -74,8 +71,8 @@ class ClosetControllerTest extends TestCase
|
||||||
|
|
||||||
// Search by keyword
|
// Search by keyword
|
||||||
$random = $textures->random();
|
$random = $textures->random();
|
||||||
$this->get('/user/closet-data?q='.$random->name)
|
$this->getJson('/user/closet-data?q='.$random->name)
|
||||||
->seeJson([
|
->assertJson([
|
||||||
'category' => 'skin',
|
'category' => 'skin',
|
||||||
'total_pages' => 1,
|
'total_pages' => 1,
|
||||||
'items' => [[
|
'items' => [[
|
||||||
|
|
@ -94,67 +91,67 @@ class ClosetControllerTest extends TestCase
|
||||||
option(['score_per_closet_item' => 10]);
|
option(['score_per_closet_item' => 10]);
|
||||||
|
|
||||||
// Missing `tid` field
|
// Missing `tid` field
|
||||||
$this->post('/user/closet/add', [], ['X-Requested-With' => 'XMLHttpRequest'])
|
$this->postJson('/user/closet/add', [], ['X-Requested-With' => 'XMLHttpRequest'])
|
||||||
->seeJson([
|
->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.required', ['attribute' => 'tid'])
|
'msg' => trans('validation.required', ['attribute' => 'tid'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// `tid` is not a integer
|
// `tid` is not a integer
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/add',
|
'/user/closet/add',
|
||||||
['tid' => 'string'],
|
['tid' => 'string'],
|
||||||
['X-Requested-With' => 'XMLHttpRequest']
|
['X-Requested-With' => 'XMLHttpRequest']
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.integer', ['attribute' => 'tid'])
|
'msg' => trans('validation.integer', ['attribute' => 'tid'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Missing `name` field
|
// Missing `name` field
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/add',
|
'/user/closet/add',
|
||||||
['tid' => 0],
|
['tid' => 0],
|
||||||
['X-Requested-With' => 'XMLHttpRequest']
|
['X-Requested-With' => 'XMLHttpRequest']
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.required', ['attribute' => 'Name'])
|
'msg' => trans('validation.required', ['attribute' => 'Name'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// `name` field has special characters
|
// `name` field has special characters
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/add',
|
'/user/closet/add',
|
||||||
['tid' => 0, 'name' => '\\'],
|
['tid' => 0, 'name' => '\\'],
|
||||||
['X-Requested-With' => 'XMLHttpRequest']
|
['X-Requested-With' => 'XMLHttpRequest']
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.no_special_chars', ['attribute' => 'Name'])
|
'msg' => trans('validation.no_special_chars', ['attribute' => 'Name'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// The user doesn't have enough score to add a texture
|
// The user doesn't have enough score to add a texture
|
||||||
$this->user->setScore(0);
|
$this->user->setScore(0);
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/add',
|
'/user/closet/add',
|
||||||
['tid' => $texture->tid, 'name' => $name]
|
['tid' => $texture->tid, 'name' => $name]
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 7,
|
'errno' => 7,
|
||||||
'msg' => trans('user.closet.add.lack-score')
|
'msg' => trans('user.closet.add.lack-score')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Add a not-existed texture
|
// Add a not-existed texture
|
||||||
$this->user->setScore(100);
|
$this->user->setScore(100);
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/add',
|
'/user/closet/add',
|
||||||
['tid' => -1, 'name' => 'my']
|
['tid' => -1, 'name' => 'my']
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('user.closet.add.not-found')
|
'msg' => trans('user.closet.add.not-found')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Add a texture successfully
|
// Add a texture successfully
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/add',
|
'/user/closet/add',
|
||||||
['tid' => $texture->tid, 'name' => $name]
|
['tid' => $texture->tid, 'name' => $name]
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 0,
|
'errno' => 0,
|
||||||
'msg' => trans('user.closet.add.success', ['name' => $name])
|
'msg' => trans('user.closet.add.success', ['name' => $name])
|
||||||
]);
|
]);
|
||||||
|
|
@ -165,10 +162,10 @@ class ClosetControllerTest extends TestCase
|
||||||
$this->assertTrue($closet->has($texture->tid));
|
$this->assertTrue($closet->has($texture->tid));
|
||||||
|
|
||||||
// If the texture is duplicated, should be warned
|
// If the texture is duplicated, should be warned
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/add',
|
'/user/closet/add',
|
||||||
['tid' => $texture->tid, 'name' => $name]
|
['tid' => $texture->tid, 'name' => $name]
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('user.closet.add.repeated')
|
'msg' => trans('user.closet.add.repeated')
|
||||||
]);
|
]);
|
||||||
|
|
@ -180,47 +177,47 @@ class ClosetControllerTest extends TestCase
|
||||||
$name = 'new';
|
$name = 'new';
|
||||||
|
|
||||||
// Missing `tid` field
|
// Missing `tid` field
|
||||||
$this->post('/user/closet/rename', [], ['X-Requested-With' => 'XMLHttpRequest'])
|
$this->postJson('/user/closet/rename', [], ['X-Requested-With' => 'XMLHttpRequest'])
|
||||||
->seeJson([
|
->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.required', ['attribute' => 'tid'])
|
'msg' => trans('validation.required', ['attribute' => 'tid'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// `tid` is not a integer
|
// `tid` is not a integer
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/rename',
|
'/user/closet/rename',
|
||||||
['tid' => 'string'],
|
['tid' => 'string'],
|
||||||
['X-Requested-With' => 'XMLHttpRequest']
|
['X-Requested-With' => 'XMLHttpRequest']
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.integer', ['attribute' => 'tid'])
|
'msg' => trans('validation.integer', ['attribute' => 'tid'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Missing `new_name` field
|
// Missing `new_name` field
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/rename',
|
'/user/closet/rename',
|
||||||
['tid' => 0],
|
['tid' => 0],
|
||||||
['X-Requested-With' => 'XMLHttpRequest']
|
['X-Requested-With' => 'XMLHttpRequest']
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.required', ['attribute' => 'new name'])
|
'msg' => trans('validation.required', ['attribute' => 'new name'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// `new_name` field has special characters
|
// `new_name` field has special characters
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/rename',
|
'/user/closet/rename',
|
||||||
['tid' => 0, 'new_name' => '\\'],
|
['tid' => 0, 'new_name' => '\\'],
|
||||||
['X-Requested-With' => 'XMLHttpRequest']
|
['X-Requested-With' => 'XMLHttpRequest']
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.no_special_chars', ['attribute' => 'new name'])
|
'msg' => trans('validation.no_special_chars', ['attribute' => 'new name'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Rename a not-existed texture
|
// Rename a not-existed texture
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/rename',
|
'/user/closet/rename',
|
||||||
['tid' => -1, 'new_name' => $name]
|
['tid' => -1, 'new_name' => $name]
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('user.closet.remove.non-existent')
|
'msg' => trans('user.closet.remove.non-existent')
|
||||||
]);
|
]);
|
||||||
|
|
@ -230,10 +227,10 @@ class ClosetControllerTest extends TestCase
|
||||||
$closet->add($texture->tid, 'name');
|
$closet->add($texture->tid, 'name');
|
||||||
$closet->save();
|
$closet->save();
|
||||||
$closet = new Closet($this->user->uid);
|
$closet = new Closet($this->user->uid);
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/rename',
|
'/user/closet/rename',
|
||||||
['tid' => $texture->tid, 'new_name' => $name]
|
['tid' => $texture->tid, 'new_name' => $name]
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 0,
|
'errno' => 0,
|
||||||
'msg' => trans('user.closet.rename.success', ['name' => 'new'])
|
'msg' => trans('user.closet.rename.success', ['name' => 'new'])
|
||||||
]);
|
]);
|
||||||
|
|
@ -247,27 +244,27 @@ class ClosetControllerTest extends TestCase
|
||||||
$texture = factory(Texture::class)->create();
|
$texture = factory(Texture::class)->create();
|
||||||
|
|
||||||
// Missing `tid` field
|
// Missing `tid` field
|
||||||
$this->post('/user/closet/remove', [], ['X-Requested-With' => 'XMLHttpRequest'])
|
$this->postJson('/user/closet/remove', [], ['X-Requested-With' => 'XMLHttpRequest'])
|
||||||
->seeJson([
|
->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.required', ['attribute' => 'tid'])
|
'msg' => trans('validation.required', ['attribute' => 'tid'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// `tid` is not a integer
|
// `tid` is not a integer
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/remove',
|
'/user/closet/remove',
|
||||||
['tid' => 'string'],
|
['tid' => 'string'],
|
||||||
['X-Requested-With' => 'XMLHttpRequest']
|
['X-Requested-With' => 'XMLHttpRequest']
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('validation.integer', ['attribute' => 'tid'])
|
'msg' => trans('validation.integer', ['attribute' => 'tid'])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Rename a not-existed texture
|
// Rename a not-existed texture
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/remove',
|
'/user/closet/remove',
|
||||||
['tid' => -1]
|
['tid' => -1]
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => trans('user.closet.remove.non-existent')
|
'msg' => trans('user.closet.remove.non-existent')
|
||||||
]);
|
]);
|
||||||
|
|
@ -277,10 +274,10 @@ class ClosetControllerTest extends TestCase
|
||||||
$closet->add($texture->tid, 'name');
|
$closet->add($texture->tid, 'name');
|
||||||
$closet->save();
|
$closet->save();
|
||||||
$score = $this->user->score;
|
$score = $this->user->score;
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/remove',
|
'/user/closet/remove',
|
||||||
['tid' => $texture->tid]
|
['tid' => $texture->tid]
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 0,
|
'errno' => 0,
|
||||||
'msg' => trans('user.closet.remove.success')
|
'msg' => trans('user.closet.remove.success')
|
||||||
]);
|
]);
|
||||||
|
|
@ -296,10 +293,10 @@ class ClosetControllerTest extends TestCase
|
||||||
$closet->add($texture->tid, 'name');
|
$closet->add($texture->tid, 'name');
|
||||||
$closet->save();
|
$closet->save();
|
||||||
$score = $this->user->score;
|
$score = $this->user->score;
|
||||||
$this->post(
|
$this->postJson(
|
||||||
'/user/closet/remove',
|
'/user/closet/remove',
|
||||||
['tid' => $texture->tid]
|
['tid' => $texture->tid]
|
||||||
)->seeJson([
|
)->assertJson([
|
||||||
'errno' => 0,
|
'errno' => 0,
|
||||||
'msg' => trans('user.closet.remove.success')
|
'msg' => trans('user.closet.remove.success')
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user