mirror of
https://github.com/Karaka-Management/oms-Comments.git
synced 2026-01-25 14:58:41 +00:00
bug and media fixes
This commit is contained in:
parent
60f74e0470
commit
a3bdbe8e12
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -392,4 +392,4 @@ function phpServe() : void
|
|||
});
|
||||
}
|
||||
|
||||
phpServe();
|
||||
\phpServe();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user