mirror of
https://github.com/Karaka-Management/oms-News.git
synced 2026-02-17 08:58:42 +00:00
cs fixes, bug fixes, code coverage
This commit is contained in:
parent
a6cd3bff7b
commit
e8f2c78bbb
|
|
@ -12,9 +12,7 @@ If you have a good idea for improvement feel free to create a new issue with all
|
||||||
|
|
||||||
### Issues
|
### Issues
|
||||||
|
|
||||||
Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the `Project.md` file in the `Docs` repository.
|
Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the code marked with `@todo` or in the [PROJECT.md](https://github.com/Orange-Management/Docs/blob/master/Project/PROJECT.md) file.
|
||||||
|
|
||||||
The issue information can be used to provide additional information such as priority, difficulty and type. For your first issue try to find a issue marked `[d:first]` or `[d:beginner]`.
|
|
||||||
|
|
||||||
### Code Style
|
### Code Style
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ final class ApiController extends Controller
|
||||||
private function updateNewsFromRequest(RequestAbstract $request) : NewsArticle
|
private function updateNewsFromRequest(RequestAbstract $request) : NewsArticle
|
||||||
{
|
{
|
||||||
/** @var NewsArticle $newsArticle */
|
/** @var NewsArticle $newsArticle */
|
||||||
$newsArticle = NewsArticleMapper::get((int) $request->getData('id'));
|
$newsArticle = NewsArticleMapper::get((int) $request->getData('id'));
|
||||||
$newsArticle->publich = new \DateTime((string) ($request->getData('publish') ?? $newsArticle->publish->format('Y-m-d H:i:s')));
|
$newsArticle->publich = new \DateTime((string) ($request->getData('publish') ?? $newsArticle->publish->format('Y-m-d H:i:s')));
|
||||||
$newsArticle->title = (string) ($request->getData('title') ?? $newsArticle->title);
|
$newsArticle->title = (string) ($request->getData('title') ?? $newsArticle->title);
|
||||||
$newsArticle->plain = $request->getData('plain') ?? $newsArticle->plain;
|
$newsArticle->plain = $request->getData('plain') ?? $newsArticle->plain;
|
||||||
|
|
@ -160,10 +160,10 @@ final class ApiController extends Controller
|
||||||
{
|
{
|
||||||
$newsArticle = new NewsArticle();
|
$newsArticle = new NewsArticle();
|
||||||
$newsArticle->createdBy = new NullAccount($request->header->account);
|
$newsArticle->createdBy = new NullAccount($request->header->account);
|
||||||
$newsArticle->publich = new \DateTime((string) ($request->getData('publish') ?? 'now'));
|
$newsArticle->publich = new \DateTime((string) ($request->getData('publish') ?? 'now'));
|
||||||
$newsArticle->title = (string) ($request->getData('title') ?? '');
|
$newsArticle->title = (string) ($request->getData('title') ?? '');
|
||||||
$newsArticle->plain = $request->getData('plain') ?? '';
|
$newsArticle->plain = $request->getData('plain') ?? '';
|
||||||
$newsArticle->content = Markdown::parse((string) ($request->getData('plain') ?? ''));
|
$newsArticle->content = Markdown::parse((string) ($request->getData('plain') ?? ''));
|
||||||
$newsArticle->setLanguage(\strtolower((string) ($request->getData('lang') ?? $request->getLanguage())));
|
$newsArticle->setLanguage(\strtolower((string) ($request->getData('lang') ?? $request->getLanguage())));
|
||||||
$newsArticle->setType((int) ($request->getData('type') ?? NewsType::ARTICLE));
|
$newsArticle->setType((int) ($request->getData('type') ?? NewsType::ARTICLE));
|
||||||
$newsArticle->setStatus((int) ($request->getData('status') ?? NewsStatus::VISIBLE));
|
$newsArticle->setStatus((int) ($request->getData('status') ?? NewsStatus::VISIBLE));
|
||||||
|
|
|
||||||
|
|
@ -357,16 +357,16 @@ class NewsArticle implements \JsonSerializable, ArrayableInterface
|
||||||
public function toArray() : array
|
public function toArray() : array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'plain' => $this->plain,
|
'plain' => $this->plain,
|
||||||
'content' => $this->content,
|
'content' => $this->content,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'isFeatured' => $this->isFeatured,
|
'isFeatured' => $this->isFeatured,
|
||||||
'publish' => $this->publish,
|
'publish' => $this->publish,
|
||||||
'createdAt' => $this->createdAt,
|
'createdAt' => $this->createdAt,
|
||||||
'createdBy' => $this->createdBy,
|
'createdBy' => $this->createdBy,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,17 +86,12 @@ echo $this->getData('nav')->render(); ?>
|
||||||
|
|
||||||
foreach ($newsList as $key => $news) : ++$count;
|
foreach ($newsList as $key => $news) : ++$count;
|
||||||
$url = UriFactory::build('{/prefix}news/article?{?}&id=' . $news->getId());
|
$url = UriFactory::build('{/prefix}news/article?{?}&id=' . $news->getId());
|
||||||
$color = 'darkred';
|
|
||||||
|
|
||||||
if ($news->getType() === NewsType::ARTICLE) { $color = 'green'; }
|
|
||||||
elseif ($news->getType() === NewsType::HEADLINE) { $color = 'purple'; }
|
|
||||||
elseif ($news->getType() === NewsType::LINK) { $color = 'yellow'; }
|
|
||||||
?>
|
?>
|
||||||
<tr tabindex="0" data-href="<?= $url; ?>">
|
<tr tabindex="0" data-href="<?= $url; ?>">
|
||||||
<td><span class="tag <?= $this->printHtml($color); ?>"><?= $this->getHtml('TYPE' . $news->getType()); ?></span></a>
|
<td><span class="tag"><?= $this->getHtml('TYPE' . $news->getType()); ?></span></a>
|
||||||
<td><a href="<?= $url; ?>"><?= $this->printHtml($news->title); ?></a>
|
<td><a href="<?= $url; ?>"><?= $this->printHtml($news->title); ?></a>
|
||||||
<td><a class="content" href="<?= UriFactory::build('{/prefix}profile/single?{?}&for=' . $news->createdBy->getId()); ?>"><?= $this->printHtml($news->createdBy->name2 . ', ' . $news->createdBy->name1); ?></a>
|
<td><a class="content" href="<?= UriFactory::build('{/prefix}profile/single?{?}&for=' . $news->createdBy->getId()); ?>"><?= $this->printHtml($news->createdBy->name2 . ', ' . $news->createdBy->name1); ?></a>
|
||||||
<td><a href="<?= $url; ?>"><?= $this->printHtml($news->getPublish()->format('Y-m-d')); ?></a>
|
<td><a href="<?= $url; ?>"><?= $this->printHtml($news->publish->format('Y-m-d')); ?></a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if ($count === 0) : ?>
|
<?php if ($count === 0) : ?>
|
||||||
<tr><td colspan="4" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
|
<tr><td colspan="4" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ echo $this->getData('nav')->render(); ?>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="iPublish"><?= $this->getHtml('Publish'); ?></label>
|
<label for="iPublish"><?= $this->getHtml('Publish'); ?></label>
|
||||||
<input type="datetime-local" name="publish" id="iPublish" value="<?= $this->printHtml($news->getPublish()->format('Y-m-d\TH:i:s')); ?>">
|
<input type="datetime-local" name="publish" id="iPublish" value="<?= $this->printHtml($news->publish->format('Y-m-d\TH:i:s')); ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ use Modules\News\Models\NewsType;
|
||||||
use Modules\News\Models\NullNewsArticle;
|
use Modules\News\Models\NullNewsArticle;
|
||||||
use phpOMS\Message\Http\HttpRequest;
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
use phpOMS\Message\Http\HttpResponse;
|
use phpOMS\Message\Http\HttpResponse;
|
||||||
use phpOMS\Uri\HttpUri;
|
|
||||||
use phpOMS\Message\Http\RequestStatusCode;
|
use phpOMS\Message\Http\RequestStatusCode;
|
||||||
use phpOMS\Utils\TestUtils;
|
|
||||||
use phpOMS\System\MimeType;
|
use phpOMS\System\MimeType;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use phpOMS\Utils\TestUtils;
|
||||||
|
|
||||||
trait ApiControllerNewsArticleTrait
|
trait ApiControllerNewsArticleTrait
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,11 @@ final class NewsArticleMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
$text = new Text();
|
$text = new Text();
|
||||||
$news = new NewsArticle();
|
$news = new NewsArticle();
|
||||||
|
|
||||||
$news->createdBy = new NullAccount(1);
|
$news->createdBy = new NullAccount(1);
|
||||||
$news->title = $text->generateText(\mt_rand(3, 7));
|
$news->title = $text->generateText(\mt_rand(3, 7));
|
||||||
$news->content = ($raw = $text->generateText(\mt_rand(100, 300)));
|
$news->content = ($raw = $text->generateText(\mt_rand(100, 300)));
|
||||||
$news->plain = $raw;
|
$news->plain = $raw;
|
||||||
$news->publish = new \DateTime('2001-05-07');
|
$news->publish = new \DateTime('2001-05-07');
|
||||||
$news->isFeatured = true;
|
$news->isFeatured = true;
|
||||||
$news->setLanguage(ISO639x1Enum::_DE);
|
$news->setLanguage(ISO639x1Enum::_DE);
|
||||||
$news->setStatus(NewsStatus::VISIBLE);
|
$news->setStatus(NewsStatus::VISIBLE);
|
||||||
|
|
@ -77,11 +77,11 @@ final class NewsArticleMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
// Created by other
|
// Created by other
|
||||||
|
|
||||||
$news = new NewsArticle();
|
$news = new NewsArticle();
|
||||||
$news->createdBy = new NullAccount(1);
|
$news->createdBy = new NullAccount(1);
|
||||||
$news->title = $text->generateText(\mt_rand(3, 7));
|
$news->title = $text->generateText(\mt_rand(3, 7));
|
||||||
$news->content = $text->generateText(\mt_rand(10, 300));
|
$news->content = $text->generateText(\mt_rand(10, 300));
|
||||||
$news->publish = new \DateTime('2001-05-07');
|
$news->publish = new \DateTime('2001-05-07');
|
||||||
$news->isFeatured = false;
|
$news->isFeatured = false;
|
||||||
$news->setLanguage(ISO639x1Enum::_DE);
|
$news->setLanguage(ISO639x1Enum::_DE);
|
||||||
$news->setStatus(NewsStatus::VISIBLE);
|
$news->setStatus(NewsStatus::VISIBLE);
|
||||||
|
|
@ -89,11 +89,11 @@ final class NewsArticleMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
$id = NewsArticleMapper::create($news);
|
$id = NewsArticleMapper::create($news);
|
||||||
|
|
||||||
$news = new NewsArticle();
|
$news = new NewsArticle();
|
||||||
$news->createdBy = new NullAccount(1);
|
$news->createdBy = new NullAccount(1);
|
||||||
$news->title = $text->generateText(\mt_rand(3, 7));
|
$news->title = $text->generateText(\mt_rand(3, 7));
|
||||||
$news->content = $text->generateText(\mt_rand(10, 300));
|
$news->content = $text->generateText(\mt_rand(10, 300));
|
||||||
$news->publish = new \DateTime('2001-05-07');
|
$news->publish = new \DateTime('2001-05-07');
|
||||||
$news->isFeatured = false;
|
$news->isFeatured = false;
|
||||||
$news->setLanguage(ISO639x1Enum::_DE);
|
$news->setLanguage(ISO639x1Enum::_DE);
|
||||||
$news->setStatus(NewsStatus::DRAFT);
|
$news->setStatus(NewsStatus::DRAFT);
|
||||||
|
|
@ -103,11 +103,11 @@ final class NewsArticleMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
// Created by me
|
// Created by me
|
||||||
|
|
||||||
$news = new NewsArticle();
|
$news = new NewsArticle();
|
||||||
$news->createdBy = new NullAccount(1);
|
$news->createdBy = new NullAccount(1);
|
||||||
$news->title = $text->generateText(\mt_rand(3, 7));
|
$news->title = $text->generateText(\mt_rand(3, 7));
|
||||||
$news->content = $text->generateText(\mt_rand(10, 300));
|
$news->content = $text->generateText(\mt_rand(10, 300));
|
||||||
$news->publish = new \DateTime('2001-05-07');
|
$news->publish = new \DateTime('2001-05-07');
|
||||||
$news->isFeatured = false;
|
$news->isFeatured = false;
|
||||||
$news->setLanguage(ISO639x1Enum::_DE);
|
$news->setLanguage(ISO639x1Enum::_DE);
|
||||||
$news->setStatus(NewsStatus::VISIBLE);
|
$news->setStatus(NewsStatus::VISIBLE);
|
||||||
|
|
@ -115,11 +115,11 @@ final class NewsArticleMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
$id = NewsArticleMapper::create($news);
|
$id = NewsArticleMapper::create($news);
|
||||||
|
|
||||||
$news = new NewsArticle();
|
$news = new NewsArticle();
|
||||||
$news->createdBy = new NullAccount(1);
|
$news->createdBy = new NullAccount(1);
|
||||||
$news->title = $text->generateText(\mt_rand(3, 7));
|
$news->title = $text->generateText(\mt_rand(3, 7));
|
||||||
$news->content = $text->generateText(\mt_rand(10, 300));
|
$news->content = $text->generateText(\mt_rand(10, 300));
|
||||||
$news->publish = new \DateTime('2001-05-07');
|
$news->publish = new \DateTime('2001-05-07');
|
||||||
$news->isFeatured = false;
|
$news->isFeatured = false;
|
||||||
$news->setLanguage(ISO639x1Enum::_DE);
|
$news->setLanguage(ISO639x1Enum::_DE);
|
||||||
$news->setStatus(NewsStatus::VISIBLE);
|
$news->setStatus(NewsStatus::VISIBLE);
|
||||||
|
|
@ -127,11 +127,11 @@ final class NewsArticleMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
$id = NewsArticleMapper::create($news);
|
$id = NewsArticleMapper::create($news);
|
||||||
|
|
||||||
$news = new NewsArticle();
|
$news = new NewsArticle();
|
||||||
$news->createdBy = new NullAccount(1);
|
$news->createdBy = new NullAccount(1);
|
||||||
$news->title = $text->generateText(\mt_rand(3, 7));
|
$news->title = $text->generateText(\mt_rand(3, 7));
|
||||||
$news->content = $text->generateText(\mt_rand(10, 300));
|
$news->content = $text->generateText(\mt_rand(10, 300));
|
||||||
$news->publish = new \DateTime('2001-05-07');
|
$news->publish = new \DateTime('2001-05-07');
|
||||||
$news->isFeatured = false;
|
$news->isFeatured = false;
|
||||||
$news->setLanguage(ISO639x1Enum::_DE);
|
$news->setLanguage(ISO639x1Enum::_DE);
|
||||||
$news->setStatus(NewsStatus::DRAFT);
|
$news->setStatus(NewsStatus::DRAFT);
|
||||||
|
|
@ -141,11 +141,11 @@ final class NewsArticleMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
// Language
|
// Language
|
||||||
|
|
||||||
$news = new NewsArticle();
|
$news = new NewsArticle();
|
||||||
$news->createdBy = new NullAccount(1);
|
$news->createdBy = new NullAccount(1);
|
||||||
$news->title = $text->generateText(\mt_rand(3, 7));
|
$news->title = $text->generateText(\mt_rand(3, 7));
|
||||||
$news->content = $text->generateText(\mt_rand(10, 300));
|
$news->content = $text->generateText(\mt_rand(10, 300));
|
||||||
$news->publish = new \DateTime('2001-05-07');
|
$news->publish = new \DateTime('2001-05-07');
|
||||||
$news->isFeatured = true;
|
$news->isFeatured = true;
|
||||||
$news->setLanguage(ISO639x1Enum::_EN);
|
$news->setLanguage(ISO639x1Enum::_EN);
|
||||||
$news->setStatus(NewsStatus::VISIBLE);
|
$news->setStatus(NewsStatus::VISIBLE);
|
||||||
|
|
@ -158,11 +158,11 @@ final class NewsArticleMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
$publishDate = new \DateTime('now');
|
$publishDate = new \DateTime('now');
|
||||||
$publishDate->modify('+1 days');
|
$publishDate->modify('+1 days');
|
||||||
|
|
||||||
$news = new NewsArticle();
|
$news = new NewsArticle();
|
||||||
$news->createdBy = new NullAccount(1);
|
$news->createdBy = new NullAccount(1);
|
||||||
$news->title = $text->generateText(\mt_rand(3, 7));
|
$news->title = $text->generateText(\mt_rand(3, 7));
|
||||||
$news->content = $text->generateText(\mt_rand(10, 300));
|
$news->content = $text->generateText(\mt_rand(10, 300));
|
||||||
$news->publish = $publishDate;
|
$news->publish = $publishDate;
|
||||||
$news->isFeatured = false;
|
$news->isFeatured = false;
|
||||||
$news->setLanguage(ISO639x1Enum::_DE);
|
$news->setLanguage(ISO639x1Enum::_DE);
|
||||||
$news->setStatus(NewsStatus::VISIBLE);
|
$news->setStatus(NewsStatus::VISIBLE);
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@ declare(strict_types=1);
|
||||||
namespace Modules\News\tests\Models;
|
namespace Modules\News\tests\Models;
|
||||||
|
|
||||||
use Modules\Admin\Models\NullAccount;
|
use Modules\Admin\Models\NullAccount;
|
||||||
|
use Modules\Media\Models\Media;
|
||||||
use Modules\News\Models\NewsArticle;
|
use Modules\News\Models\NewsArticle;
|
||||||
use Modules\News\Models\NewsStatus;
|
use Modules\News\Models\NewsStatus;
|
||||||
use Modules\News\Models\NewsType;
|
use Modules\News\Models\NewsType;
|
||||||
use phpOMS\Localization\ISO639x1Enum;
|
|
||||||
use Modules\Media\Models\Media;
|
|
||||||
use Modules\Tag\Models\Tag;
|
use Modules\Tag\Models\Tag;
|
||||||
|
use phpOMS\Localization\ISO639x1Enum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @testdox Modules\News\tests\Models\NewsArticleTest: News article
|
* @testdox Modules\News\tests\Models\NewsArticleTest: News article
|
||||||
|
|
@ -166,27 +166,27 @@ final class NewsArticleTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
public function testSerialization() : void
|
public function testSerialization() : void
|
||||||
{
|
{
|
||||||
$this->news->title = 'Title';
|
$this->news->title = 'Title';
|
||||||
$this->news->createdBy = new NullAccount(1);
|
$this->news->createdBy = new NullAccount(1);
|
||||||
$this->news->content = 'Content';
|
$this->news->content = 'Content';
|
||||||
$this->news->plain = 'Plain';
|
$this->news->plain = 'Plain';
|
||||||
$this->news->publish = new \DateTime('2001-05-07');
|
$this->news->publish = new \DateTime('2001-05-07');
|
||||||
$this->news->isFeatured = true;
|
$this->news->isFeatured = true;
|
||||||
$this->news->setLanguage(ISO639x1Enum::_DE);
|
$this->news->setLanguage(ISO639x1Enum::_DE);
|
||||||
$this->news->setStatus(NewsStatus::VISIBLE);
|
$this->news->setStatus(NewsStatus::VISIBLE);
|
||||||
$this->news->setType(NewsType::HEADLINE);
|
$this->news->setType(NewsType::HEADLINE);
|
||||||
|
|
||||||
$arr = [
|
$arr = [
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
'title' => $this->news->title,
|
'title' => $this->news->title,
|
||||||
'plain' => $this->news->plain,
|
'plain' => $this->news->plain,
|
||||||
'content' => $this->news->content,
|
'content' => $this->news->content,
|
||||||
'type' => $this->news->getType(),
|
'type' => $this->news->getType(),
|
||||||
'status' => $this->news->getStatus(),
|
'status' => $this->news->getStatus(),
|
||||||
'isFeatured' => $this->news->isFeatured,
|
'isFeatured' => $this->news->isFeatured,
|
||||||
'publish' => $this->news->publish,
|
'publish' => $this->news->publish,
|
||||||
'createdAt' => $this->news->createdAt,
|
'createdAt' => $this->news->createdAt,
|
||||||
'createdBy' => $this->news->createdBy,
|
'createdBy' => $this->news->createdBy,
|
||||||
];
|
];
|
||||||
|
|
||||||
self::assertEquals($arr, $this->news->toArray());
|
self::assertEquals($arr, $this->news->toArray());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user