Files
FOSSBilling/tests/Modules/Product/ClientTest.php.skip
Belle Aerni a3c3a1ed6e Ensure random passwords meet the requirements (#2145)
I made a mistake when I setup the random password generation for the live tests and forgot that `bin2hex(random_bytes(6));` wasn't guaranteed to actually generate something with a number, this change fixes that to ensure one will be set.
2024-02-15 14:52:46 -08:00

48 lines
1.5 KiB
Plaintext

<?php
declare(strict_types=1);
namespace ProductTests;
use APIHelper\Request;
use PHPUnit\Framework\TestCase;
final class ClientTest extends TestCase
{
private string $clientPassword;
private int $clientID;
private string $clientApiKey;
public function setUp(): void
{
parent::setUp();
// Generate a new test user
$this->clientPassword = 'A1' . bin2hex(random_bytes(6));
$result = Request::makeRequest('guest/client/create', [
'email' => 'client@example.com',
'first_name' => 'Test',
'password' => $this->clientPassword,
'password_confirm' => $this->clientPassword,
]);
$this->assertTrue($result->wasSuccessful(), $result->generatePHPUnitMessage());
$this->assertIsNotNumeric($result->getResult());
$this->clientID = intval($result->getResult());
// Now make an admin API request to get an API key for that user
$result = Request::makeRequest('admin/profile/api_key_reset', ['id' => $this->clientID]);
$this->assertTrue($result->wasSuccessful(), $result->generatePHPUnitMessage());
$this->assertIsString($result->getResult());
$this->clientApiKey = $result->getResult();
}
public function tearDown(): void
{
parent::tearDown();
$result = Request::makeRequest('admin/client/delete', ['id' => $this->clientID]);
$this->assertTrue($result->wasSuccessful(), $result->generatePHPUnitMessage());
$this->assertTrue($result->getResult());
}
}