1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/tests/Integration/UniqueEmailTest.php
David Bomba f745c3f0a6
Working on Social Authentication (#2458)
* Laravel Socialite + Refactor for searching for Users across multiple databases

* Refactor for Unique User Rules, add Middleware for setting active DB connection per request, more tests
2018-10-18 16:04:36 +11:00

67 lines
1.6 KiB
PHP

<?php
namespace Tests\Unit;
use App\Http\ValidationRules\UniqueUserRule;
use App\Models\User;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
/**
* @test
* @covers App\Utils\NumberHelper
*/
class UniqueEmailTest extends TestCase
{
//use InteractsWithDatabase;
//use DatabaseMigrations;
protected $rule;
public function setUp()
{
parent::setUp();
if (config('auth.providers.users.driver') == 'eloquent')
$this->markTestSkipped('Multi DB not enabled - skipping');
DB::connection('db-ninja-1')->table('users')->delete();
DB::connection('db-ninja-2')->table('users')->delete();
$this->rule = new UniqueUserRule();
$user = [
'first_name' => 'user_db_1',
'email' => 'user@example.com',
'password' => Hash::make('password'),
];
User::on('db-ninja-1')->create($user);
User::on('db-ninja-2')->create($user);
}
public function test_unique_emails_detected_on_database()
{
$this->assertFalse($this->rule->passes('email', 'user@example.com'));
}
public function test_no_unique_emails_detected()
{
$this->assertTrue($this->rule->passes('email', 'nohit@example.com'));
}
public function tearDown()
{
DB::connection('db-ninja-1')->table('users')->delete();
DB::connection('db-ninja-2')->table('users')->delete();
}
}