Merge branch '2.4' of github.com:CachetHQ/Cachet into feature/2895-custom-meta-descriptions-per-incident

This commit is contained in:
Nico Stapelbroek
2018-07-02 11:20:47 +02:00
399 changed files with 10754 additions and 5607 deletions

View File

@@ -14,22 +14,17 @@ namespace CachetHQ\Tests\Cachet;
use CachetHQ\Cachet\Models\User;
use CachetHQ\Cachet\Settings\Cache;
use CachetHQ\Cachet\Settings\Repository;
use Illuminate\Contracts\Console\Kernel;
use Laravel\BrowserKitTesting\TestCase;
use Illuminate\Foundation\Testing\TestCase;
/**
* This is the abstract test case class.
*
* @author Graham Campbell <graham@alt-three.com>
* @author James Brooks <james@alt-three.com>
*/
abstract class AbstractTestCase extends TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
use CreatesApplicationTrait;
/**
* Test actor.
@@ -38,20 +33,6 @@ abstract class AbstractTestCase extends TestCase
*/
protected $user;
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
return $app;
}
/**
* Sign in an user if it's the case.
*

View File

@@ -11,18 +11,24 @@
namespace CachetHQ\Tests\Cachet;
use AltThree\TestBench\AnalysisTrait;
use PHPUnit_Framework_TestCase as TestCase;
use GrahamCampbell\Analyzer\AnalysisTrait;
use PHPUnit\Framework\TestCase;
/**
* This is the analysis test class.
*
* @author Graham Campbell <graham@alt-three.com>
* @author James Brooks <james@alt-three.com>
*/
class AnalysisTest extends TestCase
{
use AnalysisTrait;
/**
* Get the code paths to analyze.
*
* @return string[]
*/
protected function getPaths()
{
return [

View File

@@ -28,12 +28,16 @@ abstract class AbstractApiTestCase extends AbstractTestCase
/**
* Become a user.
*
* @return void
* @return $this
*/
protected function beUser()
{
$this->user = factory(User::class)->create();
$this->user = factory(User::class)->create([
'username' => 'cachet-test',
]);
$this->be($this->user);
return $this;
}
}

View File

@@ -11,6 +11,9 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Bus\Events\ComponentGroup\ComponentGroupWasCreatedEvent;
use CachetHQ\Cachet\Bus\Events\ComponentGroup\ComponentGroupWasRemovedEvent;
use CachetHQ\Cachet\Bus\Events\ComponentGroup\ComponentGroupWasUpdatedEvent;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
@@ -25,109 +28,155 @@ 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');
$this->doesntExpectEvents(ComponentGroupWasCreatedEvent::class);
$this->assertResponseStatus(401);
$response = $this->json('POST', '/api/v1/components/groups');
$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);
$this->doesntExpectEvents(ComponentGroupWasCreatedEvent::class);
$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', [
$this->expectsEvents(ComponentGroupWasCreatedEvent::class);
$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', [
$this->expectsEvents(ComponentGroupWasUpdatedEvent::class);
$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);
$this->expectsEvents(ComponentGroupWasRemovedEvent::class);
$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 +188,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)
{

View File

@@ -11,6 +11,12 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasChangedEvent;
use CachetHQ\Cachet\Bus\Events\Component\ComponentWasCreatedEvent;
use CachetHQ\Cachet\Bus\Events\Component\ComponentWasRemovedEvent;
use CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent;
use CachetHQ\Cachet\Models\Component;
/**
* This is the component test class.
*
@@ -19,43 +25,52 @@ namespace CachetHQ\Tests\Cachet\Api;
*/
class ComponentTest extends AbstractApiTestCase
{
public function testGetComponents()
public function test_can_get_all_components()
{
$components = factory('CachetHQ\Cachet\Models\Component', 3)->create();
$components = factory(Component::class, 3)->create();
$this->get('/api/v1/components');
$this->seeJsonContains(['id' => $components[0]->id]);
$this->seeJsonContains(['id' => $components[1]->id]);
$this->seeJsonContains(['id' => $components[2]->id]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/components');
$response->assertStatus(200);
$response->assertJsonFragment(['id' => $components[0]->id]);
$response->assertJsonFragment(['id' => $components[1]->id]);
$response->assertJsonFragment(['id' => $components[2]->id]);
}
public function testGetInvalidComponent()
public function test_cannot_get_invalid_component()
{
$this->get('/api/v1/components/1');
$this->assertResponseStatus(404);
$response = $this->json('GET', '/api/v1/components/1');
$response->assertStatus(404);
}
public function testPostComponentUnauthorized()
public function test_cannot_create_component_without_authorization()
{
$this->post('/api/v1/components');
$this->doesntExpectEvents(ComponentWasCreatedEvent::class);
$this->assertResponseStatus(401);
$response = $this->json('POST', '/api/v1/components');
$response->assertStatus(401);
}
public function testPostComponentNoData()
public function test_cannot_create_component_without_data()
{
$this->beUser();
$this->post('/api/v1/components');
$this->assertResponseStatus(400);
$this->doesntExpectEvents(ComponentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/components');
$response->assertStatus(400);
}
public function testPostComponent()
public function test_can_create_component()
{
$this->beUser();
$this->post('/api/v1/components', [
$this->expectsEvents(ComponentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo',
'description' => 'Bar',
'status' => 1,
@@ -64,15 +79,18 @@ class ComponentTest extends AbstractApiTestCase
'group_id' => 1,
'enabled' => true,
]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function testPostComponentWithoutEnabledField()
public function test_can_create_component_without_enabled_field()
{
$this->beUser();
$this->post('/api/v1/components', [
$this->expectsEvents(ComponentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo',
'description' => 'Bar',
'status' => 1,
@@ -80,15 +98,18 @@ class ComponentTest extends AbstractApiTestCase
'order' => 1,
'group_id' => 1,
]);
$this->seeJsonContains(['name' => 'Foo', 'enabled' => true]);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'enabled' => true]);
}
public function testPostComponentWithMetaData()
public function test_can_create_component_with_meta_data()
{
$this->beUser();
$this->post('/api/v1/components', [
$this->expectsEvents(ComponentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo',
'description' => 'Bar',
'status' => 1,
@@ -101,19 +122,23 @@ class ComponentTest extends AbstractApiTestCase
],
]);
$this->seeJsonContains([
'meta' => [
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Foo',
'status' => 1,
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
],
]);
$this->assertResponseOk();
}
public function testPostDisabledComponent()
public function test_can_create_disabled_component()
{
$this->beUser();
$this->post('/api/v1/components', [
$this->expectsEvents(ComponentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo',
'description' => 'Bar',
'status' => 1,
@@ -122,62 +147,108 @@ class ComponentTest extends AbstractApiTestCase
'group_id' => 1,
'enabled' => 0,
]);
$this->seeJsonContains(['name' => 'Foo', 'enabled' => false]);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'enabled' => false]);
}
public function testGetNewComponent()
public function test_can_get_newly_created_component()
{
$component = factory('CachetHQ\Cachet\Models\Component')->create();
$component = factory(Component::class)->create();
$this->get('/api/v1/components/1');
$this->seeJsonContains(['name' => $component->name]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/components/1');
$response->assertStatus(200);
$response->assertJsonFragment(['name' => $component->name]);
}
public function testPutComponent()
public function test_can_update_component()
{
$this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create();
$component = factory(Component::class)->create();
$this->put('/api/v1/components/1', [
$this->expectsEvents(ComponentWasUpdatedEvent::class);
$response = $this->json('PUT', '/api/v1/components/1', [
'name' => 'Foo',
]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function testPutComponentWithMetaData()
public function test_can_update_component_without_status_change()
{
$this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create([
$component = factory(Component::class)->create();
$this->expectsEvents(ComponentWasUpdatedEvent::class);
$this->doesntExpectEvents(ComponentStatusWasChangedEvent::class);
$response = $this->json('PUT', '/api/v1/components/1', [
'name' => 'Foo',
]);
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function test_can_update_component_with_status_change()
{
$this->beUser();
$component = factory(Component::class)->create([
'status' => 1,
]);
$this->expectsEvents([
ComponentWasUpdatedEvent::class,
ComponentStatusWasChangedEvent::class,
]);
$response = $this->json('PUT', '/api/v1/components/1', [
'name' => 'Foo',
'status' => 2,
]);
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'status' => 2]);
}
public function test_can_update_component_with_meta_data()
{
$this->beUser();
$component = factory(Component::class)->create([
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
],
]);
$this->put('/api/v1/components/1', [
$this->expectsEvents(ComponentWasUpdatedEvent::class);
$response = $this->json('PUT', '/api/v1/components/1', [
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
'foo' => 'bar',
],
]);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
'foo' => 'bar',
],
]);
$this->assertResponseOk();
}
public function testDeleteComponent()
public function test_can_delete_component()
{
$this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create();
$component = factory(Component::class)->create();
$this->delete('/api/v1/components/1');
$this->assertResponseStatus(204);
$this->expectsEvents(ComponentWasRemovedEvent::class);
$response = $this->json('DELETE', '/api/v1/components/1');
$response->assertStatus(204);
}
}

View File

@@ -19,26 +19,27 @@ namespace CachetHQ\Tests\Cachet\Api;
*/
class GeneralTest extends AbstractApiTestCase
{
public function testGetPing()
public function test_can_ping()
{
$this->get('/api/v1/ping');
$this->seeJsonContains(['data' => 'Pong!']);
$this->assertResponseOk();
$this->seeHeader('Content-Type', 'application/json');
$response = $this->json('GET', '/api/v1/ping');
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/json');
$response->assertJsonFragment(['data' => 'Pong!']);
}
public function testErrorPage()
public function test_see_error_page_for_unknown_endpoint()
{
$this->get('/api/v1/not-found');
$response = $this->json('GET', '/api/v1/not-found');
$this->assertResponseStatus(404);
$this->seeHeader('Content-Type', 'application/json');
$response->assertStatus(404);
$response->assertHeader('Content-Type', 'application/json');
}
public function testNotAcceptableContentType()
public function test_non_acceptable_content_type()
{
$this->get('/api/v1/ping', ['HTTP_Accept' => 'text/html']);
$response = $this->json('GET', '/api/v1/ping', [], ['HTTP_Accept' => 'text/html']);
$this->assertResponseStatus(406);
$response->assertStatus(406);
}
}

View File

@@ -11,6 +11,13 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasCreatedEvent;
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasRemovedEvent;
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasUpdatedEvent;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate;
/**
* This is the incident test class.
*
@@ -19,59 +26,73 @@ namespace CachetHQ\Tests\Cachet\Api;
*/
class IncidentTest extends AbstractApiTestCase
{
public function testGetIncidents()
public function test_can_get_all_incidents()
{
$incidents = factory('CachetHQ\Cachet\Models\Incident', 3)->create();
$incidents = factory(Incident::class, 3)->create();
$this->get('/api/v1/incidents');
$this->seeJsonContains(['id' => $incidents[0]->id]);
$this->seeJsonContains(['id' => $incidents[1]->id]);
$this->seeJsonContains(['id' => $incidents[2]->id]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/incidents');
$response->assertStatus(200);
$response->assertJsonFragment(['id' => $incidents[0]->id]);
$response->assertJsonFragment(['id' => $incidents[1]->id]);
$response->assertJsonFragment(['id' => $incidents[2]->id]);
}
public function testGetInvalidIncident()
public function test_cannot_get_invalid_component()
{
$this->get('/api/v1/incidents/0');
$this->assertResponseStatus(404);
$response = $this->json('GET', '/api/v1/incidents/0');
$response->assertStatus(404);
}
public function testPostIncidentUnauthorized()
public function test_cannot_create_incident_without_authorization()
{
$this->post('/api/v1/incidents');
$this->assertResponseStatus(401);
$this->doesntExpectEvents(IncidentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/incidents');
$response->assertStatus(401);
}
public function testPostIncidentNoData()
public function test_cannot_create_incident_with_missing_data()
{
$this->beUser();
$this->post('/api/v1/incidents');
$this->assertResponseStatus(400);
$this->doesntExpectEvents(IncidentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/incidents');
$response->assertStatus(400);
}
public function testPostIncident()
public function test_can_create_incident()
{
$this->beUser();
$this->post('/api/v1/incidents', [
$this->expectsEvents(IncidentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/incidents', [
'name' => 'Foo',
'message' => 'Lorem ipsum dolor sit amet',
'status' => 1,
'visible' => 1,
'stickied' => false,
]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function testPostIncidentWithComponentStatus()
public function test_can_create_incident_with_component_status()
{
$component = factory('CachetHQ\Cachet\Models\Component')->create();
$component = factory(Component::class)->create();
$this->beUser();
$this->post('/api/v1/incidents', [
$this->expectsEvents(IncidentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/incidents', [
'name' => 'Foo',
'message' => 'Lorem ipsum dolor sit amet',
'status' => 1,
@@ -80,16 +101,19 @@ class IncidentTest extends AbstractApiTestCase
'visible' => 1,
'stickied' => false,
]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function testCreateIncidentWithTemplate()
public function test_can_create_incident_with_template()
{
$template = factory('CachetHQ\Cachet\Models\IncidentTemplate')->create();
$template = factory(IncidentTemplate::class)->create();
$this->beUser();
$this->post('/api/v1/incidents', [
$this->expectsEvents(IncidentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/incidents', [
'name' => 'Foo',
'status' => 1,
'visible' => 1,
@@ -100,66 +124,97 @@ class IncidentTest extends AbstractApiTestCase
'message' => 'Hello there this is a foo!',
],
]);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Foo',
'message' => "Name: Foo,\nMessage: Hello there this is a foo!",
]);
}
public function testGetNewIncident()
public function test_can_get_newly_created_incident()
{
$incident = factory('CachetHQ\Cachet\Models\Incident')->create();
$incident = factory(Incident::class)->create();
$this->get('/api/v1/incidents/1');
$this->seeJsonContains(['name' => $incident->name]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/incidents/1');
$response->assertStatus(200);
$response->assertJsonFragment(['name' => $incident->name]);
}
public function testPutIncident()
public function test_can_update_incident()
{
$this->beUser();
$component = factory('CachetHQ\Cachet\Models\Incident')->create();
$incident = factory(Incident::class)->create();
$this->put('/api/v1/incidents/1', [
$this->expectsEvents(IncidentWasUpdatedEvent::class);
$response = $this->json('PUT', '/api/v1/incidents/1', [
'name' => 'Foo',
]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function testPutIncidentWithTemplate()
public function test_can_update_incident_with_template()
{
$this->beUser();
$template = factory('CachetHQ\Cachet\Models\IncidentTemplate')->create([
$template = factory(IncidentTemplate::class)->create([
'template' => 'Hello there this is a foo in my {{ incident.name }}!',
]);
$component = factory('CachetHQ\Cachet\Models\Incident')->create();
$incident = factory(Incident::class)->create();
$this->put('/api/v1/incidents/1', [
$this->expectsEvents(IncidentWasUpdatedEvent::class);
$response = $this->json('PUT', '/api/v1/incidents/1', [
'name' => 'Foo',
'template' => $template->slug,
]);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Foo',
'message' => 'Hello there this is a foo in my Foo!',
]);
$this->assertResponseOk();
}
public function testDeleteIncident()
public function test_can_update_incident_when_no_user_is_associated()
{
$incident = factory(Incident::class)->create(['user_id' => null]);
$this->beUser();
$this->expectsEvents(IncidentWasUpdatedEvent::class);
$response = $this->json('PUT', '/api/v1/incidents/1', [
'name' => 'Updated incident name',
]);
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Updated incident name',
'user_id' => null,
]);
}
public function test_can_delete_incident()
{
$this->beUser();
$component = factory('CachetHQ\Cachet\Models\Incident')->create();
$incident = factory(Incident::class)->create();
$this->delete('/api/v1/incidents/1');
$this->assertResponseStatus(204);
$this->expectsEvents(IncidentWasRemovedEvent::class);
$response = $this->json('DELETE', '/api/v1/incidents/1');
$response->assertStatus(204);
}
public function testCreateIncidentWithMeta()
public function test_can_create_incident_with_meta_data()
{
$this->beUser();
$this->post('/api/v1/incidents', [
$this->expectsEvents(IncidentWasCreatedEvent::class);
$response = $this->json('POST', '/api/v1/incidents', [
'name' => 'Foo',
'message' => 'Lorem ipsum dolor sit amet',
'status' => 1,
@@ -167,11 +222,12 @@ class IncidentTest extends AbstractApiTestCase
'id' => 123456789,
],
]);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'meta' => [
'id' => 123456789,
],
]);
$this->assertResponseOk();
}
}

View File

@@ -11,6 +11,9 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentUpdate;
/**
* This is the incident update test class.
*
@@ -18,85 +21,84 @@ namespace CachetHQ\Tests\Cachet\Api;
*/
class IncidentUpdateTest extends AbstractApiTestCase
{
public function testGetIncidentUpdates()
public function test_can_get_all_incident_updates()
{
$incident = factory('CachetHQ\Cachet\Models\Incident')->create();
$updates = factory('CachetHQ\Cachet\Models\IncidentUpdate', 3)->create([
$incident = factory(Incident::class)->create();
$updates = factory(IncidentUpdate::class, 3)->create([
'incident_id' => $incident->id,
]);
$this->get("/api/v1/incidents/{$incident->id}/updates");
$response = $this->json('GET', "/api/v1/incidents/{$incident->id}/updates");
$this->assertResponseOk();
$response->assertStatus(200);
$this->seeJsonContains(['id' => $updates[0]->id]);
$this->seeJsonContains(['id' => $updates[1]->id]);
$this->seeJsonContains(['id' => $updates[2]->id]);
$response->assertJsonFragment(['id' => $updates[0]->id]);
$response->assertJsonFragment(['id' => $updates[1]->id]);
$response->assertJsonFragment(['id' => $updates[2]->id]);
}
public function testGetInvalidIncidentUpdate()
public function test_cannot_get_invalid_incident_update()
{
$this->get('/api/v1/incidents/1/updates/1');
$response = $this->json('GET', '/api/v1/incidents/1/updates/1');
$this->assertResponseStatus(404);
$response->assertStatus(404);
}
public function testPostIncidentUpdateUnauthorized()
public function test_cannot_create_incident_update_without_authorization()
{
$incident = factory('CachetHQ\Cachet\Models\Incident')->create();
$this->post("/api/v1/incidents/{$incident->id}/updates");
$incident = factory(Incident::class)->create();
$this->assertResponseStatus(401);
$response = $this->json('POST', "/api/v1/incidents/{$incident->id}/updates");
$response->assertStatus(401);
}
public function testPostIncidentUpdateNoData()
public function test_cannot_create_incident_update_without_data()
{
$this->beUser();
$incident = factory('CachetHQ\Cachet\Models\Incident')->create();
$incident = factory(Incident::class)->create();
$this->post("/api/v1/incidents/{$incident->id}/updates");
$response = $this->json('POST', "/api/v1/incidents/{$incident->id}/updates");
$this->assertResponseStatus(400);
$response->assertStatus(400);
}
public function testPostIncidentUpdate()
public function test_can_create_incident_update()
{
$this->beUser();
$incident = factory('CachetHQ\Cachet\Models\Incident')->create();
$incident = factory(Incident::class)->create();
$this->post("/api/v1/incidents/{$incident->id}/updates", [
$response = $this->json('POST', "/api/v1/incidents/{$incident->id}/updates", [
'status' => 4,
'message' => 'Incident fixed!',
]);
$this->assertResponseOk();
$this->seeJsonContains(['incident_id' => $incident->id]);
$response->assertStatus(200);
$response->assertJsonFragment(['incident_id' => $incident->id]);
}
public function testPutIncidentUpdate()
public function test_can_update_incident_update()
{
$this->beUser();
$incident = factory('CachetHQ\Cachet\Models\Incident')->create();
$update = factory('CachetHQ\Cachet\Models\IncidentUpdate')->create();
$incident = factory(Incident::class)->create();
$update = factory(IncidentUpdate::class)->create();
$this->put("/api/v1/incidents/{$incident->id}/updates/{$update->id}", [
$response = $this->json('PUT', "/api/v1/incidents/{$incident->id}/updates/{$update->id}", [
'message' => 'Message updated :smile:',
]);
$this->assertResponseOk();
$this->seeJsonContains(['message' => 'Message updated :smile:']);
$response->assertStatus(200);
$response->assertJsonFragment(['message' => 'Message updated :smile:']);
}
public function testDeleteIncidentUpdate()
public function test_can_delete_incident_update()
{
$this->beUser();
$incident = factory('CachetHQ\Cachet\Models\Incident')->create();
$update = factory('CachetHQ\Cachet\Models\IncidentUpdate')->create();
$incident = factory(Incident::class)->create();
$update = factory(IncidentUpdate::class)->create();
$this->delete("/api/v1/incidents/{$incident->id}/updates/{$update->id}");
$response = $this->json('DELETE', "/api/v1/incidents/{$incident->id}/updates/{$update->id}");
$this->assertResponseStatus(204);
$response->assertStatus(204);
}
}

View File

@@ -11,6 +11,8 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
use Carbon\Carbon;
/**
@@ -21,72 +23,69 @@ use Carbon\Carbon;
*/
class MetricPointTest extends AbstractApiTestCase
{
public function testGetMetricPoint()
public function test_can_get_all_metric_points()
{
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint', 3)->create([
$metric = factory(Metric::class)->create();
$metricPoint = factory(MetricPoint::class, 3)->create([
'metric_id' => $metric->id,
]);
$this->get("/api/v1/metrics/{$metric->id}/points");
$response = $this->json('GET', "/api/v1/metrics/{$metric->id}/points");
$this->seeJsonContains(['id' => $metricPoint[0]->id]);
$this->seeJsonContains(['id' => $metricPoint[1]->id]);
$this->seeJsonContains(['id' => $metricPoint[2]->id]);
$response->assertJsonFragment(['id' => $metricPoint[0]->id]);
$response->assertJsonFragment(['id' => $metricPoint[1]->id]);
$response->assertJsonFragment(['id' => $metricPoint[2]->id]);
$this->assertResponseOk();
$response->assertStatus(200);
}
public function testPostMetricPointUnauthorized()
public function test_cannot_create_metric_point_without_authorization()
{
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([
$metric = factory(Metric::class)->create();
$metricPoint = factory(MetricPoint::class)->create([
'metric_id' => $metric->id,
]);
$this->post("/api/v1/metrics/{$metric->id}/points");
$response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points");
$this->assertResponseStatus(401);
$response->assertStatus(401);
}
public function testPostMetricPoint()
public function test_can_create_metric_point()
{
$this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([
$metric = factory(Metric::class)->create();
$metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id,
]);
$this->post("/api/v1/metrics/{$metric->id}/points", $metricPoint->toArray());
$this->seeJsonContains(['value' => $metricPoint->value]);
$this->assertResponseOk();
$response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $metricPoint->toArray());
$response->assertStatus(200);
$response->assertJsonFragment(['value' => $metricPoint->value]);
}
public function testPostMetricPointTimestamp()
public function test_can_create_metric_point_with_timestamp()
{
$this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$timestamp = 1434369116;
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([
$metric = factory(Metric::class)->create();
$timestamp = strtotime('now');
$metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id,
]);
$postData = $metricPoint->toArray();
$postData['timestamp'] = $timestamp;
$this->post("/api/v1/metrics/{$metric->id}/points", $postData);
$response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'value' => $metricPoint->value,
'created_at' => date('Y-m-d H:i:s', 1434369116),
'created_at' => date('Y-m-d H:i:s', $timestamp),
]);
$this->assertResponseOk();
}
public function testPostMetricPointTimestampTimezone()
public function test_can_create_metric_point_with_timestamp_timezone()
{
$this->beUser();
@@ -94,48 +93,46 @@ class MetricPointTest extends AbstractApiTestCase
Carbon::setTestNow(Carbon::now());
$timezone = 'America/Mexico_City';
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$metric = factory(Metric::class)->create();
$datetime = Carbon::now()->timezone($timezone);
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([
$metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id,
]);
$postData = $metricPoint->toArray();
$postData['timestamp'] = $datetime->timestamp;
$this->post("/api/v1/metrics/{$metric->id}/points", $postData, ['Time-Zone' => $timezone]);
$response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData, ['Time-Zone' => $timezone]);
$this->seeJsonContains(['value' => $metricPoint->value, 'created_at' => $datetime->toDateTimeString()]);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['value' => $metricPoint->value, 'created_at' => $datetime->toDateTimeString()]);
}
public function testPutMetricPoint()
public function test_can_update_metric_point()
{
$this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([
$metric = factory(Metric::class)->create();
$metricPoint = factory(MetricPoint::class)->create([
'metric_id' => $metric->id,
]);
$this->put("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}", [
$response = $this->json('PUT', "/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}", [
'value' => 999,
]);
$this->seeJsonContains(['value' => 999]);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['value' => 999]);
}
public function testDeleteMetricPoint()
public function test_can_delete_metric_point()
{
$this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([
$metric = factory(Metric::class)->create();
$metricPoint = factory(MetricPoint::class)->create([
'metric_id' => $metric->id,
]);
$this->delete("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}");
$response = $this->json('DELETE', "/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}");
$this->assertResponseStatus(204);
$response->assertStatus(204);
}
}

View File

@@ -11,6 +11,8 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Metric;
/**
* This is the metric test class.
*
@@ -19,42 +21,43 @@ namespace CachetHQ\Tests\Cachet\Api;
*/
class MetricTest extends AbstractApiTestCase
{
public function testGetMetrics()
public function test_can_get_all_metrics()
{
$metrics = factory('CachetHQ\Cachet\Models\Metric', 3)->create();
$metrics = factory(Metric::class, 3)->create();
$this->get('/api/v1/metrics');
$this->seeJsonContains(['id' => $metrics[0]->id]);
$this->seeJsonContains(['id' => $metrics[1]->id]);
$this->seeJsonContains(['id' => $metrics[2]->id]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/metrics');
$response->assertJsonFragment(['id' => $metrics[0]->id]);
$response->assertJsonFragment(['id' => $metrics[1]->id]);
$response->assertJsonFragment(['id' => $metrics[2]->id]);
$response->assertStatus(200);
}
public function testGetInvalidMetric()
public function test_cannot_get_invalid_metric()
{
$this->get('/api/v1/metrics/0');
$this->assertResponseStatus(404);
$response = $this->json('GET', '/api/v1/metrics/0');
$response->assertStatus(404);
}
public function testPostMetricUnauthorized()
public function test_cannot_create_metric_without_authorization()
{
$this->post('/api/v1/metrics');
$this->assertResponseStatus(401);
$response = $this->json('POST', '/api/v1/metrics');
$response->assertStatus(401);
}
public function testPostMetricNoData()
public function test_cannot_create_metric_without_data()
{
$this->beUser();
$this->post('/api/v1/metrics');
$this->assertResponseStatus(400);
$response = $this->json('POST', '/api/v1/metrics');
$response->assertStatus(400);
}
public function testPostMetric()
public function test_can_create_metric()
{
$this->beUser();
$this->post('/api/v1/metrics', [
$response = $this->json('POST', '/api/v1/metrics', [
'name' => 'Foo',
'suffix' => 'foo\'s per second',
'description' => 'Lorem ipsum dolor',
@@ -65,38 +68,42 @@ class MetricTest extends AbstractApiTestCase
'threshold' => 5,
'order' => 1,
]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function testGetNewMetric()
public function test_can_get_newly_created_metric()
{
$incident = factory('CachetHQ\Cachet\Models\Metric')->create();
$incident = factory(Metric::class)->create();
$this->get('/api/v1/metrics/1');
$this->seeJsonContains(['name' => $incident->name]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/metrics/1');
$response->assertStatus(200);
$response->assertJsonFragment(['name' => $incident->name]);
}
public function testPutMetric()
public function test_can_update_metric()
{
$this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$metric = factory(Metric::class)->create();
$this->put('/api/v1/metrics/1', [
$response = $this->json('PUT', '/api/v1/metrics/1', [
'name' => 'Foo',
'view' => 2,
]);
$this->seeJsonContains(['name' => 'Foo', 'default_view' => 2]);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'default_view' => 2]);
}
public function testDeleteMetric()
public function test_can_delete_metric()
{
$this->beUser();
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$metric = factory(Metric::class)->create();
$this->delete('/api/v1/metrics/1');
$this->assertResponseStatus(204);
$response = $this->json('DELETE', '/api/v1/metrics/1');
$response->assertStatus(204);
}
}

View File

@@ -11,6 +11,8 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Schedule;
/**
* This is the schedule test class.
*
@@ -18,31 +20,29 @@ namespace CachetHQ\Tests\Cachet\Api;
*/
class ScheduleTest extends AbstractApiTestCase
{
public function testGetSchedules()
public function test_can_get_all_schedules()
{
$schedules = factory('CachetHQ\Cachet\Models\Schedule', 3)->create();
$schedules = factory(Schedule::class, 3)->create();
$this->get('/api/v1/schedules');
$response = $this->json('GET', '/api/v1/schedules');
$this->assertResponseOk();
$this->seeJsonContains(['id' => $schedules[0]->id]);
$this->seeJsonContains(['id' => $schedules[1]->id]);
$this->seeJsonContains(['id' => $schedules[2]->id]);
$response->assertStatus(200);
$response->assertJsonFragment(['id' => $schedules[0]->id]);
$response->assertJsonFragment(['id' => $schedules[1]->id]);
$response->assertJsonFragment(['id' => $schedules[2]->id]);
}
public function testGetSchedule()
public function test_can_get_single_schedule()
{
$schedule = factory('CachetHQ\Cachet\Models\Schedule')->create();
$schedule = factory(Schedule::class)->create();
$this->get('/api/v1/schedules/'.$schedule->id);
$response = $this->json('GET', '/api/v1/schedules/'.$schedule->id);
$this->assertResponseOk();
$this->seeJsonContains(['name' => $schedule->name]);
$response->assertStatus(200);
$response->assertJsonFragment(['name' => $schedule->name]);
}
public function testCreateSchedule()
public function test_can_create_schedule()
{
$this->beUser();
@@ -53,36 +53,35 @@ class ScheduleTest extends AbstractApiTestCase
'scheduled_at' => date('Y-m-d H:i'),
];
$this->post('/api/v1/schedules/', $schedule);
$response = $this->json('POST', '/api/v1/schedules/', $schedule);
array_forget($schedule, 'scheduled_at');
$this->assertResponseOk();
$this->seeJsonContains($schedule);
$response->assertStatus(200);
$response->assertJsonFragment($schedule);
}
public function testUpdateSchedule()
public function test_can_update_schedule()
{
$this->beUser();
$schedule = factory('CachetHQ\Cachet\Models\Schedule')->create();
$schedule = factory(Schedule::class)->create();
$this->put('/api/v1/schedules/'.$schedule->id, [
$response = $this->json('PUT', '/api/v1/schedules/'.$schedule->id, [
'name' => 'Updated schedule',
]);
$this->assertResponseOk();
$this->seeJsonContains(['name' => 'Updated schedule']);
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Updated schedule']);
}
public function testDeleteSchedule()
public function test_can_delete_schedule()
{
$this->beUser();
factory('CachetHQ\Cachet\Models\Schedule')->create();
factory(Schedule::class)->create();
$this->delete('/api/v1/schedules/1');
$response = $this->json('DELETE', '/api/v1/schedules/1');
$this->assertResponseStatus(204);
$response->assertStatus(204);
}
}

View File

@@ -11,6 +11,10 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Bus\Events\Subscriber\SubscriberHasSubscribedEvent;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Models\Subscription;
use Illuminate\Support\Facades\Notification;
/**
@@ -21,97 +25,104 @@ use Illuminate\Support\Facades\Notification;
*/
class SubscriberTest extends AbstractApiTestCase
{
public function testGetSubscribersUnauthenticated()
{
$this->get('/api/v1/subscribers');
$this->assertResponseStatus(401);
$this->seeHeader('Content-Type', 'application/json');
}
public function testGetSubscribers()
public function test_can_get_all_subscribers()
{
$this->beUser();
$subscriber = factory('CachetHQ\Cachet\Models\Subscriber')->create();
$subscriber = factory(Subscriber::class)->create();
$this->get('/api/v1/subscribers');
$this->seeHeader('Content-Type', 'application/json');
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/subscribers');
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/json');
}
public function testCreateSubscriber()
public function test_cannot_get_subscribers_without_authorization()
{
$response = $this->json('GET', '/api/v1/subscribers');
$response->assertStatus(401);
$response->assertHeader('Content-Type', 'application/json');
}
public function test_can_create_subscriber()
{
$this->beUser();
Notification::fake();
$this->expectsEvents('CachetHQ\Cachet\Bus\Events\Subscriber\SubscriberHasSubscribedEvent');
$this->expectsEvents(SubscriberHasSubscribedEvent::class);
$this->post('/api/v1/subscribers', [
$response = $this->json('POST', '/api/v1/subscribers', [
'email' => 'support@alt-three.com',
]);
$this->assertResponseOk();
$this->seeHeader('Content-Type', 'application/json');
$this->seeJsonContains(['email' => 'support@alt-three.com']);
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/json');
$response->assertJsonFragment(['email' => 'support@alt-three.com']);
}
public function testCreateSubscriberAutoVerified()
public function test_can_create_subscriber_automatically_verified()
{
$this->beUser();
Notification::fake();
$this->expectsEvents('CachetHQ\Cachet\Bus\Events\Subscriber\SubscriberHasSubscribedEvent');
$this->expectsEvents(SubscriberHasSubscribedEvent::class);
$this->post('/api/v1/subscribers', [
$response = $this->json('POST', '/api/v1/subscribers', [
'email' => 'support@alt-three.com',
'verify' => true,
]);
$this->assertResponseOk();
$this->seeHeader('Content-Type', 'application/json');
$this->seeJsonContains(['email' => 'support@alt-three.com']);
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/json');
$response->assertJsonFragment(['email' => 'support@alt-three.com']);
}
public function testCreateSubscriberWithSubscriptions()
public function test_can_create_subscriber_with_subscription()
{
$this->beUser();
factory('CachetHQ\Cachet\Models\Component', 3)->create();
factory(Component::class, 3)->create();
$this->post('/api/v1/subscribers', [
'email' => 'support@alt-three.com',
'verify' => true,
'components' => [
$response = $this->json('POST', '/api/v1/subscribers', [
'email' => 'support@alt-three.com',
'verify' => true,
'components' => [
1,
3,
],
]);
$this->assertResponseOk();
$this->seeHeader('Content-Type', 'application/json');
$this->seeJsonContains(['email' => 'support@alt-three.com']);
$this->seeJsonStructure(['data' => ['subscriptions' => []]]);
$data = $this->decodeResponseJson();
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/json');
$response->assertJsonFragment(['email' => 'support@alt-three.com']);
$data = $response->decodeResponseJson();
$this->assertCount(2, $data['data']['subscriptions']);
$this->assertEquals(1, $data['data']['subscriptions'][0]['component_id']);
$this->assertEquals(3, $data['data']['subscriptions'][1]['component_id']);
}
public function testDeleteSubscriber()
public function test_can_delete_subscriber()
{
$this->beUser();
$subscriber = factory('CachetHQ\Cachet\Models\Subscriber')->create();
$this->delete("/api/v1/subscribers/{$subscriber->id}");
$this->assertResponseStatus(204);
$subscriber = factory(Subscriber::class)->create();
$response = $this->json('DELETE', "/api/v1/subscribers/{$subscriber->id}");
$response->assertStatus(204);
}
public function testDeleteSubscription()
public function test_can_delete_subscription()
{
$this->beUser();
$subscription = factory('CachetHQ\Cachet\Models\Subscription')->create();
$this->delete("/api/v1/subscriptions/{$subscription->id}");
$this->assertResponseStatus(204);
$subscription = factory(Subscription::class)->create();
$response = $this->json('DELETE', "/api/v1/subscriptions/{$subscription->id}");
$response->assertStatus(204);
}
}

View File

@@ -12,12 +12,13 @@
namespace CachetHQ\Tests\Cachet\Bus\Commands;
use AltThree\TestBench\ExistenceTrait;
use PHPUnit_Framework_TestCase as TestCase;
use PHPUnit\Framework\TestCase;
/**
* This is the command existence test class.
*
* @author Graham Campbell <graham@alt-three.com>
* @author James Brooks <james@alt-three.com>
*/
class CommandExistenceTest extends TestCase
{

View File

@@ -0,0 +1,54 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Bus\Commands\Tag;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\Tag\ApplyTagCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\Tag\ApplyTagCommandHandler;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Tag;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the apply tag command test class.
*
* @author James Brooks <james@alt-three.com>
*/
class ApplyTagCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = [
'model' => new Component(),
'tag' => new Tag(),
];
$object = new ApplyTagCommand(
$params['model'],
$params['tag']
);
return compact('params', 'object');
}
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass()
{
return ApplyTagCommandHandler::class;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Bus\Commands\Tag;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\Tag\CreateTagCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\Tag\CreateTagCommandHandler;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the create tag command test class.
*
* @author James Brooks <james@alt-three.com>
*/
class CreateTagCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = [
'name' => 'Test',
'slug' => 'test',
];
$object = new CreateTagCommand(
$params['name'],
$params['slug']
);
return compact('params', 'object');
}
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass()
{
return CreateTagCommandHandler::class;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Bus\Commands\Tag;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\Tag\DeleteTagCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\Tag\DeleteTagCommandHandler;
use CachetHQ\Cachet\Models\Tag;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the delete tag command test class.
*
* @author James Brooks <james@alt-three.com>
*/
class DeleteTagCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = [
'tag' => new Tag(),
];
$object = new DeleteTagCommand(
$params['tag']
);
return compact('params', 'object');
}
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass()
{
return DeleteTagCommandHandler::class;
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Bus\Commands\Tag;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\Tag\UpdateTagCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\Tag\UpdateTagCommandHandler;
use CachetHQ\Cachet\Models\Tag;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the update tag command test class.
*
* @author James Brooks <james@alt-three.com>
*/
class UpdateTagCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = [
'tag' => new Tag(),
'name' => 'Test',
'slug' => 'test',
];
$object = new UpdateTagCommand(
$params['tag'],
$params['name'],
$params['slug']
);
return compact('params', 'object');
}
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass()
{
return UpdateTagCommandHandler::class;
}
}

View File

@@ -12,7 +12,7 @@
namespace CachetHQ\Tests\Cachet\Bus\Events;
use AltThree\TestBench\ExistenceTrait;
use PHPUnit_Framework_TestCase as TestCase;
use PHPUnit\Framework\TestCase;
/**
* This is the event existence test class.

View File

@@ -12,7 +12,7 @@
namespace CachetHQ\Tests\Cachet\Bus\Jobs;
use AltThree\TestBench\ExistenceTrait;
use PHPUnit_Framework_TestCase as TestCase;
use PHPUnit\Framework\TestCase;
/**
* This is the job existence test class.

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet;
use Illuminate\Contracts\Console\Kernel;
/**
* This is the creates application trait.
*
* @author James Brooks <james@alt-three.com>
*/
trait CreatesApplicationTrait
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
return $app;
}
}

View File

@@ -13,13 +13,29 @@ namespace CachetHQ\Tests\Cachet\Foundation\Providers;
use AltThree\TestBench\EventServiceProviderTrait;
use CachetHQ\Tests\Cachet\AbstractTestCase;
use Illuminate\Support\ServiceProvider;
use ReflectionClass;
/**
* This is the event service provider test class.
*
* @author Graham Campbell <graham@alt-three.com>
* @author James Brooks <james@alt-three.com>
*/
class EventServiceProviderTest extends AbstractTestCase
{
use EventServiceProviderTrait;
public function testIsAnEventServiceProvider()
{
$class = $this->getServiceProviderClass($this->app);
$reflection = new ReflectionClass($class);
$provider = new ReflectionClass(ServiceProvider::class);
$msg = "Expected class '$class' to be a service provider.";
$this->assertTrue($reflection->isSubclassOf($provider), $msg);
}
}

View File

@@ -1,25 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Foundation\Providers;
use AltThree\TestBench\ServiceProviderTrait;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the composer service provider test class.
*
* @author Connor S. Parks <connor@connorvg.tv>
*/
class ModuleServiceProviderTest extends AbstractTestCase
{
use ServiceProviderTrait;
}

View File

@@ -12,7 +12,12 @@
namespace CachetHQ\Tests\Cachet\Foundation\Providers;
use AltThree\TestBench\ServiceProviderTrait;
use CachetHQ\Cachet\Foundation\Providers\RouteServiceProvider;
use CachetHQ\Cachet\Http\Middleware\Authenticate;
use CachetHQ\Tests\Cachet\AbstractTestCase;
use Illuminate\Routing\Route;
use Illuminate\Routing\RouteCollection;
use Illuminate\Routing\Router;
/**
* This is the route service provider test class.
@@ -22,4 +27,195 @@ use CachetHQ\Tests\Cachet\AbstractTestCase;
class RouteServiceProviderTest extends AbstractTestCase
{
use ServiceProviderTrait;
/**
* The login routes should always be available regardless of the always authenticate setting.
*/
public function testWhenAlwaysAuthenticateIsEnabledLoginRoutesAreWhiteListed()
{
$loginRoutes = [
'core::get:auth.login',
'core::post:auth.login',
'core::post:auth.two-factor',
'core::get:auth.logout',
'core::get:signup.invite',
'core::post:signup.invite',
];
$this->assertRoutesDontHaveAuthMiddleware($loginRoutes, $this->bootRouter(true));
}
/**
* The setup routes should always be available regardless of the always authenticate setting.
*/
public function testWhenAlwaysAuthenticateIsEnabledSetupRoutesAreWhiteListed()
{
$loginRoutes = [
'core::get:setup',
'core::post:setup.step1',
'core::post:setup.step2',
'core::post:setup.step3',
];
$this->assertRoutesDontHaveAuthMiddleware($loginRoutes, $this->bootRouter(true));
}
/**
* It's possible to retrieve the cachet version, status and ping endpoints regardless of the
* always authenticate setting.
*/
public function testWhenAlwaysAuthenticateIsEnabledApiSystemRoutesAreWhiteListed()
{
$routeActions = [
'CachetHQ\Cachet\Http\Controllers\Api\GeneralController@ping',
'CachetHQ\Cachet\Http\Controllers\Api\GeneralController@version',
'CachetHQ\Cachet\Http\Controllers\Api\GeneralController@status',
];
$router = $this->bootRouter(true);
foreach ($routeActions as $routeAction) {
$route = $router->getRoutes()->getByAction($routeAction);
$this->assertInstanceOf(Route::class, $route);
$middleware = $route->gatherMiddleware();
$this->assertFalse(in_array('auth.api:true', $middleware, true));
}
}
/**
* When using always authenticate, normal graceful api routes will require full authentication.
*/
public function testWhenAlwaysAuthenticateIsEnabledApiRoutesAreHardAuthenticated()
{
$routeActions = [
'CachetHQ\Cachet\Http\Controllers\Api\ComponentController@index',
'CachetHQ\Cachet\Http\Controllers\Api\ComponentGroupController@index',
'CachetHQ\Cachet\Http\Controllers\Api\ComponentGroupController@show',
'CachetHQ\Cachet\Http\Controllers\Api\ComponentController@show',
'CachetHQ\Cachet\Http\Controllers\Api\IncidentController@index',
'CachetHQ\Cachet\Http\Controllers\Api\IncidentController@show',
'CachetHQ\Cachet\Http\Controllers\Api\IncidentUpdateController@index',
'CachetHQ\Cachet\Http\Controllers\Api\IncidentUpdateController@show',
'CachetHQ\Cachet\Http\Controllers\Api\MetricController@index',
'CachetHQ\Cachet\Http\Controllers\Api\MetricController@show',
'CachetHQ\Cachet\Http\Controllers\Api\MetricPointController@index',
'CachetHQ\Cachet\Http\Controllers\Api\ScheduleController@index',
'CachetHQ\Cachet\Http\Controllers\Api\ScheduleController@show',
];
$router = $this->bootRouter(true);
foreach ($routeActions as $routeAction) {
$route = $router->getRoutes()->getByAction($routeAction);
$this->assertInstanceOf(Route::class, $route);
$middleware = $route->gatherMiddleware();
$this->assertTrue(in_array('auth.api:true', $middleware, true));
}
}
/**
* When enabling the always authenticate setting, the core frontpage routes require authentication.
*/
public function testWhenAlwaysAuthenticateIsEnabledAllNormalRoutesAreAuthenticated()
{
$namedRoutes = [
'core::get:status-page',
'core::get:incident',
'core::get:schedule',
'core::get:metric',
'core::get:component_shield',
'core::get:feed.atom',
'core::get:feed.rss',
'core::get:subscribe',
'core::post:subscribe',
'core::get:subscribe.manage',
'core::post:subscribe.manage',
'core::get:subscribe.verify',
'core::get:subscribe.unsubscribe',
];
$this->assertRoutesHaveAuthMiddleware($namedRoutes, $this->bootRouter(true));
}
/**
* This test asserts that when always authenticate is disabled, you are allowed to visit the frontpage
* routes without enforced authentication.
*/
public function testWhenAlwaysAuthenticateIsDisabledAllNormalRoutesAreUnauthenticated()
{
$namedRoutes = [
'core::get:status-page',
'core::get:incident',
'core::get:schedule',
'core::get:metric',
'core::get:component_shield',
'core::get:feed.atom',
'core::get:feed.rss',
'core::get:subscribe',
'core::post:subscribe',
'core::get:subscribe.manage',
'core::post:subscribe.manage',
'core::get:subscribe.verify',
'core::get:subscribe.unsubscribe',
];
$this->assertRoutesDontHaveAuthMiddleware($namedRoutes, $this->bootRouter(false));
}
/**
* A helper method that will execute the RouteProvider's map function and return a clean router.
*
* @param bool $alwaysAuthenticate
*
* @return Router
*/
private function bootRouter($alwaysAuthenticate)
{
$this->app->config->set('setting.always_authenticate', $alwaysAuthenticate);
$router = $this->app->make(Router::class);
$router->setRoutes(new RouteCollection());
$routeServiceProvider = new RouteServiceProvider($this->app);
$routeServiceProvider->map($router);
return $router;
}
/**
* Assertion helper that asserts if the authentication middleware has not been injected onto
* the collection of named routes.
*
* @param array $routeNames
* @param Router $router
*/
private function assertRoutesDontHaveAuthMiddleware(array $routeNames, Router $router)
{
foreach ($routeNames as $routeName) {
$route = $router->getRoutes()->getByName($routeName);
$this->assertInstanceOf(Route::class, $route);
$middleware = $route->gatherMiddleware();
$this->assertFalse(in_array(Authenticate::class, $middleware, true));
}
}
/**
* Assertion helper that asserts if the authentication middleware has been injected onto
* the collection of named routes.
*
* @param array $routeNames
* @param Router $router
*/
private function assertRoutesHaveAuthMiddleware(array $routeNames, Router $router)
{
foreach ($routeNames as $routeName) {
$route = $router->getRoutes()->getByName($routeName);
$this->assertInstanceOf(Route::class, $route);
$middleware = $route->gatherMiddleware();
$this->assertTrue(in_array(Authenticate::class, $middleware, true));
}
}
}

View File

@@ -12,12 +12,13 @@
namespace CachetHQ\Tests\Cachet\Models;
use AltThree\TestBench\ExistenceTrait;
use PHPUnit_Framework_TestCase as TestCase;
use PHPUnit\Framework\TestCase;
/**
* This is the model existence test class.
*
* @author Graham Campbell <graham@alt-three.com>
* @author James Brooks <james@alt-three.com>
*/
class ModelExistenceTest extends TestCase
{

View File

@@ -0,0 +1,31 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Models;
use AltThree\TestBench\ValidationTrait;
use CachetHQ\Cachet\Models\Taggable;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the taggable model test class.
*
* @author James Brooks <james@alt-three.com>
*/
class TaggableTest extends AbstractTestCase
{
use ValidationTrait;
public function testValidation()
{
$this->checkRules(new Taggable());
}
}

View File

@@ -1,166 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Services\Modules;
use CachetHQ\Tests\Cachet\AbstractTestCase;
use Mockery as m;
/**
* This is the modules manager service test class.
*
* @author Connor S. Parks <connor@connorvg.tv>
*/
class ManagerTest extends AbstractTestCase
{
public function testGroupNoModules()
{
$manager = m::mock('CachetHQ\Cachet\Services\Modules\Manager[groupModules]');
$manager->shouldReceive('groupModules')->once()->passthru();
$grouped = $manager->groupModules([]);
$this->assertSame([], $grouped);
}
public function testGroupModulesNoGroups()
{
$manager = m::mock('CachetHQ\Cachet\Services\Modules\Manager[groupModules]');
$manager->shouldReceive('groupModules')->once()->passthru();
$grouped = $manager->groupModules($this->getModules(), []);
$this->assertSame($this->getGroupedModules(), $grouped);
}
public function testGroupModules()
{
$manager = m::mock('CachetHQ\Cachet\Services\Modules\Manager[groupModules]');
$manager->shouldReceive('groupModules')->once()->passthru();
$grouped = $manager->groupModules($this->getModules(), $this->getModuleGroups());
$this->assertSame($this->getGroupedModulesWithOrders(), $grouped);
}
public function testOrderModules()
{
$manager = m::mock('CachetHQ\Cachet\Services\Modules\Manager[orderModules]');
$manager->shouldReceive('orderModules')->once()->passthru();
$ordered = $manager->orderModules($this->getGroupedModules());
$this->assertSame($this->getOrderedModules(), $ordered);
}
public function testOrderModulesWithOrders()
{
$manager = m::mock('CachetHQ\Cachet\Services\Modules\Manager[orderModules]');
$manager->shouldReceive('orderModules')->once()->passthru();
$ordered = $manager->orderModules($this->getGroupedModulesWithOrders());
$this->assertSame($this->getOrderedModulesWithOrders(), $ordered);
}
protected function getModules()
{
return [
['group' => 'two', 'partial' => 'partials.two.a'],
['partial' => 'partials.a', 'order' => 8],
['group' => 'one', 'partial' => 'partials.one.c'],
['partial' => 'partials.c'],
['group' => 'one', 'partial' => 'partials.one.a', 'order' => 1],
['group' => 'one', 'partial' => 'partials.one.b', 'order' => 2],
['partial' => 'partials.b', 'order' => 15],
];
}
protected function getModuleGroups()
{
return [
'one' => 1,
'two' => 2,
];
}
protected function getGroupedModules()
{
return [
'two' => [
['group' => 'two', 'partial' => 'partials.two.a'],
],
[['partial' => 'partials.a', 'order' => 8], 'order' => 8],
'one' => [
['group' => 'one', 'partial' => 'partials.one.c'],
['group' => 'one', 'partial' => 'partials.one.a', 'order' => 1],
['group' => 'one', 'partial' => 'partials.one.b', 'order' => 2],
],
[['partial' => 'partials.c'], 'order' => PHP_INT_MAX - 4],
[['partial' => 'partials.b', 'order' => 15], 'order' => 15],
];
}
protected function getGroupedModulesWithOrders()
{
return [
'two' => [
['group' => 'two', 'partial' => 'partials.two.a'],
'order' => 2,
],
[['partial' => 'partials.a', 'order' => 8], 'order' => 8],
'one' => [
['group' => 'one', 'partial' => 'partials.one.c'],
['group' => 'one', 'partial' => 'partials.one.a', 'order' => 1],
['group' => 'one', 'partial' => 'partials.one.b', 'order' => 2],
'order' => 1,
],
[['partial' => 'partials.c'], 'order' => PHP_INT_MAX - 4],
[['partial' => 'partials.b', 'order' => 15], 'order' => 15],
];
}
protected function getOrderedModules()
{
return [
[['partial' => 'partials.a', 'order' => 8], 'order' => 8],
2 => [['partial' => 'partials.b', 'order' => 15], 'order' => 15],
1 => [['partial' => 'partials.c'], 'order' => PHP_INT_MAX - 4],
'two' => [
['group' => 'two', 'partial' => 'partials.two.a'],
],
'one' => [
1 => ['group' => 'one', 'partial' => 'partials.one.a', 'order' => 1],
2 => ['group' => 'one', 'partial' => 'partials.one.b', 'order' => 2],
0 => ['group' => 'one', 'partial' => 'partials.one.c'],
],
];
}
protected function getOrderedModulesWithOrders()
{
return [
'one' => [
1 => ['group' => 'one', 'partial' => 'partials.one.a', 'order' => 1],
2 => ['group' => 'one', 'partial' => 'partials.one.b', 'order' => 2],
0 => ['group' => 'one', 'partial' => 'partials.one.c'],
'order' => 1,
],
'two' => [
['group' => 'two', 'partial' => 'partials.two.a'],
'order' => 2,
],
[['partial' => 'partials.a', 'order' => 8], 'order' => 8],
2 => [['partial' => 'partials.b', 'order' => 15], 'order' => 15],
1 => [['partial' => 'partials.c'], 'order' => PHP_INT_MAX - 4],
];
}
}

View File

@@ -1,143 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Services\Modules;
use CachetHQ\Tests\Cachet\AbstractTestCase;
use Mockery as m;
/**
* This is the modules renderer service test class.
*
* @author Connor S. Parks <connor@connorvg.tv>
*/
class RendererTest extends AbstractTestCase
{
public function testRenderNoModules()
{
$renderer = m::mock('CachetHQ\Cachet\Services\Modules\Renderer[renderModules]');
$renderer->shouldReceive('renderModules')->once()->passthru();
$output = $renderer->renderModules(
$this->getFactory(),
[],
[],
null
);
$this->assertSame('', $output);
}
public function testRenderNonExistentModulesGroup()
{
$renderer = m::mock('CachetHQ\Cachet\Services\Modules\Renderer[renderModules]');
$renderer->shouldReceive('renderModules')->once()->passthru();
$output = $renderer->renderModules(
$this->getFactory(),
[],
$this->getModules(),
'non-existent group'
);
$this->assertSame('', $output);
}
public function testRenderModules()
{
$renderer = m::mock('CachetHQ\Cachet\Services\Modules\Renderer[renderModules]');
$renderer->shouldReceive('renderModules')->once()->passthru();
$factory = $this->getFactory([
'partial.a', 'partial.b', 'partial.c',
'partial.one.a', 'partial.one.b', 'partial.one.c',
'partial.two.a',
'partial.three.a', 'partial.three.b',
]);
$output = $renderer->renderModules(
$factory,
['a' => 'b', 'c' => 'd'],
$this->getModules(),
null
);
$this->assertSame('partial.apartial.one.apartial.one.bpartial.one.cpartial.two.apartial.bpartial.cpartial.three.apartial.three.b', $output);
}
public function testRenderModuleGroups()
{
$renderer = m::mock('CachetHQ\Cachet\Services\Modules\Renderer[renderModules]');
$renderer->shouldReceive('renderModules')->once()->passthru();
$factory = $this->getFactory([
'partial.one.a', 'partial.one.b', 'partial.one.c',
]);
$output = $renderer->renderModules(
$factory,
['a' => 'b', 'c' => 'd'],
$this->getModules(),
'one'
);
$this->assertSame('partial.one.apartial.one.bpartial.one.c', $output);
}
protected function getModules()
{
return [
'two' => [
'order' => 3,
['partial' => 'partial.two.a'],
],
[
['partial' => 'partial.c'],
['partial' => 'partial.b', 'order' => 1],
],
[
'order' => 1,
['partial' => 'partial.a'],
],
'one' => [
'order' => 2,
['partial' => 'partial.one.c'],
['partial' => 'partial.one.a', 'order' => 1],
['partial' => 'partial.one.b', 'order' => 2],
],
'three' => [
['partial' => 'partial.three.a'],
['partial' => 'partial.three.b'],
],
];
}
protected function getFactory($views = [])
{
$factory = m::mock('Illuminate\View\Factory[make]', $this->getFactoryArgs());
foreach ($views as $view) {
$factory->shouldReceive('make')->once()->with($view, ['a' => 'b', 'c' => 'd'])->andReturn($mockView = m::mock('StdClass'));
$mockView->shouldReceive('render')->once()->andReturn($view);
}
return $factory;
}
protected function getFactoryArgs()
{
return [
m::mock('Illuminate\View\Engines\EngineResolver'),
m::mock('Illuminate\View\ViewFinderInterface'),
m::mock('Illuminate\Contracts\Events\Dispatcher'),
];
}
}

67
tests/SmokeTest.php Normal file
View File

@@ -0,0 +1,67 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Setting;
use Illuminate\Foundation\Testing\DatabaseMigrations;
/**
* This is the smoke test class.
*
* @author James Brooks <james@alt-three.com>
*/
class SmokeTest extends AbstractTestCase
{
use DatabaseMigrations;
public function test_setup_page()
{
$this->get('/setup')->assertStatus(200);
}
public function test_status_page()
{
$this->configureApp();
$this->get('/')->assertStatus(200);
}
public function test_single_component_page()
{
$this->configureApp();
$this->get('/incidents/1')->assertStatus(200);
}
public function test_dashboard_auth_page()
{
$this->configureApp();
$this->get('/auth/login')->assertStatus(200);
}
protected function configureApp()
{
factory(Setting::class)->create([
'name' => 'app_name',
'value' => 'Cachet Test Suite',
]);
$component = factory(Component::class)->create();
$incident = factory(Incident::class)->create([
'component_id' => $component->id,
]);
}
}

View File

@@ -11,24 +11,79 @@
namespace CachetHQ\Tests\Cachet;
use PHPUnit_Framework_BaseTestListener;
use PHPUnit_Framework_TestSuite;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener as PHPUnitTestListener;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
/**
* This is the test listener class.
*
* @author Connor S. Parks <connor@connorvg.tv>
*/
class TestListener extends PHPUnit_Framework_BaseTestListener
class TestListener implements PHPUnitTestListener
{
/**
* A test suite ended.
*
* @param \PHPUnit_Framework_TestSuite $suite
*
* @return void
* An error occurred.
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
public function addError(Test $test, \Throwable $t, float $time): void
{
//
}
/**
* A warning occurred.
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
//
}
/**
* A failure occurred.
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
//
}
/**
* Incomplete test.
*/
public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
{
//
}
/**
* Risky test.
*/
public function addRiskyTest(Test $test, \Throwable $t, float $time): void
{
//
}
/**
* Skipped test.
*/
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
{
//
}
/**
* A test suite started.
*/
public function startTestSuite(TestSuite $suite): void
{
//
}
/**
* A test suite ended.
*/
public function endTestSuite(TestSuite $suite): void
{
if ($suite->getName() !== 'Cachet Test Suite') {
return;
@@ -38,4 +93,20 @@ class TestListener extends PHPUnit_Framework_BaseTestListener
unlink($file);
}
}
/**
* A test started.
*/
public function startTest(Test $test): void
{
//
}
/**
* A test ended.
*/
public function endTest(Test $test, float $time): void
{
//
}
}