2018-07-14 13:22:33 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Auth\User;
|
|
|
|
use App\Models\Common\Company;
|
2021-04-16 00:59:43 +03:00
|
|
|
use Faker\Factory as Faker;
|
2018-07-14 13:22:33 +03:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
abstract class FeatureTestCase extends TestCase
|
|
|
|
{
|
2020-01-13 11:50:38 +03:00
|
|
|
protected $faker;
|
2018-07-14 13:22:33 +03:00
|
|
|
|
2020-01-13 11:50:38 +03:00
|
|
|
protected $user;
|
2018-07-14 13:22:33 +03:00
|
|
|
|
2020-01-13 11:50:38 +03:00
|
|
|
protected $company;
|
2018-07-14 13:22:33 +03:00
|
|
|
|
2020-01-13 11:50:38 +03:00
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2020-01-13 11:50:38 +03:00
|
|
|
$this->withoutExceptionHandling();
|
2019-12-22 18:57:04 +03:00
|
|
|
|
2021-04-16 00:59:43 +03:00
|
|
|
$this->faker = Faker::create();
|
2020-01-13 11:50:38 +03:00
|
|
|
$this->user = User::first();
|
|
|
|
$this->company = $this->user->companies()->first();
|
2019-04-02 18:51:06 +03:00
|
|
|
|
2020-01-13 11:50:38 +03:00
|
|
|
// Disable debugbar
|
|
|
|
config(['debugbar.enabled', false]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty for default user.
|
|
|
|
*
|
|
|
|
* @param User|null $user
|
|
|
|
* @param Company|null $company
|
|
|
|
* @return FeatureTestCase
|
|
|
|
*/
|
|
|
|
public function loginAs(User $user = null, Company $company = null)
|
|
|
|
{
|
|
|
|
if (!$user) {
|
|
|
|
$user = $this->user;
|
|
|
|
}
|
|
|
|
|
2021-04-16 00:59:43 +03:00
|
|
|
if ($company) {
|
|
|
|
$company->makeCurrent();
|
|
|
|
}
|
2020-01-13 11:50:38 +03:00
|
|
|
|
2021-04-17 01:29:18 +03:00
|
|
|
app('url')->defaults(['company_id' => company_id()]);
|
|
|
|
|
2021-04-16 00:59:43 +03:00
|
|
|
return $this->actingAs($user);
|
2020-01-13 11:50:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function assertFlashLevel($excepted)
|
|
|
|
{
|
|
|
|
$flash['level'] = null;
|
|
|
|
|
|
|
|
if ($flashMessage = session('flash_notification')) {
|
|
|
|
$flash = $flashMessage->first();
|
|
|
|
}
|
|
|
|
|
2022-12-01 18:14:00 +03:00
|
|
|
$this->assertEquals($excepted, $flash['level'], json_encode($flash));
|
2020-01-13 11:50:38 +03:00
|
|
|
}
|
2019-03-11 22:56:56 +06:00
|
|
|
}
|