From a3bdbe8e123f39e8f1726047cfbc4fdb799c421c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 29 Oct 2021 14:49:55 +0200 Subject: [PATCH] bug and media fixes --- Controller/ApiController.php | 15 ++++++++------- Models/Comment.php | 13 ++++++------- Models/CommentVote.php | 1 - tests/Bootstrap.php | 2 +- tests/Controller/ApiControllerTest.php | 12 ++++++------ tests/Models/CommentMapperTest.php | 4 ++-- tests/Models/CommentTest.php | 20 ++++++++++---------- tests/Models/CommentVoteMapperTest.php | 16 ++++++++-------- 8 files changed, 41 insertions(+), 42 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 271b80f..42e803d 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -181,12 +181,13 @@ final class ApiController extends Controller $comment->title = (string) ($request->getData('title') ?? ''); $comment->contentRaw = (string) ($request->getData('plain') ?? ''); $comment->content = Markdown::parse((string) ($request->getData('plain') ?? '')); - $comment->ref = $request->getData('ref') !== null ? (int) $request->getData('ref') : null; - $comment->list = (int) ($request->getData('list') ?? 0); + $comment->ref = $request->getData('ref') !== null ? (int) $request->getData('ref') : null; + $comment->list = (int) ($request->getData('list') ?? 0); if (!empty($uploadedFiles = $request->getFiles() ?? [])) { $uploaded = $this->app->moduleManager->get('Media')->uploadFiles( - [''], + [], + [], $uploadedFiles, $request->header->account, __DIR__ . '/../../../Modules/Media/Files/Modules/Comments', @@ -239,11 +240,11 @@ final class ApiController extends Controller */ private function updateCommentFromRequest(RequestAbstract $request) : Comment { - $comment = CommentMapper::get((int) $request->getData('id')); - $comment->title = $request->getData('title') ?? $comment->getTitle(); + $comment = CommentMapper::get((int) $request->getData('id')); + $comment->title = $request->getData('title') ?? $comment->getTitle(); $comment->contentRaw = $request->getData('plain') ?? $comment->getContentRaw(); - $comment->content = Markdown::parse((string) ($request->getData('plain') ?? $comment->getPlain())); - $comment->ref = $request->getData('ref') ?? $comment->ref; + $comment->content = Markdown::parse((string) ($request->getData('plain') ?? $comment->getPlain())); + $comment->ref = $request->getData('ref') ?? $comment->ref; return $comment; } diff --git a/Models/Comment.php b/Models/Comment.php index f674790..dd51eda 100755 --- a/Models/Comment.php +++ b/Models/Comment.php @@ -157,19 +157,18 @@ class Comment return $this->status; } - /** * {@inheritdoc} */ public function jsonSerialize() : array { return [ - 'id' => $this->id, - 'title' => $this->title, - 'content' => $this->content, - 'list' => $this->list, - 'ref' => $this->ref, - 'status' => $this->status, + 'id' => $this->id, + 'title' => $this->title, + 'content' => $this->content, + 'list' => $this->list, + 'ref' => $this->ref, + 'status' => $this->status, 'createdAt' => $this->createdAt, 'createdBy' => $this->createdBy, ]; diff --git a/Models/CommentVote.php b/Models/CommentVote.php index 14fd618..0e06d94 100755 --- a/Models/CommentVote.php +++ b/Models/CommentVote.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace Modules\Comments\Models; use Modules\Admin\Models\Account; -use Modules\Admin\Models\NullAccount; /** * Comment vote class. diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 051ac7e..f5fc99c 100755 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -392,4 +392,4 @@ function phpServe() : void }); } -phpServe(); +\phpServe(); diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 27b8ad7..b73253e 100644 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -16,22 +16,22 @@ namespace Modules\Comments\tests\Controller; use Model\CoreSettings; use Modules\Admin\Models\AccountPermission; -use phpOMS\DataStorage\Session\HttpSession; use phpOMS\Account\Account; use phpOMS\Account\AccountManager; use phpOMS\Account\PermissionType; use phpOMS\Application\ApplicationAbstract; +use phpOMS\DataStorage\Session\HttpSession; use phpOMS\Dispatcher\Dispatcher; use phpOMS\Event\EventManager; -use phpOMS\Module\ModuleAbstract; -use phpOMS\Module\ModuleManager; -use phpOMS\Router\WebRouter; -use phpOMS\Utils\TestUtils; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Uri\HttpUri; +use phpOMS\Module\ModuleAbstract; +use phpOMS\Module\ModuleManager; +use phpOMS\Router\WebRouter; use phpOMS\System\MimeType; +use phpOMS\Uri\HttpUri; +use phpOMS\Utils\TestUtils; /** * @testdox Modules\Comments\tests\Controller\ApiControllerTest: Comments api controller diff --git a/tests/Models/CommentMapperTest.php b/tests/Models/CommentMapperTest.php index 57a7a86..0fe9df3 100755 --- a/tests/Models/CommentMapperTest.php +++ b/tests/Models/CommentMapperTest.php @@ -34,8 +34,8 @@ final class CommentMapperTest extends \PHPUnit\Framework\TestCase $comment->createdBy = new NullAccount(1); $comment->title = 'Test Title'; $comment->content = 'Test Content'; - $comment->ref = null; - $comment->list = new CommentList(); + $comment->ref = null; + $comment->list = new CommentList(); $id = CommentMapper::create($comment); self::assertGreaterThan(0, $comment->getId()); diff --git a/tests/Models/CommentTest.php b/tests/Models/CommentTest.php index 27edf89..fb591c1 100755 --- a/tests/Models/CommentTest.php +++ b/tests/Models/CommentTest.php @@ -15,10 +15,10 @@ 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; +use Modules\Media\Models\Media; /** * @internal @@ -132,10 +132,10 @@ final class CommentTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->comment->title = 'Title'; - $this->comment->content = 'Content'; - $this->comment->list = 2; - $this->comment->ref = 1; + $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(); @@ -144,12 +144,12 @@ final class CommentTest extends \PHPUnit\Framework\TestCase self::assertEquals( [ - 'id' => 0, - 'title' => 'Title', + 'id' => 0, + 'title' => 'Title', 'content' => 'Content', - 'list' => 2, - 'ref' => 1, - 'status' => CommentStatus::VISIBLE, + 'list' => 2, + 'ref' => 1, + 'status' => CommentStatus::VISIBLE, ], $serialized ); diff --git a/tests/Models/CommentVoteMapperTest.php b/tests/Models/CommentVoteMapperTest.php index ab1152c..2e875dd 100644 --- a/tests/Models/CommentVoteMapperTest.php +++ b/tests/Models/CommentVoteMapperTest.php @@ -15,9 +15,9 @@ declare(strict_types=1); namespace Modules\Comments\tests\Models; use Modules\Admin\Models\NullAccount; +use Modules\Comments\Models\Comment; 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; @@ -34,18 +34,18 @@ final class CommentVoteMapperTest extends \PHPUnit\Framework\TestCase public function testCR() : void { $list = new CommentList(); - $lId = CommentListMapper::create($list); + $lId = CommentListMapper::create($list); - $comment = new Comment(); - $comment->title = 'TestComment'; + $comment = new Comment(); + $comment->title = 'TestComment'; $comment->createdBy = new NullAccount(1); - $comment->list = $lId; + $comment->list = $lId; $cId = CommentMapper::create($comment); - $vote = new CommentVote(); - $vote->comment = $cId; - $vote->score = 1; + $vote = new CommentVote(); + $vote->comment = $cId; + $vote->score = 1; $vote->createdBy = 1; CommentVoteMapper::create($vote);