-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Attachment; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class AbstractMimeTypeTest extends TestCase | ||
{ | ||
public function testGuessByExt(): void | ||
{ | ||
$this->assertEquals('application/andrew-inset', AbstractMimeType::guessByExt('ez')); | ||
$this->assertEquals('application/mac-binhex40', AbstractMimeType::guessByExt('hqx')); | ||
$this->assertEquals('application/octet-stream', AbstractMimeType::guessByExt('extension')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Captcha; | ||
|
||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Database\Sqlite3; | ||
use phpMyFAQ\Strings; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CaptchaTest extends TestCase | ||
{ | ||
private static ?CaptchaInterface $captcha = null; | ||
|
||
protected Configuration $configuration; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Strings::init(); | ||
|
||
$dbHandle = new Sqlite3(); | ||
$dbHandle->connect(PMF_TEST_DIR . '/test.db', '', ''); | ||
$this->configuration = new Configuration($dbHandle); | ||
} | ||
public function testGetInstanceWithGoogleRecaptchaEnabled(): void | ||
{ | ||
$this->configuration->set('security.enableGoogleReCaptchaV2', true); | ||
|
||
$captcha = Captcha::getInstance($this->configuration); | ||
|
||
$this->assertInstanceOf(GoogleRecaptcha::class, $captcha); | ||
} | ||
|
||
public function testGetInstanceWithGoogleRecaptchaDisabled(): void | ||
{ | ||
$this->configuration->set('security.enableGoogleReCaptchaV2', false); | ||
|
||
$captcha = Captcha::getInstance($this->configuration); | ||
|
||
$this->assertInstanceOf(BuiltinCaptcha::class, $captcha); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Captcha\Helper; | ||
|
||
use phpMyFAQ\Captcha\BuiltinCaptcha; | ||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Database\Sqlite3; | ||
use phpMyFAQ\Strings; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CaptchaHelperTest extends TestCase | ||
{ | ||
protected Configuration $configuration; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Strings::init(); | ||
|
||
$dbHandle = new Sqlite3(); | ||
$dbHandle->connect(PMF_TEST_DIR . '/test.db', '', ''); | ||
$this->configuration = new Configuration($dbHandle); | ||
} | ||
|
||
public function testGetInstanceWithGoogleRecaptchaEnabled(): void | ||
{ | ||
$this->configuration->set('security.enableGoogleReCaptchaV2', true); | ||
|
||
$captchaHelper = CaptchaHelper::getInstance($this->configuration); | ||
|
||
$this->assertInstanceOf(GoogleRecaptchaHelper::class, $captchaHelper); | ||
} | ||
|
||
public function testGetInstanceWithGoogleRecaptchaDisabled(): void | ||
{ | ||
$this->configuration->set('security.enableGoogleReCaptchaV2', false); | ||
|
||
$captchaHelper = CaptchaHelper::getInstance($this->configuration); | ||
|
||
$this->assertInstanceOf(BuiltinCaptchaHelper::class, $captchaHelper); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Core; | ||
|
||
use ErrorException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ErrorTest extends TestCase | ||
{ | ||
public function testErrorHandler(): void | ||
{ | ||
// Arrange | ||
$level = E_NOTICE; | ||
$message = "Undefined variable: x"; | ||
$filename = "test.php"; | ||
$line = 10; | ||
|
||
// Act | ||
try { | ||
Error::errorHandler($level, $message, $filename, $line); | ||
} catch (ErrorException $exception) { | ||
// Assert | ||
$this->assertSame($message, $exception->getMessage()); | ||
$this->assertSame(0, $exception->getCode()); | ||
$this->assertSame($level, $exception->getSeverity()); | ||
$this->assertSame(DEBUG ? $filename : basename($filename), $exception->getFile()); | ||
$this->assertSame($line, $exception->getLine()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Core; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class ExceptionTest extends TestCase | ||
{ | ||
public function testToString(): void | ||
{ | ||
$message = 'Test exception message'; | ||
$file = __FILE__; | ||
$line = 14; | ||
$exception = new Exception($message, 0, null); | ||
|
||
// Generate the expected string representation | ||
$expected = sprintf( | ||
"Exception %s with message %s in %s: %d\nStack trace:\n%s", | ||
Exception::class, | ||
$message, | ||
$file, | ||
$line, | ||
$exception->getTraceAsString() | ||
); | ||
|
||
// Ensure the __toString method returns the expected string | ||
$this->assertSame($expected, (string)$exception); | ||
} | ||
} |