Clean up test names and remove laravel/browser-kit-testing

This commit is contained in:
James Brooks
2018-06-16 21:21:38 +01:00
parent 1593b7b451
commit aa2a39da6d
13 changed files with 444 additions and 405 deletions

View File

@@ -25,109 +25,145 @@ class ComponentGroupTest extends AbstractApiTestCase
const COMPONENT_GROUP_1_NAME = 'Component Group 1';
const COMPONENT_GROUP_2_NAME = 'Component Group 2';
public function testGetGroups()
public function test_can_get_all_component_groups()
{
$groups = factory('CachetHQ\Cachet\Models\ComponentGroup', 3)
$groups = factory(ComponentGroup::class, 2)
->create(['visible' => ComponentGroup::VISIBLE_GUEST]);
$this->get('/api/v1/components/groups');
$this->seeJsonContains(['id' => $groups[0]->id]);
$this->seeJsonContains(['id' => $groups[1]->id]);
$this->seeJsonContains(['id' => $groups[2]->id]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/components/groups');
$response->assertStatus(200);
$response->assertJsonFragment([
[
'id' => $groups[0]->id,
'name' => $groups[0]->name,
'created_at' => (string) $groups[0]->created_at,
'updated_at' => (string) $groups[0]->updated_at,
'order' => $groups[0]->order,
'collapsed' => $groups[0]->collapsed,
'visible' => $groups[0]->visible,
'enabled_components' => $groups[0]->enabled_components,
'enabled_components_lowest' => $groups[0]->enabled_components_lowest,
'lowest_human_status' => $groups[0]->lowest_human_status,
]
]);
$response->assertJsonFragment([
[
'id' => $groups[1]->id,
'name' => $groups[1]->name,
'created_at' => (string) $groups[1]->created_at,
'updated_at' => (string) $groups[1]->updated_at,
'order' => $groups[1]->order,
'collapsed' => $groups[1]->collapsed,
'visible' => $groups[1]->visible,
'enabled_components' => $groups[1]->enabled_components,
'enabled_components_lowest' => $groups[1]->enabled_components_lowest,
'lowest_human_status' => $groups[1]->lowest_human_status,
]
]);
}
public function testGetInvalidGroup()
public function test_cannot_get_invalid_component_group()
{
$this->get('/api/v1/components/groups/1');
$this->assertResponseStatus(404);
$response = $this->json('GET', '/api/v1/components/groups/1');
$response->assertStatus(404);
}
public function testPostGroupUnauthorized()
public function test_cannot_create_component_group_without_authorization()
{
$this->post('/api/v1/components/groups');
$response = $this->json('POST', '/api/v1/components/groups');
$this->assertResponseStatus(401);
$response->assertStatus(401);
}
public function testPostGroupNoData()
public function test_cannot_create_component_group_without_data()
{
$this->beUser();
$this->post('/api/v1/components/groups');
$this->assertResponseStatus(400);
$response = $this->json('POST', '/api/v1/components/groups');
$response->assertStatus(400);
}
public function testPostGroup()
public function test_can_create_new_component_group()
{
$this->beUser();
$this->post('/api/v1/components/groups', [
$response = $this->json('POST', '/api/v1/components/groups', [
'name' => 'Foo',
'order' => 1,
'collapsed' => 1,
'visible' => ComponentGroup::VISIBLE_GUEST,
]);
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Foo',
'order' => 1,
'collapsed' => 1,
'visible' => ComponentGroup::VISIBLE_GUEST,
]);
$this->seeJsonContains(['name' => 'Foo', 'order' => 1, 'collapsed' => 1, 'visible' => ComponentGroup::VISIBLE_GUEST]);
$this->assertResponseOk();
}
public function testGetNewGroup()
public function test_can_get_single_component_group()
{
$group = factory('CachetHQ\Cachet\Models\ComponentGroup')->create();
$group = factory(ComponentGroup::class)->create();
$this->get('/api/v1/components/groups/1');
$this->seeJsonContains(['name' => $group->name]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/components/groups/1');
$response->assertStatus(200);
$response->assertJsonFragment(['name' => $group->name]);
}
public function testPutGroup()
public function test_can_update_component_group()
{
$this->beUser();
$group = factory('CachetHQ\Cachet\Models\ComponentGroup')->create();
$group = factory(ComponentGroup::class)->create();
$this->put('/api/v1/components/groups/1', [
$response = $this->json('PUT', '/api/v1/components/groups/1', [
'name' => 'Lorem Ipsum Groupous',
]);
$this->seeJsonContains(['name' => 'Lorem Ipsum Groupous']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Lorem Ipsum Groupous']);
}
public function testDeleteGroup()
public function test_can_delete_component_group()
{
$this->beUser();
$group = factory('CachetHQ\Cachet\Models\ComponentGroup')->create();
$group = factory(ComponentGroup::class)->create();
$this->delete('/api/v1/components/groups/1');
$this->assertResponseStatus(204);
$response = $this->json('DELETE', '/api/v1/components/groups/1');
$response->assertStatus(204);
}
/** @test */
public function only_public_component_groups_are_shown_for_a_guest()
public function test_only_public_component_groups_are_shown_for_a_guest()
{
$this->createComponentGroups();
$this->get('/api/v1/components/groups')
->seeJsonContains(['name' => self::COMPONENT_GROUP_1_NAME]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/components/groups');
$response->assertStatus(200);
$response->assertJsonFragment(['name' => self::COMPONENT_GROUP_1_NAME]);
}
/** @test */
public function all_component_groups_are_displayed_for_loggedin_users()
public function test_all_component_groups_are_displayed_for_logged_in_users()
{
$this->createComponentGroups()
->signIn();
$this->get('/api/v1/components/groups')
->seeJsonContains(['name' => self::COMPONENT_GROUP_1_NAME])
->seeJsonContains(['name' => self::COMPONENT_GROUP_2_NAME]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/components/groups');
$response->assertStatus(200);
$response->assertJsonFragment(['name' => self::COMPONENT_GROUP_1_NAME]);
}
/**
* Set up the needed data for the tests.
*
* @return TestCase
* @return $this
*/
protected function createComponentGroups()
{
@@ -139,13 +175,13 @@ class ComponentGroupTest extends AbstractApiTestCase
/**
* Create a component group.
* Also attaches a creator if any given as a parameter
* or exists in the test class.
*
* Also attaches a creator if any given as a parameter or exists in the test class.
*
* @param string $name
* @param string $visible
*
* @return AbstractApiTestCase
* @return $this
*/
protected function createComponentGroup($name, $visible)
{