Skip to content

Commit

Permalink
test: added tests for AuthHttp class
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Mar 22, 2024
1 parent 66777bb commit b16624c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
4 changes: 2 additions & 2 deletions phpmyfaq/src/phpMyFAQ/Auth/AuthHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public function __construct(Configuration $configuration)
public function create(string $login, string $password, string $domain = ''): bool
{
$user = new User($this->configuration);
$result = $user->createUser($login);
$user->createUser($login);

$user->setStatus('active');
$user->setAuthSource(AuthenticationSourceType::AUTH_HTTP->value);
$user->setUserData(['display_name' => $login]);

return $result;
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ public function setAuthSource(string $authSource): bool
$this->getUserId()
);

return $this->configuration->getDb()->query($update);
return (bool) $this->configuration->getDb()->query($update);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/User/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function save(): bool
Database::getTablePrefix(),
date('YmdHis', $_SERVER['REQUEST_TIME']),
$this->configuration->getDb()->escape($this->data['display_name']),
$this->configuration->getDb()->escape($this->data['email']),
$this->configuration->getDb()->escape($this->data['email'] ?? ''),
$this->data['is_visible'],
$this->data['twofactor_enabled'],
$this->data['secret'],
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
<directory suffix=".php">./phpmyfaq/src/libs</directory>
</exclude>
</source>
<php>
<server name="PHP_AUTH_USER" value="testUser" />
<server name="PHP_AUTH_PW" value="testPassword" />
</php>
</phpunit>
1 change: 1 addition & 0 deletions tests/phpMyFAQ/Auth/AuthDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class AuthDatabaseTest extends TestCase
{
private AuthDatabase $authDatabase;

protected function setUp(): void
{
$this->authDatabase = new AuthDatabase(Configuration::getConfigurationInstance());
Expand Down
53 changes: 53 additions & 0 deletions tests/phpMyFAQ/Auth/AuthHttpTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace phpMyFAQ\Auth;

use phpMyFAQ\Configuration;
use phpMyFAQ\Core\Exception;
use PHPUnit\Framework\TestCase;

class AuthHttpTest extends TestCase
{
private AuthHttp $authHttp;

protected function setUp(): void
{
$this->authHttp = new AuthHttp(Configuration::getConfigurationInstance());
$this->authHttp->selectEncType('sha1');
}

/**
* @throws Exception
*/
public function testCreate(): void
{
$login = 'testUser';
$password = 'testPassword';

$this->assertTrue($this->authHttp->create($login, $password));
}

/**
* @throws Exception
*/
public function testCheckCredentials(): void
{
$login = 'testUser';
$password = 'testPassword';
$this->authHttp->create($login, $password);

$this->assertTrue($this->authHttp->checkCredentials($login, $password));
}

/**
* @throws Exception
*/
public function testIsValidLogin(): void
{
$login = 'testUser';
$password = 'testPassword';
$this->authHttp->create($login, $password);

$this->assertEquals(1, $this->authHttp->isValidLogin($login));
}
}

0 comments on commit b16624c

Please sign in to comment.