mirror of
https://github.com/Karaka-Management/oms-Marketing.git
synced 2026-02-16 01:58:40 +00:00
add unit tests
This commit is contained in:
parent
a3434abcbb
commit
b30f51fd96
|
|
@ -18,10 +18,11 @@ use Modules\Admin\Models\Account;
|
||||||
use Modules\Admin\Models\NullAccount;
|
use Modules\Admin\Models\NullAccount;
|
||||||
use Modules\Calendar\Models\Calendar;
|
use Modules\Calendar\Models\Calendar;
|
||||||
use Modules\Tasks\Models\Task;
|
use Modules\Tasks\Models\Task;
|
||||||
|
use Modules\Tasks\Models\NullTask;
|
||||||
use phpOMS\Localization\Money;
|
use phpOMS\Localization\Money;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Project class.
|
* Promotion class.
|
||||||
*
|
*
|
||||||
* @package Modules\Marketing\Models
|
* @package Modules\Marketing\Models
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
|
|
@ -39,20 +40,20 @@ class Promotion
|
||||||
protected int $id = 0;
|
protected int $id = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start of the promotion.
|
* Event start.
|
||||||
*
|
*
|
||||||
* @var \DateTime
|
* @var \DateTime
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private \DateTime $start;
|
public \DateTime $start;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End of the promotion.
|
* Event end.
|
||||||
*
|
*
|
||||||
* @var \DateTime
|
* @var \DateTime
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private \DateTime $end;
|
public \DateTime $end;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name.
|
* Name.
|
||||||
|
|
@ -60,7 +61,7 @@ class Promotion
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private string $name = '';
|
public string $name = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* Description.
|
||||||
|
|
@ -76,7 +77,7 @@ class Promotion
|
||||||
* @var Calendar
|
* @var Calendar
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private Calendar $calendar;
|
public Calendar $calendar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Costs.
|
* Costs.
|
||||||
|
|
@ -84,7 +85,7 @@ class Promotion
|
||||||
* @var Money
|
* @var Money
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private Money $costs;
|
public Money $costs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Budget.
|
* Budget.
|
||||||
|
|
@ -92,7 +93,7 @@ class Promotion
|
||||||
* @var Money
|
* @var Money
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private Money $budget;
|
public Money $budget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Earnings.
|
* Earnings.
|
||||||
|
|
@ -100,7 +101,15 @@ class Promotion
|
||||||
* @var Money
|
* @var Money
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private Money $earnings;
|
public Money $earnings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tasks.
|
||||||
|
*
|
||||||
|
* @var Task[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private array $tasks = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Media.
|
* Media.
|
||||||
|
|
@ -116,7 +125,7 @@ class Promotion
|
||||||
* @var int
|
* @var int
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private int $progress = 0;
|
public int $progress = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Progress type.
|
* Progress type.
|
||||||
|
|
@ -127,7 +136,7 @@ class Promotion
|
||||||
private int $progressType = ProgressType::MANUAL;
|
private int $progressType = ProgressType::MANUAL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created at.
|
* Created.
|
||||||
*
|
*
|
||||||
* @var \DateTimeImmutable
|
* @var \DateTimeImmutable
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -135,7 +144,7 @@ class Promotion
|
||||||
public \DateTimeImmutable $createdAt;
|
public \DateTimeImmutable $createdAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by.
|
* Creator.
|
||||||
*
|
*
|
||||||
* @var Account
|
* @var Account
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -143,35 +152,24 @@ class Promotion
|
||||||
public Account $createdBy;
|
public Account $createdBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tasks.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @var Task[]
|
* @param string $name Event name/title
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private array $tasks = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cosntructor
|
|
||||||
*
|
|
||||||
* @param string $name Promotion name
|
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct(string $name = '')
|
public function __construct(string $name = '')
|
||||||
{
|
{
|
||||||
$this->start = new \DateTime('now');
|
$this->start = new \DateTime('now');
|
||||||
$this->end = new \DateTime('now');
|
$this->end = (new \DateTime('now'))->modify('+1 month');
|
||||||
$this->end->modify('+1 month');
|
$this->calendar = new Calendar();
|
||||||
|
$this->costs = new Money();
|
||||||
|
$this->budget = new Money();
|
||||||
|
$this->earnings = new Money();
|
||||||
$this->createdAt = new \DateTimeImmutable('now');
|
$this->createdAt = new \DateTimeImmutable('now');
|
||||||
$this->createdBy = new NullAccount();
|
$this->createdBy = new NullAccount();
|
||||||
|
|
||||||
$this->calendar = new Calendar();
|
$this->name = $name;
|
||||||
|
|
||||||
$this->costs = new Money();
|
|
||||||
$this->budget = new Money();
|
|
||||||
$this->earnings = new Money();
|
|
||||||
|
|
||||||
$this->setName($name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -212,6 +210,32 @@ class Promotion
|
||||||
$this->media[] = $media;
|
$this->media[] = $media;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get progress type.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getProgressType() : int
|
||||||
|
{
|
||||||
|
return $this->progressType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set progress type.
|
||||||
|
*
|
||||||
|
* @param int $type Progress type
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setProgressType(int $type) : void
|
||||||
|
{
|
||||||
|
$this->progressType = $type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add task.
|
* Add task.
|
||||||
*
|
*
|
||||||
|
|
@ -223,11 +247,7 @@ class Promotion
|
||||||
*/
|
*/
|
||||||
public function addTask(Task $task) : void
|
public function addTask(Task $task) : void
|
||||||
{
|
{
|
||||||
if ($task->getId() !== 0) {
|
$this->tasks[] = $task;
|
||||||
$this->tasks[$task->getId()] = $task;
|
|
||||||
} else {
|
|
||||||
$this->tasks[] = $task;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -261,7 +281,7 @@ class Promotion
|
||||||
*/
|
*/
|
||||||
public function getTask(int $id) : Task
|
public function getTask(int $id) : Task
|
||||||
{
|
{
|
||||||
return $this->tasks[$id] ?? new Task();
|
return $this->tasks[$id] ?? new NullTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -289,223 +309,33 @@ class Promotion
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get start date.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
public function getStart() : \DateTime
|
public function toArray() : array
|
||||||
{
|
{
|
||||||
return $this->start;
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'start' => $this->start,
|
||||||
|
'end' => $this->end,
|
||||||
|
'name' => $this->name,
|
||||||
|
'description' => $this->description,
|
||||||
|
'calendar' => $this->calendar,
|
||||||
|
'costs' => $this->costs,
|
||||||
|
'budget' => $this->budget,
|
||||||
|
'earnings' => $this->earnings,
|
||||||
|
'tasks' => $this->tasks,
|
||||||
|
'media' => $this->media,
|
||||||
|
'progress' => $this->progress,
|
||||||
|
'progressType' => $this->progressType,
|
||||||
|
'createdAt' => $this->createdAt,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set start date.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param \DateTime $start Start date
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
public function setStart(\DateTime $start) : void
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
$this->start = $start;
|
return $this->toArray();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set end.
|
|
||||||
*
|
|
||||||
* @param \DateTime $end End date
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setEnd(\DateTime $end) : void
|
|
||||||
{
|
|
||||||
$this->end = $end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get end.
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getEnd() : \DateTime
|
|
||||||
{
|
|
||||||
return $this->end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get progress.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getProgress() : int
|
|
||||||
{
|
|
||||||
return $this->progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set progress.
|
|
||||||
*
|
|
||||||
* @param int $progress Progress
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setProgress(int $progress) : void
|
|
||||||
{
|
|
||||||
$this->progress = $progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get progress type.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getProgressType() : int
|
|
||||||
{
|
|
||||||
return $this->progressType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set progress type.
|
|
||||||
*
|
|
||||||
* @param int $type Progress type
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setProgressType(int $type) : void
|
|
||||||
{
|
|
||||||
$this->progressType = $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get calendar.
|
|
||||||
*
|
|
||||||
* @return Calendar
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getCalendar() : Calendar
|
|
||||||
{
|
|
||||||
return $this->calendar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get name
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getName() : string
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set name
|
|
||||||
*
|
|
||||||
* @param string $name Name
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setName(string $name) : void
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
$this->calendar->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get costs.
|
|
||||||
*
|
|
||||||
* @return Money
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getCosts() : Money
|
|
||||||
{
|
|
||||||
return $this->costs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get budget.
|
|
||||||
*
|
|
||||||
* @return Money
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getBudget() : Money
|
|
||||||
{
|
|
||||||
return $this->budget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get earnings.
|
|
||||||
*
|
|
||||||
* @return Money
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getEarnings() : Money
|
|
||||||
{
|
|
||||||
return $this->earnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set costs.
|
|
||||||
*
|
|
||||||
* @param Money $costs Costs
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setCosts(Money $costs) : void
|
|
||||||
{
|
|
||||||
$this->costs = $costs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set budget.
|
|
||||||
*
|
|
||||||
* @param Money $budget Budget
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setBudget(Money $budget) : void
|
|
||||||
{
|
|
||||||
$this->budget = $budget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set earnings.
|
|
||||||
*
|
|
||||||
* @param Money $earnings Earnings
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setEarnings(Money $earnings) : void
|
|
||||||
{
|
|
||||||
$this->earnings = $earnings;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ namespace Modules\Marketing\tests\Models;
|
||||||
use Modules\Admin\Models\NullAccount;
|
use Modules\Admin\Models\NullAccount;
|
||||||
use Modules\Marketing\Models\Promotion;
|
use Modules\Marketing\Models\Promotion;
|
||||||
use Modules\Marketing\Models\PromotionMapper;
|
use Modules\Marketing\Models\PromotionMapper;
|
||||||
|
use Modules\Marketing\Models\ProgressType;
|
||||||
use Modules\Media\Models\Media;
|
use Modules\Media\Models\Media;
|
||||||
use Modules\Tasks\Models\Task;
|
use Modules\Tasks\Models\Task;
|
||||||
use phpOMS\Localization\Money;
|
use phpOMS\Localization\Money;
|
||||||
|
|
@ -35,37 +36,40 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$promotion = new Promotion();
|
$promotion = new Promotion();
|
||||||
|
|
||||||
$promotion->setName('Promotionname');
|
$promotion->name = 'Promotionname';
|
||||||
$promotion->description = 'Description';
|
$promotion->description = 'Description';
|
||||||
$promotion->createdBy = new NullAccount(1);
|
$promotion->createdBy = new NullAccount(1);
|
||||||
$promotion->setStart(new \DateTime('2000-05-05'));
|
$promotion->start = new \DateTime('2000-05-05');
|
||||||
$promotion->setEnd(new \DateTime('2005-05-05'));
|
$promotion->end = new \DateTime('2005-05-05');
|
||||||
|
|
||||||
$money = new Money();
|
$money = new Money();
|
||||||
$money->setString('1.23');
|
$money->setString('1.23');
|
||||||
|
|
||||||
$promotion->setCosts($money);
|
$promotion->costs = $money;
|
||||||
$promotion->setBudget($money);
|
$promotion->budget = $money;
|
||||||
$promotion->setEarnings($money);
|
$promotion->earnings = $money;
|
||||||
|
|
||||||
$task = new Task();
|
$task = new Task();
|
||||||
$task->title = 'PromotionTask 1';
|
$task->title = 'EventTask 1';
|
||||||
$task->setCreatedBy(new NullAccount(1));
|
$task->setCreatedBy(new NullAccount(1));
|
||||||
|
|
||||||
$task2 = new Task();
|
$task2 = new Task();
|
||||||
$task2->title = 'PromotionTask 2';
|
$task2->title = 'EventTask 2';
|
||||||
$task2->setCreatedBy(new NullAccount(1));
|
$task2->setCreatedBy(new NullAccount(1));
|
||||||
|
|
||||||
$promotion->addTask($task);
|
$promotion->addTask($task);
|
||||||
$promotion->addTask($task2);
|
$promotion->addTask($task2);
|
||||||
|
|
||||||
|
$promotion->progress = 11;
|
||||||
|
$promotion->setProgressType(ProgressType::TASKS);
|
||||||
|
|
||||||
$media = new Media();
|
$media = new Media();
|
||||||
$media->createdBy = new NullAccount(1);
|
$media->createdBy = new NullAccount(1);
|
||||||
$media->description = 'desc';
|
$media->description = 'desc';
|
||||||
$media->setPath('some/path');
|
$media->setPath('some/path');
|
||||||
$media->size = 11;
|
$media->size = 11;
|
||||||
$media->extension = 'png';
|
$media->extension = 'png';
|
||||||
$media->name = 'Promotion Media';
|
$media->name = 'Event Media';
|
||||||
$promotion->addMedia($media);
|
$promotion->addMedia($media);
|
||||||
|
|
||||||
$id = PromotionMapper::create($promotion);
|
$id = PromotionMapper::create($promotion);
|
||||||
|
|
@ -74,15 +78,16 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
$promotionR = PromotionMapper::get($promotion->getId());
|
$promotionR = PromotionMapper::get($promotion->getId());
|
||||||
|
|
||||||
self::assertEquals($promotion->getName(), $promotionR->getName());
|
self::assertEquals($promotion->name, $promotionR->name);
|
||||||
self::assertEquals($promotion->description, $promotionR->description);
|
self::assertEquals($promotion->description, $promotionR->description);
|
||||||
self::assertEquals($promotion->countTasks(), $promotionR->countTasks());
|
self::assertEquals($promotion->countTasks(), $promotionR->countTasks());
|
||||||
self::assertEquals($promotion->getCosts()->getAmount(), $promotionR->getCosts()->getAmount());
|
self::assertEquals($promotion->start->format('Y-m-d'), $promotionR->start->format('Y-m-d'));
|
||||||
self::assertEquals($promotion->getBudget()->getAmount(), $promotionR->getBudget()->getAmount());
|
self::assertEquals($promotion->end->format('Y-m-d'), $promotionR->end->format('Y-m-d'));
|
||||||
self::assertEquals($promotion->getEarnings()->getAmount(), $promotionR->getEarnings()->getAmount());
|
self::assertEquals($promotion->costs->getAmount(), $promotionR->costs->getAmount());
|
||||||
self::assertEquals($promotion->createdAt->format('Y-m-d'), $promotionR->createdAt->format('Y-m-d'));
|
self::assertEquals($promotion->budget->getAmount(), $promotionR->budget->getAmount());
|
||||||
self::assertEquals($promotion->getStart()->format('Y-m-d'), $promotionR->getStart()->format('Y-m-d'));
|
self::assertEquals($promotion->earnings->getAmount(), $promotionR->earnings->getAmount());
|
||||||
self::assertEquals($promotion->getEnd()->format('Y-m-d'), $promotionR->getEnd()->format('Y-m-d'));
|
self::assertEquals($promotion->progress, $promotionR->progress);
|
||||||
|
self::assertEquals($promotion->getProgressType(), $promotionR->getProgressType());
|
||||||
|
|
||||||
$expected = $promotion->getMedia();
|
$expected = $promotion->getMedia();
|
||||||
$actual = $promotionR->getMedia();
|
$actual = $promotionR->getMedia();
|
||||||
|
|
@ -100,33 +105,4 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
self::assertCount(1, $newest);
|
self::assertCount(1, $newest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group volume
|
|
||||||
* @group module
|
|
||||||
* @coversNothing
|
|
||||||
*/
|
|
||||||
public function testVolume() : void
|
|
||||||
{
|
|
||||||
for ($i = 1; $i < 100; ++$i) {
|
|
||||||
$text = new Text();
|
|
||||||
|
|
||||||
$promotion = new Promotion();
|
|
||||||
|
|
||||||
$promotion->setName($text->generateText(\mt_rand(3, 7)));
|
|
||||||
$promotion->description = $text->generateText(\mt_rand(20, 100));
|
|
||||||
$promotion->createdBy = new NullAccount(1);
|
|
||||||
$promotion->setStart(new \DateTime('2000-05-05'));
|
|
||||||
$promotion->setEnd(new \DateTime('2005-05-05'));
|
|
||||||
|
|
||||||
$money = new Money();
|
|
||||||
$money->setString('1.23');
|
|
||||||
|
|
||||||
$promotion->setCosts($money);
|
|
||||||
$promotion->setBudget($money);
|
|
||||||
$promotion->setEarnings($money);
|
|
||||||
|
|
||||||
$id = PromotionMapper::create($promotion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,9 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Marketing\tests\Models;
|
namespace Modules\Marketing\tests\Models;
|
||||||
|
|
||||||
use Modules\Admin\Models\NullAccount;
|
|
||||||
use Modules\Marketing\Models\Promotion;
|
use Modules\Marketing\Models\Promotion;
|
||||||
|
use Modules\Marketing\Models\ProgressType;
|
||||||
|
use Modules\Media\Models\Media;
|
||||||
use Modules\Tasks\Models\Task;
|
use Modules\Tasks\Models\Task;
|
||||||
use phpOMS\Localization\Money;
|
use phpOMS\Localization\Money;
|
||||||
|
|
||||||
|
|
@ -24,71 +25,158 @@ use phpOMS\Localization\Money;
|
||||||
*/
|
*/
|
||||||
final class PromotionTest extends \PHPUnit\Framework\TestCase
|
final class PromotionTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
private Promotion $promotion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->promotion = new Promotion();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Modules\Marketing\Models\Promotion
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
* @group module
|
* @group module
|
||||||
*/
|
*/
|
||||||
public function testDefault() : void
|
public function testDefault() : void
|
||||||
{
|
{
|
||||||
$promotion = new Promotion();
|
self::assertEquals(0, $this->promotion->getId());
|
||||||
|
self::assertInstanceOf('\Modules\Calendar\Models\Calendar', $this->promotion->calendar);
|
||||||
self::assertEquals(0, $promotion->getId());
|
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->promotion->start->format('Y-m-d'));
|
||||||
self::assertInstanceOf('\Modules\Calendar\Models\Calendar', $promotion->getCalendar());
|
self::assertEquals((new \DateTime('now'))->modify('+1 month')->format('Y-m-d'), $this->promotion->end->format('Y-m-d'));
|
||||||
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $promotion->createdAt->format('Y-m-d'));
|
self::assertEquals(0, $this->promotion->costs->getInt());
|
||||||
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $promotion->getStart()->format('Y-m-d'));
|
self::assertEquals(0, $this->promotion->budget->getInt());
|
||||||
self::assertEquals((new \DateTime('now'))->modify('+1 month')->format('Y-m-d'), $promotion->getEnd()->format('Y-m-d'));
|
self::assertEquals(0, $this->promotion->earnings->getInt());
|
||||||
self::assertEquals(0, $promotion->createdBy->getId());
|
self::assertFalse($this->promotion->removeTask(2));
|
||||||
self::assertEquals('', $promotion->getName());
|
self::assertEmpty($this->promotion->getTasks());
|
||||||
self::assertEquals('', $promotion->description);
|
self::assertEmpty($this->promotion->getMedia());
|
||||||
self::assertEquals(0, $promotion->getCosts()->getInt());
|
self::assertInstanceOf('\Modules\Tasks\Models\NullTask', $this->promotion->getTask(1));
|
||||||
self::assertEquals(0, $promotion->getBudget()->getInt());
|
self::assertEquals(0, $this->promotion->progress);
|
||||||
self::assertEquals(0, $promotion->getEarnings()->getInt());
|
self::assertEquals(ProgressType::MANUAL, $this->promotion->getProgressType());
|
||||||
self::assertEmpty($promotion->getTasks());
|
|
||||||
self::assertFalse($promotion->removeTask(2));
|
|
||||||
self::assertInstanceOf('\Modules\Tasks\Models\Task', $promotion->getTask(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Modules\Marketing\Models\Promotion
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
* @group module
|
* @group module
|
||||||
*/
|
*/
|
||||||
public function testSetGet() : void
|
public function testCostsInputOutput() : void
|
||||||
{
|
{
|
||||||
$promotion = new Promotion();
|
|
||||||
|
|
||||||
$promotion->setName('Promotion');
|
|
||||||
self::assertEquals('Promotion', $promotion->getName());
|
|
||||||
|
|
||||||
$promotion->description = 'Description';
|
|
||||||
self::assertEquals('Description', $promotion->description);
|
|
||||||
|
|
||||||
$promotion->setStart($date = new \DateTime('2000-05-05'));
|
|
||||||
self::assertEquals($date->format('Y-m-d'), $promotion->getStart()->format('Y-m-d'));
|
|
||||||
|
|
||||||
$promotion->setEnd($date = new \DateTime('2000-05-05'));
|
|
||||||
self::assertEquals($date->format('Y-m-d'), $promotion->getEnd()->format('Y-m-d'));
|
|
||||||
|
|
||||||
$money = new Money();
|
$money = new Money();
|
||||||
$money->setString('1.23');
|
$money->setString('1.23');
|
||||||
|
|
||||||
$promotion->setCosts($money);
|
$this->promotion->costs = $money;
|
||||||
self::assertEquals($money->getAmount(), $promotion->getCosts()->getAmount());
|
self::assertEquals($money->getAmount(), $this->promotion->costs->getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
$promotion->setBudget($money);
|
/**
|
||||||
self::assertEquals($money->getAmount(), $promotion->getBudget()->getAmount());
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testBudgetInputOutput() : void
|
||||||
|
{
|
||||||
|
$money = new Money();
|
||||||
|
$money->setString('1.23');
|
||||||
|
|
||||||
$promotion->setEarnings($money);
|
$this->promotion->budget = $money;
|
||||||
self::assertEquals($money->getAmount(), $promotion->getEarnings()->getAmount());
|
self::assertEquals($money->getAmount(), $this->promotion->budget->getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testEarningsInputOutput() : void
|
||||||
|
{
|
||||||
|
$money = new Money();
|
||||||
|
$money->setString('1.23');
|
||||||
|
|
||||||
|
$this->promotion->earnings = $money;
|
||||||
|
self::assertEquals($money->getAmount(), $this->promotion->earnings->getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testMediaInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->promotion->addMedia(new Media());
|
||||||
|
self::assertCount(1, $this->promotion->getMedia());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testTaskInputOutput() : void
|
||||||
|
{
|
||||||
$task = new Task();
|
$task = new Task();
|
||||||
$task->title = 'Promo Task A';
|
$task->title = 'A';
|
||||||
$task->setCreatedBy(new NullAccount(1));
|
|
||||||
|
|
||||||
$promotion->addTask($task);
|
$this->promotion->addTask($task);
|
||||||
|
self::assertEquals('A', $this->promotion->getTask(0)->title);
|
||||||
|
|
||||||
self::assertEquals('Promo Task A', $promotion->getTask(0)->title);
|
self::assertTrue($this->promotion->removeTask(0));
|
||||||
self::assertCount(1, $promotion->getTasks());
|
self::assertEquals(0, $this->promotion->countTasks());
|
||||||
self::assertTrue($promotion->removeTask(0));
|
|
||||||
self::assertEquals(0, $promotion->countTasks());
|
$this->promotion->addTask($task);
|
||||||
|
self::assertCount(1, $this->promotion->getTasks());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testProgressInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->promotion->progress = 10;
|
||||||
|
self::assertEquals(10, $this->promotion->progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testProgressTypeInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->promotion->setProgressType(ProgressType::TASKS);
|
||||||
|
self::assertEquals(ProgressType::TASKS, $this->promotion->getProgressType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Marketing\Models\Promotion
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testSerialize() : void
|
||||||
|
{
|
||||||
|
$this->promotion->name = 'Name';
|
||||||
|
$this->promotion->description = 'Description';
|
||||||
|
$this->promotion->start = new \DateTime();
|
||||||
|
$this->promotion->end = new \DateTime();
|
||||||
|
$this->promotion->progress = 10;
|
||||||
|
$this->promotion->setProgressType(ProgressType::TASKS);
|
||||||
|
|
||||||
|
$serialized = $this->promotion->jsonSerialize();
|
||||||
|
unset($serialized['calendar']);
|
||||||
|
unset($serialized['createdAt']);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
'id' => 0,
|
||||||
|
'start' => $this->promotion->start,
|
||||||
|
'end' => $this->promotion->end,
|
||||||
|
'name' => 'Name',
|
||||||
|
'description' => 'Description',
|
||||||
|
'costs' => new Money(),
|
||||||
|
'budget' => new Money(),
|
||||||
|
'earnings' => new Money(),
|
||||||
|
'tasks' => [],
|
||||||
|
'media' => [],
|
||||||
|
'progress' => 10,
|
||||||
|
'progressType' => ProgressType::TASKS,
|
||||||
|
],
|
||||||
|
$serialized
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Bootstrap.php" colors="true" stopOnError="true" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Bootstrap.php" colors="true" columns="120" stopOnError="true" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
<coverage includeUncoveredFiles="true" processUncoveredFiles="false">
|
<coverage includeUncoveredFiles="true" processUncoveredFiles="false">
|
||||||
<exclude>
|
<exclude>
|
||||||
<directory>*vendor*</directory>
|
<directory>*vendor*</directory>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user