Files
cachet-docker/tests/AbstractTestCase.php
Marius Palade ad0954eb20 Add visibility to component groups (#2027)
Implement visibility for the components groups. Closes #1892

Add functional test that asserts a guest can only see public items.

* Fix tests not running due to hitting the Setup page.

The missing `boostrap/cachet/testing.php` file is now generated the first time tests are ran.

* Add a functional test that asserts logged in users can see all items.

Add constants for possible values for the visible column/field of the ComponentGroup model.
Code review changes.

* Add API tests for component group visibility feature.

* Implement the visibility hidden option for a component group. Fixes #1892.

Add migration for the created_by column, in component_groups table.
Add methods to the ComponentGroup and User models to be able to work with the created_by column.
Hidden component groups are no longer displayed on the index page for loggedin users.
Add functional test for the dashboard page.
Save owner on create/edit component group.
Update the API tests for Component group visibility feature.

* Replace auth() usage with app(Guard::class).

* Apply StyleCI fixes.

* Drop the hidden visibility feature and fix all tests.

Some code review fixes too.

* Rename public to visible since it's a reserved keyword. Apply StyleCI fixes and correct typo.

* Code review changes.

* Tidy up component and component groups gathering.

* Code review changes and StyleCI fixes.

* Code review changes.

* Remove extra whitespace

* Remove useless method.
2016-10-02 13:57:32 +01:00

107 lines
2.2 KiB
PHP

<?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\User;
use CachetHQ\Cachet\Settings\Cache;
use CachetHQ\Cachet\Settings\Repository;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\TestCase;
/**
* This is the abstract test case class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
abstract class AbstractTestCase extends TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
/**
* Test actor.
*
* @var User
*/
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.
*
* @param User|null $user
*
* @return AbstractTestCase
*/
protected function signIn(User $user = null)
{
$this->user = $user ?: $this->createUser();
$this->be($this->user);
return $this;
}
/**
* Create and return a new user.
*
* @param array $properties
*
* @return User
*/
protected function createUser($properties = [])
{
return factory(User::class)->create($properties);
}
/**
* Set up the needed configuration to be able to run the tests.
*
* @return AbstractTestCase
*/
protected function setupConfig()
{
$env = $this->app->environment();
$repo = $this->app->make(Repository::class);
$cache = $this->app->make(Cache::class);
$loaded = $cache->load($env);
if ($loaded === false) {
$loaded = $repo->all();
$cache->store($env, $loaded);
}
$settings = array_merge($this->app->config->get('setting'), $loaded);
$this->app->config->set('setting', $settings);
return $this;
}
}