2018-07-14 13:22:33 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Auth\User;
|
|
|
|
use App\Models\Common\Company;
|
|
|
|
use Faker\Factory;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
abstract class FeatureTestCase extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Faker\Generator
|
|
|
|
*/
|
|
|
|
protected $faker;
|
|
|
|
|
|
|
|
/** @var User */
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/** @var Company */
|
|
|
|
protected $company;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2018-07-14 13:22:33 +03:00
|
|
|
$this->faker = Factory::create();
|
|
|
|
$this->user = User::first();
|
|
|
|
$this->company = $this->user->first()->companies()->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty for default user.
|
|
|
|
*
|
|
|
|
* @param User|null $user
|
|
|
|
* @param Company|null $company
|
|
|
|
* @return FeatureTestCase
|
|
|
|
*/
|
|
|
|
public function loginAs(User $user = null, Company $company = null)
|
|
|
|
{
|
2018-09-29 17:28:34 +03:00
|
|
|
if (!$user) {
|
|
|
|
$user = $this->user;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$company) {
|
|
|
|
$company = $user->companies()->first();
|
|
|
|
}
|
|
|
|
|
2018-07-14 13:22:33 +03:00
|
|
|
$this->startSession();
|
2018-09-29 17:28:34 +03:00
|
|
|
|
|
|
|
return $this->actingAs($user)->withSession(['company_id' => $company->id]);
|
2018-07-14 13:22:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function assertFlashLevel($excepted)
|
|
|
|
{
|
2018-09-29 17:28:34 +03:00
|
|
|
$flash['level'] = null;
|
|
|
|
|
|
|
|
if ($flashMessage = session('flash_notification')) {
|
2018-07-14 13:22:33 +03:00
|
|
|
$flash = $flashMessage->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals($excepted, $flash['level']);
|
|
|
|
}
|
|
|
|
}
|