Files
core/tests/php/Repository/UserRepositoryTest.php
FatGuyTyson 955eef4824 Issue [#514](https://github.com/bolt/core/issues/514)
Changed the repository method to accept the credential(string) and has
the storage engine compare the lowercase values. At least this is
consistent to the strings compared so it should be a consistent
experience
2019-09-17 13:40:51 -07:00

47 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Bolt\Tests\Repository;
use Bolt\Entity\User;
use Bolt\Tests\DbAwareTestCase;
class UserRepositoryTest extends DbAwareTestCase
{
protected function setUp(): void
{
parent::setUp();
// fixtures loading takes a lot of time, it would be better to load database dump for tests
self::runCommand('doctrine:fixtures:load --no-interaction --group=without-images');
}
public function testFindOneByUsername()
{
$admin = $this->getEm()->getRepository(User::class)->findOneByUsername('admin');
$this->assertInstanceOf(User::class, $admin);
$administrator = $this->getEm()->getRepository(User::class)->findOneByUsername('administrator');
$this->assertNull($administrator);
}
public function testFindOneByCredentials()
{
$admin = $this->getEm()->getRepository(User::class)->findOneByCredentials('admin');
$this->assertInstanceOf(User::class, $admin);
$adminEmail = $this->getEm()->getRepository(User::class)->findOneByCredentials('admin@example.org');
$this->assertInstanceOf(User::class, $adminEmail);
$janeAdmin = $this->getEm()->getRepository(User::class)->findOneByCredentials('Jane_Admin');
$this->assertInstanceOf(User::class, $janeAdmin);
$janeAdminEmail = $this->getEm()->getRepository(User::class)->findOneByCredentials('Jane_Admin@Example.Org');
$this->assertInstanceOf(User::class, $janeAdminEmail);
$administrator = $this->getEm()->getRepository(User::class)->findOneByCredentials('administrator');
$this->assertNull($administrator);
}
}