Files
FOSSBilling/tests/Modules/Extension/ExtensionTest.php
T
Belle Aerni ccc97a3ec9 Initial implementation of CI against a live FOSSBilling Install (#2067)
* Rename tests to tests-legacy

* Groundwork for live tests

* Somewhat working tests on a live instance

* Hmmmmmm

* Fix

* Fixed the other bug

* Added a handful of various tests

* Typos, all these are admin endpoints

* Bypass this check for testing envs

* Disable it for now

* Mini cleanup

* Cleanup from debugging, ran PHP-CS-Fixer
2024-01-14 22:51:32 -08:00

72 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
use APIHelper\Request;
use PHPUnit\Framework\TestCase;
final class ExtensionTest extends TestCase
{
public function testCanActivateExtension(): void
{
$response = Request::makeRequest('admin/extension/activate', ['type' => 'mod', 'id' => 'massmailer']);
$this->assertTrue($response->wasSuccessful(), 'The API request failed with the following message: ' . $response->getError());
}
public function testCanDeactivateExtension(): void
{
$response = Request::makeRequest('admin/extension/deactivate', ['type' => 'mod', 'id' => 'massmailer']);
$this->assertTrue($response->wasSuccessful(), 'The API request failed with the following message: ' . $response->getError());
}
/*
public function testCanInstallExtension(): void
{
$response = Request::makeRequest('admin/extension/install', ['type' => 'mod', 'id' => 'example']);
$this->assertTrue($response->wasSuccessful(), 'The API request failed with the following message: ' . $response->getError());
}
*/
public function testLanguageManagement(): void
{
$response = Request::makeRequest('admin/extension/languages');
$this->assertTrue($response->wasSuccessful(), 'The API request failed with the following message: ' . $response->getError());
$this->assertNotCount(0, $response->getResult()); // A fresh install should never display 0 enabled languages
$response = Request::makeRequest('admin/extension/languages', ['disabled' => true]);
$this->assertTrue($response->wasSuccessful(), 'The API request failed with the following message: ' . $response->getError());
$this->assertCount(0, $response->getResult()); // There should be no disabled languages on a fresh install
// Disable the en_US language
$response = Request::makeRequest('admin/extension/toggle_language', ['locale_id' => 'en_US']);
$this->assertTrue($response->wasSuccessful(), 'The API request failed with the following message: ' . $response->getError());
// Validate it's now listed under the disabled languages
$response = Request::makeRequest('admin/extension/languages', ['disabled' => true, 'details' => false]);
$this->assertTrue($response->wasSuccessful(), 'The API request failed with the following message: ' . $response->getError());
$this->assertContains('en_US', $response->getResult(), 'The en_US language was not disabled');
}
public function testLanguageCompletion(): void
{
// Enable any languages that are disabled
$locales = Request::makeRequest('admin/extension/languages', ['disabled' => true, 'details' => false])->getResult();
foreach ($locales as $locale) {
Request::makeRequest('admin/extension/toggle_language', ['locale_id' => $locale]);
}
$this->assertEmpty(Request::makeRequest('admin/extension/languages', ['disabled' => true, 'details' => false])->getResult()); // There should now be no disabled languages
// Get a list of all languages, validate they have an expected completion level
$locales = Request::makeRequest('admin/extension/languages')->getResult();
foreach ($locales as $locale) {
$completionResult = Request::makeRequest('admin/extension/locale_completion', ['locale_id' => $locale]);
if ($locale === 'en_US') {
$this->assertEquals(100, $completionResult->getResult());
} else {
$this->greaterThanOrEqual(25, $completionResult->getResult());
}
}
}
}