Skip to content

Commit

Permalink
test: added missing tests for Auth and Bookmark classes
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Apr 1, 2024
1 parent 590f6d7 commit 16d0188
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/phpMyFAQ/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace phpMyFAQ;

use phpMyFAQ\Core\Exception;
use phpMyFAQ\Database\Sqlite3;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -48,13 +49,22 @@ public function testErrorWithError(): void
$this->assertEquals("EncryptionTypes method could not be found.\n", $this->auth->error());
}

/**
* @throws Exception
*/
public function testSelectAuth(): void
{
$this->assertInstanceOf('phpMyFAQ\Auth\AuthDatabase', $this->auth->selectAuth('database'));
$this->assertInstanceOf('phpMyFAQ\Auth\AuthHttp', $this->auth->selectAuth('http'));
$this->assertInstanceOf('phpMyFAQ\Auth\AuthSso', $this->auth->selectAuth('sso'));
}

public function testSelectAuthWithNonExistingAuth(): void
{
$this->expectException(Exception::class);
$this->auth->selectAuth('foobar');
}

public function testSetReadOnly(): void
{
$this->assertFalse($this->auth->setReadOnly());
Expand Down
42 changes: 40 additions & 2 deletions tests/phpMyFAQ/BookmarkTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php


namespace phpMyFAQ;

use phpMyFAQ\Database\Sqlite3;
use phpMyFAQ\User\CurrentUser;
use PHPUnit\Framework\TestCase;


class BookmarkTest extends TestCase
{
private Bookmark $bookmark;
Expand All @@ -18,6 +16,12 @@ protected function setUp(): void

Strings::init();

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

$dbHandle = new Sqlite3();
$dbHandle->connect(PMF_TEST_DIR . '/test.db', '', '');
$configuration = new Configuration($dbHandle);
Expand All @@ -33,12 +37,46 @@ public function testSaveFaqAsBookmarkById(): void
{
$result = $this->bookmark->saveFaqAsBookmarkById(1);
$this->assertTrue($result);

// Clean up
$this->bookmark->remove(1);
}

public function testIsFaqBookmark(): void
{
$this->bookmark->saveFaqAsBookmarkById(1);
$result = $this->bookmark->isFaqBookmark(1);
$this->assertTrue($result);

// Clean up
$this->bookmark->remove(1);
}

public function testGetAll(): void
{
$this->bookmark->saveFaqAsBookmarkById(1);
$result = $this->bookmark->getAll();
$this->assertIsArray($result);
$this->assertEquals(1, count($result));

// Clean up
$this->bookmark->remove(1);
}

public function testRemove(): void
{
$this->bookmark->saveFaqAsBookmarkById(1);
$this->assertTrue($this->bookmark->remove(1));
}

public function testRenderBookmarkTree(): void
{
$this->bookmark->saveFaqAsBookmarkById(1);
$result = $this->bookmark->renderBookmarkTree();
$this->assertIsString($result);
$this->assertStringContainsString('<div class="list-group mb-4">', $result);

// Clean up
$this->bookmark->remove(1);
}
}

0 comments on commit 16d0188

Please sign in to comment.