Skip to content

Commit

Permalink
refactor: removed deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Mar 30, 2024
1 parent bea0d75 commit 940b98c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 50 deletions.
21 changes: 0 additions & 21 deletions phpmyfaq/src/phpMyFAQ/Component/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,4 @@ public static function danger(string $translationKey, ?string $errorMessage = nu
'<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'
);
}

/**
* Renders a Bootstrap info alert component.
*/
public static function info(string $translationKey): string
{
return sprintf('<div class="alert alert-info">%s</div>', Translation::get($translationKey));
}

/**
* Renders a Bootstrap warning alert component.
*/
public static function warning(string $translationKey, ?string $warningMessage = null): string
{
return sprintf(
'<div class="alert alert-warning alert-dismissible fade show">%s%s%s</div>',
Translation::get($translationKey),
$warningMessage !== null ? '<br>' . $warningMessage : '',
'<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'
);
}
}
19 changes: 7 additions & 12 deletions phpmyfaq/src/phpMyFAQ/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,13 @@ public static function isForbiddenElement(string $string): bool
*/
public static function debug(string $string): string
{
// sometimes Zend Optimizer causes segfaults with debug_backtrace()
if (extension_loaded('Zend Optimizer')) {
$ret = '<code>' . Strings::htmlentities($string) . "</code><br>\n";
} else {
$debug = debug_backtrace();
$ret = '';
if (isset($debug[2]['class'])) {
$ret = $debug[2]['file'] . ': ';
$ret .= $debug[2]['class'] . $debug[1]['type'];
$ret .= $debug[2]['function'] . '() in line ' . $debug[2]['line'];
$ret .= ':<br><code>' . Strings::htmlentities($string) . "</code><br>\n";
}
$debug = debug_backtrace();
$ret = '';
if (isset($debug[2]['class'])) {
$ret = $debug[2]['file'] . ': ';
$ret .= $debug[2]['class'] . $debug[1]['type'];
$ret .= $debug[2]['function'] . '() in line ' . $debug[2]['line'];
$ret .= ':<br><code>' . Strings::htmlentities($string) . "</code><br>\n";
}

return $ret;
Expand Down
17 changes: 0 additions & 17 deletions tests/phpMyFAQ/Component/AlertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ public function testDangerWithError(): void
);
}

public function testWarning(): void
{
$this->assertEquals(
'<div class="alert alert-warning alert-dismissible fade show">Hilfe' .
'<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>',
Alert::warning('msgHelp')
);
}

public function testSuccess(): void
{
$this->assertEquals(
Expand All @@ -57,12 +48,4 @@ public function testSuccess(): void
Alert::success('msgHelp')
);
}

public function testInfo(): void
{
$this->assertEquals(
'<div class="alert alert-info">Hilfe</div>',
Alert::info('msgHelp')
);
}
}
6 changes: 6 additions & 0 deletions tests/phpMyFAQ/RatingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class RatingTest extends TestCase
{
private Sqlite3 $dbHandle;

private Rating $rating;

/**
Expand Down Expand Up @@ -98,6 +99,11 @@ public function testGetNumberOfVotings(): void
$this->assertEquals(2, $this->rating->getNumberOfVotings(1));
}

public function testGetNumberOfVotingsWithNoVotes(): void
{
$this->assertEquals(0, $this->rating->getNumberOfVotings(1));
}

public function testUpdate(): void
{
$votingData = new Vote();
Expand Down
13 changes: 13 additions & 0 deletions tests/phpMyFAQ/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

class ServicesTest extends TestCase
{
public function testSetQuestion(): void
{
// Create a mock Configuration object
$configuration = $this->createMock(Configuration::class);

// Create a Services object
$services = new Services($configuration);
$services->setQuestion('What is phpMyFAQ?');

// Test getQuestion method
$this->assertEquals('What+is+phpMyFAQ%3F', $services->getQuestion());
}

public function testGetSuggestLink(): void
{
// Create a mock Configuration object
Expand Down
8 changes: 8 additions & 0 deletions tests/phpMyFAQ/StopWordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public function testCheckBannedWord(): void
$this->assertTrue($this->stopWords->checkBannedWord('test'));
$this->assertFalse($this->stopWords->checkBannedWord('abolon'));
}

public function testCheckBannedWordWithEmptyString(): void
{
$this->stopWords->setLanguage('test');
$this->stopWords->add('test');
$this->assertTrue($this->stopWords->checkBannedWord(''));
}

}

0 comments on commit 940b98c

Please sign in to comment.