Skip to content

Commit

Permalink
test: added more tests for AdministrationHelper class
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed May 13, 2024
1 parent ed86570 commit 5bf10f8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
3 changes: 2 additions & 1 deletion phpmyfaq/admin/faqs.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use phpMyFAQ\Template\UserNameTwigExtension;
use phpMyFAQ\Translation;
use phpMyFAQ\User\CurrentUser;
use phpMyFAQ\Utils;
use Twig\Extension\DebugExtension;

if (!defined('IS_VALID_PHPMYFAQ')) {
Expand Down Expand Up @@ -136,11 +135,13 @@
],
]
);

if (is_array($selectedCategory)) {
foreach ($selectedCategory as $cats) {
$categories[] = ['category_id' => $cats, 'category_lang' => $faqData['lang']];
}
}

$faqData['active'] = Filter::filterInput(INPUT_POST, 'active', FILTER_SANITIZE_SPECIAL_CHARS);
$faqData['keywords'] = Filter::filterInput(INPUT_POST, 'keywords', FILTER_SANITIZE_SPECIAL_CHARS);
$faqData['title'] = Filter::filterInput(INPUT_POST, 'thema', FILTER_SANITIZE_SPECIAL_CHARS);
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Helper/AdministrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function addMenuEntry(
bool $checkPerm = true
): string {

if ($action != '') {
if ($action !== '') {
$action = 'action=' . $action;
}

Expand Down
44 changes: 43 additions & 1 deletion tests/phpMyFAQ/Helper/AdministrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace phpMyFAQ\Helper;

use phpMyFAQ\Enums\ReleaseType;
use phpMyFAQ\Strings;
use phpMyFAQ\Translation;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -14,9 +17,27 @@ class AdministrationHelperTest extends TestCase

protected function setUp(): void
{
parent::setUp();

Strings::init();

Translation::create()
->setLanguagesDir(PMF_TRANSLATION_DIR)
->setDefaultLanguage('en')
->setCurrentLanguage('en')
->setMultiByteLanguage();

$this->instance = new AdministrationHelper();
}

public function testAddMenuEntry(): void
{
$expected = '<a class="nav-link" href="?action=edit">Categories</a>' . "\n";
$actual = $this->instance->addMenuEntry('', 'edit', 'ad_menu_categ_edit', '', false);

$this->assertEquals($expected, $actual);
}

public function testRenderMetaRobotsDropdown(): void
{
$expected = '<option selected>index, follow</option><option>index, nofollow</option>' .
Expand All @@ -26,4 +47,25 @@ public function testRenderMetaRobotsDropdown(): void
$this->assertEquals($expected, $actual);
}

}
public function testRenderReleaseTypeOptions(): void
{
$optionsDevelopment = AdministrationHelper::renderReleaseTypeOptions(ReleaseType::DEVELOPMENT->value);
$optionsStable = AdministrationHelper::renderReleaseTypeOptions(ReleaseType::STABLE->value);
$optionsNightly = AdministrationHelper::renderReleaseTypeOptions(ReleaseType::NIGHTLY->value);

// Assert the HTML output for each release type
$expectedDevelopment = '<option value="development" selected>Development</option>' .
'<option value="stable">Stable</option>' .
'<option value="nightly">Nightly</option>';
$expectedStable = '<option value="development">Development</option>' .
'<option value="stable" selected>Stable</option>' .
'<option value="nightly">Nightly</option>';
$expectedNightly = '<option value="development">Development</option>' .
'<option value="stable">Stable</option>' .
'<option value="nightly" selected>Nightly</option>';

$this->assertEquals($expectedDevelopment, $optionsDevelopment);
$this->assertEquals($expectedStable, $optionsStable);
$this->assertEquals($expectedNightly, $optionsNightly);
}
}

0 comments on commit 5bf10f8

Please sign in to comment.