mirror of
https://github.com/Karaka-Management/oms-Comments.git
synced 2026-01-28 16:28:42 +00:00
more tests and make classes final
This commit is contained in:
parent
513a0e1a1b
commit
6dd9fad78c
|
|
@ -58,7 +58,7 @@ class Comment
|
|||
* @var int|CommentList
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $list = 0;
|
||||
public $list = 0;
|
||||
|
||||
/**
|
||||
* Title
|
||||
|
|
@ -98,7 +98,7 @@ class Comment
|
|||
* @var null|int|self
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $ref = null;
|
||||
public $ref = null;
|
||||
|
||||
/**
|
||||
* Media files
|
||||
|
|
@ -131,32 +131,6 @@ class Comment
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference id
|
||||
*
|
||||
* @param mixed $ref Reference
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setRef($ref) : void
|
||||
{
|
||||
$this->ref = $ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reference
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getRef()
|
||||
{
|
||||
return $this->ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the status
|
||||
*
|
||||
|
|
@ -183,38 +157,22 @@ class Comment
|
|||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list this comment belongs to
|
||||
*
|
||||
* @param int|CommentList $list List
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setList($list) : void
|
||||
{
|
||||
$this->list = $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list this comment belongs to
|
||||
*
|
||||
* @return int|CommentList
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
return $this->list;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
'list' => $this->list,
|
||||
'ref' => $this->ref,
|
||||
'status' => $this->status,
|
||||
'createdAt' => $this->createdAt,
|
||||
'createdBy' => $this->createdBy,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ class CommentVote
|
|||
/**
|
||||
* Account.
|
||||
*
|
||||
* @var Account
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public Account $createdBy;
|
||||
public int $createdBy = 0;
|
||||
|
||||
/**
|
||||
* Created at
|
||||
|
|
@ -74,7 +74,18 @@ class CommentVote
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdBy = new NullAccount();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id.
|
||||
*
|
||||
* @return int Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getId() : int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,15 +22,24 @@ use Modules\Comments\Models\CommentList;
|
|||
*/
|
||||
class CommentListTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private CommentList $list;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->list = new CommentList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\CommentList
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$list = new CommentList();
|
||||
self::assertEquals(0, $list->getId());
|
||||
self::assertEquals([], $list->getComments());
|
||||
self::assertEquals(0, $this->list->getId());
|
||||
self::assertEquals([], $this->list->getComments());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -39,15 +48,14 @@ class CommentListTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testGetSet() : void
|
||||
{
|
||||
$list = new CommentList();
|
||||
$comment = new Comment();
|
||||
$comment->title = 'Test Title';
|
||||
$comment->contentRaw = 'TestRaw';
|
||||
$comment->content = 'Test Content';
|
||||
|
||||
$list->addComment($comment);
|
||||
self::assertEquals('Test Title', $list->getComments()[0]->title);
|
||||
self::assertEquals('TestRaw', $list->getComments()[0]->contentRaw);
|
||||
self::assertEquals('Test Content', $list->getComments()[0]->content);
|
||||
$this->list->addComment($comment);
|
||||
self::assertEquals('Test Title', $this->list->getComments()[0]->title);
|
||||
self::assertEquals('TestRaw', $this->list->getComments()[0]->contentRaw);
|
||||
self::assertEquals('Test Content', $this->list->getComments()[0]->content);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ class CommentMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$comment->createdBy = new NullAccount(1);
|
||||
$comment->title = 'Test Title';
|
||||
$comment->content = 'Test Content';
|
||||
$comment->setRef(null);
|
||||
$comment->setList(new CommentList());
|
||||
$comment->ref = null;
|
||||
$comment->list = new CommentList();
|
||||
|
||||
$id = CommentMapper::create($comment);
|
||||
self::assertGreaterThan(0, $comment->getId());
|
||||
|
|
@ -46,7 +46,7 @@ class CommentMapperTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($comment->createdBy->getId(), $commentR->createdBy->getId());
|
||||
self::assertEquals($comment->title, $commentR->title);
|
||||
self::assertEquals($comment->content, $commentR->content);
|
||||
self::assertEquals($comment->getRef(), $commentR->getRef());
|
||||
self::assertEquals($comment->getList()->getId(), $commentR->getList()->getId());
|
||||
self::assertEquals($comment->ref, $commentR->ref);
|
||||
self::assertEquals($comment->list->getId(), $commentR->list->getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ declare(strict_types=1);
|
|||
namespace Modules\Comments\tests\Models;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Comments\Models\Comment;
|
||||
use Modules\Comments\Models\CommentStatus;
|
||||
use Modules\Comments\Models\NullComment;
|
||||
|
||||
/**
|
||||
|
|
@ -23,45 +25,133 @@ use Modules\Comments\Models\NullComment;
|
|||
*/
|
||||
class CommentTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private Comment $comment;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->comment = new Comment();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\Comment
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$comment = new Comment();
|
||||
self::assertEquals(0, $comment->getId());
|
||||
self::assertEquals(0, $this->comment->getId());
|
||||
|
||||
$date = new \DateTime('now');
|
||||
self::assertEquals($date->format('Y-m-d'), $comment->createdAt->format('Y-m-d'));
|
||||
self::assertEquals(0, $comment->createdBy->getId());
|
||||
self::assertEquals(0, $comment->getList());
|
||||
self::assertEquals(0, $comment->getRef());
|
||||
self::assertEquals('', $comment->title);
|
||||
self::assertEquals('', $comment->content);
|
||||
self::assertEquals($date->format('Y-m-d'), $this->comment->createdAt->format('Y-m-d'));
|
||||
self::assertEquals(0, $this->comment->createdBy->getId());
|
||||
self::assertEquals(0, $this->comment->list);
|
||||
self::assertEquals(0, $this->comment->ref);
|
||||
self::assertEquals('', $this->comment->title);
|
||||
self::assertEquals('', $this->comment->content);
|
||||
self::assertEquals([], $this->comment->getMedia());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\Comment
|
||||
* @group module
|
||||
*/
|
||||
public function testGetSet() : void
|
||||
public function testCreatedByInputOutput() : void
|
||||
{
|
||||
$comment = new Comment();
|
||||
$this->comment->createdBy = new NullAccount(1);
|
||||
self::assertEquals(1, $this->comment->createdBy->getId());
|
||||
}
|
||||
|
||||
$comment->createdBy = new NullAccount(1);
|
||||
self::assertEquals(1, $comment->createdBy->getId());
|
||||
/**
|
||||
* @covers Modules\Comments\Models\Comment
|
||||
* @group module
|
||||
*/
|
||||
public function testListInputOutput() : void
|
||||
{
|
||||
$this->comment->list = 3;
|
||||
self::assertEquals(3, $this->comment->list);
|
||||
}
|
||||
|
||||
$comment->setList(2);
|
||||
self::assertEquals(2, $comment->getList());
|
||||
/**
|
||||
* @covers Modules\Comments\Models\Comment
|
||||
* @group module
|
||||
*/
|
||||
public function testRefInputOutput() : void
|
||||
{
|
||||
$this->comment->ref = 2;
|
||||
self::assertEquals(2, $this->comment->ref);
|
||||
|
||||
$comment->setRef(new NullComment(3));
|
||||
self::assertEquals(3, $comment->getRef()->getId());
|
||||
$this->comment->ref = new NullComment(3);
|
||||
self::assertEquals(3, $this->comment->ref->getId());
|
||||
}
|
||||
|
||||
$comment->title = 'Test Title';
|
||||
self::assertEquals('Test Title', $comment->title);
|
||||
/**
|
||||
* @covers Modules\Comments\Models\Comment
|
||||
* @group module
|
||||
*/
|
||||
public function testTitleInputOutput() : void
|
||||
{
|
||||
$this->comment->title = 'Test Title';
|
||||
self::assertEquals('Test Title', $this->comment->title);
|
||||
}
|
||||
|
||||
$comment->content = 'Test Content';
|
||||
self::assertEquals('Test Content', $comment->content);
|
||||
/**
|
||||
* @covers Modules\Comments\Models\Comment
|
||||
* @group module
|
||||
*/
|
||||
public function testContentInputOutput() : void
|
||||
{
|
||||
$this->comment->content = 'Test Content';
|
||||
self::assertEquals('Test Content', $this->comment->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\Comment
|
||||
* @group module
|
||||
*/
|
||||
public function testStatusInputOutput() : void
|
||||
{
|
||||
$this->comment->setStatus(CommentStatus::INVISIBLE);
|
||||
self::assertEquals(CommentStatus::INVISIBLE, $this->comment->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\Comment
|
||||
* @group module
|
||||
*/
|
||||
public function testMediaInputOutput() : void
|
||||
{
|
||||
$this->comment->addMedia(new Media());
|
||||
self::assertCount(1, $this->comment->getMedia());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\CMS\Models\PageL11n
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->comment->title = 'Title';
|
||||
$this->comment->content = 'Content';
|
||||
$this->comment->list = 2;
|
||||
$this->comment->ref = 1;
|
||||
$this->comment->createdBy = new NullAccount(2);
|
||||
|
||||
$serialized = $this->comment->jsonSerialize();
|
||||
unset($serialized['createdAt']);
|
||||
unset($serialized['createdBy']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'title' => 'Title',
|
||||
'content' => 'Content',
|
||||
'list' => 2,
|
||||
'ref' => 1,
|
||||
'status' => CommentStatus::VISIBLE,
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
57
tests/Models/CommentVoteMapperTest.php
Normal file
57
tests/Models/CommentVoteMapperTest.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Comments\tests\Models;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Comments\Models\CommentList;
|
||||
use Modules\Comments\Models\CommentListMapper;
|
||||
use Modules\Comments\Models\Comment;
|
||||
use Modules\Comments\Models\CommentMapper;
|
||||
use Modules\Comments\Models\CommentVote;
|
||||
use Modules\Comments\Models\CommentVoteMapper;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class CommentVoteMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Comments\Models\CommentVote
|
||||
* @group module
|
||||
*/
|
||||
public function testCR() : void
|
||||
{
|
||||
$list = new CommentList();
|
||||
$lId = CommentListMapper::create($list);
|
||||
|
||||
$comment = new Comment();
|
||||
$comment->title = 'TestComment';
|
||||
$comment->createdBy = new NullAccount(1);
|
||||
$comment->list = $lId;
|
||||
|
||||
$cId = CommentMapper::create($comment);
|
||||
|
||||
$vote = new CommentVote();
|
||||
$vote->comment = $cId;
|
||||
$vote->score = 1;
|
||||
$vote->createdBy = 1;
|
||||
|
||||
CommentVoteMapper::create($vote);
|
||||
|
||||
$voteR = CommentvoteMapper::findVote($cId, 1);
|
||||
self::assertEquals($vote->comment, $voteR->comment);
|
||||
self::assertEquals($vote->createdBy, $voteR->createdBy);
|
||||
}
|
||||
}
|
||||
66
tests/Models/CommentVoteTest.php
Normal file
66
tests/Models/CommentVoteTest.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Comments\tests\Models;
|
||||
|
||||
use Modules\Comments\Models\CommentVote;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class CommentVoteTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private CommentVote $vote;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->vote = new CommentVote();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\CommentVote
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->vote->getId());
|
||||
self::assertEquals(0, $this->vote->score);
|
||||
self::assertEquals(0, $this->vote->comment);
|
||||
self::assertEquals(0, $this->vote->createdBy);
|
||||
self::assertInstanceOf('\DateTimeImmutable', $this->vote->createdAt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\CommentVote
|
||||
* @group module
|
||||
*/
|
||||
public function testScoreInputOutput() : void
|
||||
{
|
||||
$this->vote->score = 1;
|
||||
self::assertEquals(1, $this->vote->score);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\CommentVote
|
||||
* @group module
|
||||
*/
|
||||
public function testCommentInputOutput() : void
|
||||
{
|
||||
$this->vote->comment = 1;
|
||||
self::assertEquals(1, $this->vote->comment);
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullComment.php
Normal file
42
tests/Models/NullComment.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Comments\tests\Models;
|
||||
|
||||
use Modules\Comments\Models\NullComment;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullCommentTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Comments\Models\NullComment
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\Comments\Models\Comment', new NullComment());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\NullComment
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullComment(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullCommentList.php
Normal file
42
tests/Models/NullCommentList.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Comments\tests\Models;
|
||||
|
||||
use Modules\Comments\Models\NullCommentList;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullCommentListTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Comments\Models\NullCommentList
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\Comments\Models\CommentList', new NullCommentList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\NullCommentList
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullCommentList(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullCommentVote.php
Normal file
42
tests/Models/NullCommentVote.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Comments\tests\Models;
|
||||
|
||||
use Modules\Comments\Models\NullCommentVote;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullCommentVoteTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Comments\Models\NullCommentVote
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\Comments\Models\CommentVote', new NullCommentVote());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Comments\Models\NullCommentVote
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullCommentVote(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user