mirror of
https://github.com/Karaka-Management/oms-Marketing.git
synced 2026-01-31 19:08:41 +00:00
add tests
This commit is contained in:
parent
5272c1b136
commit
cfe0912f7d
26
tests/Admin/AdminTest.php
Normal file
26
tests/Admin/AdminTest.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @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\tests\Marketing\Admin;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class AdminTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected const MODULE_NAME = 'Marketing';
|
||||
protected const URI_LOAD = '';
|
||||
|
||||
use \Modules\tests\ModuleTestTrait;
|
||||
}
|
||||
124
tests/Models/PromotionMapperTest.php
Normal file
124
tests/Models/PromotionMapperTest.php
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @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\tests\Marketing\Models;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Marketing\Models\Promotion;
|
||||
use Modules\Marketing\Models\PromotionMapper;
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Tasks\Models\Task;
|
||||
use phpOMS\Localization\Money;
|
||||
use phpOMS\Utils\RnG\Text;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class PromotionMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testCRUD() : void
|
||||
{
|
||||
$promotion = new Promotion();
|
||||
|
||||
$promotion->setName('Promotionname');
|
||||
$promotion->setDescription('Description');
|
||||
$promotion->setCreatedBy(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);
|
||||
|
||||
$task = new Task();
|
||||
$task->setTitle('PromotionTask 1');
|
||||
$task->setCreatedBy(new NullAccount(1));
|
||||
|
||||
$task2 = new Task();
|
||||
$task2->setTitle('PromotionTask 2');
|
||||
$task2->setCreatedBy(new NullAccount(1));
|
||||
|
||||
$promotion->addTask($task);
|
||||
$promotion->addTask($task2);
|
||||
|
||||
$media = new Media();
|
||||
$media->setCreatedBy(new NullAccount(1));
|
||||
$media->setDescription('desc');
|
||||
$media->setPath('some/path');
|
||||
$media->setSize(11);
|
||||
$media->setExtension('png');
|
||||
$media->setName('Promotion Media');
|
||||
$promotion->addMedia($media);
|
||||
|
||||
$id = PromotionMapper::create($promotion);
|
||||
self::assertGreaterThan(0, $promotion->getId());
|
||||
self::assertEquals($id, $promotion->getId());
|
||||
|
||||
$promotionR = PromotionMapper::get($promotion->getId());
|
||||
|
||||
self::assertEquals($promotion->getName(), $promotionR->getName());
|
||||
self::assertEquals($promotion->getDescription(), $promotionR->getDescription());
|
||||
self::assertEquals($promotion->countTasks(), $promotionR->countTasks());
|
||||
self::assertEquals($promotion->getCosts()->getAmount(), $promotionR->getCosts()->getAmount());
|
||||
self::assertEquals($promotion->getBudget()->getAmount(), $promotionR->getBudget()->getAmount());
|
||||
self::assertEquals($promotion->getEarnings()->getAmount(), $promotionR->getEarnings()->getAmount());
|
||||
self::assertEquals($promotion->getCreatedAt()->format('Y-m-d'), $promotionR->getCreatedAt()->format('Y-m-d'));
|
||||
self::assertEquals($promotion->getStart()->format('Y-m-d'), $promotionR->getStart()->format('Y-m-d'));
|
||||
self::assertEquals($promotion->getEnd()->format('Y-m-d'), $promotionR->getEnd()->format('Y-m-d'));
|
||||
|
||||
$expected = $promotion->getMedia();
|
||||
$actual = $promotionR->getMedia();
|
||||
|
||||
self::assertEquals(\end($expected)->getName(), \end($actual)->getName());
|
||||
}
|
||||
|
||||
public function testNewest() : void
|
||||
{
|
||||
$newest = PromotionMapper::getNewest(1);
|
||||
|
||||
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->setDescription($text->generateText(\mt_rand(20, 100)));
|
||||
$promotion->setCreatedBy(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
86
tests/Models/PromotionTest.php
Normal file
86
tests/Models/PromotionTest.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @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\tests\Marketing\Models;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Marketing\Models\Promotion;
|
||||
use Modules\Tasks\Models\Task;
|
||||
use phpOMS\Localization\Money;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class PromotionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testDefault() : void
|
||||
{
|
||||
$promotion = new Promotion();
|
||||
|
||||
self::assertEquals(0, $promotion->getId());
|
||||
self::assertInstanceOf('\Modules\Calendar\Models\Calendar', $promotion->getCalendar());
|
||||
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $promotion->getCreatedAt()->format('Y-m-d'));
|
||||
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $promotion->getStart()->format('Y-m-d'));
|
||||
self::assertEquals((new \DateTime('now'))->modify('+1 month')->format('Y-m-d'), $promotion->getEnd()->format('Y-m-d'));
|
||||
self::assertEquals(0, $promotion->getCreatedBy()->getId());
|
||||
self::assertEquals('', $promotion->getName());
|
||||
self::assertEquals('', $promotion->getDescription());
|
||||
self::assertEquals(0, $promotion->getCosts()->getInt());
|
||||
self::assertEquals(0, $promotion->getBudget()->getInt());
|
||||
self::assertEquals(0, $promotion->getEarnings()->getInt());
|
||||
self::assertEmpty($promotion->getTasks());
|
||||
self::assertFalse($promotion->removeTask(2));
|
||||
self::assertInstanceOf('\Modules\Tasks\Models\Task', $promotion->getTask(0));
|
||||
}
|
||||
|
||||
public function testSetGet() : void
|
||||
{
|
||||
$promotion = new Promotion();
|
||||
|
||||
$promotion->setName('Promotion');
|
||||
self::assertEquals('Promotion', $promotion->getName());
|
||||
|
||||
$promotion->setDescription('Description');
|
||||
self::assertEquals('Description', $promotion->getDescription());
|
||||
|
||||
$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->setString('1.23');
|
||||
|
||||
$promotion->setCosts($money);
|
||||
self::assertEquals($money->getAmount(), $promotion->getCosts()->getAmount());
|
||||
|
||||
$promotion->setBudget($money);
|
||||
self::assertEquals($money->getAmount(), $promotion->getBudget()->getAmount());
|
||||
|
||||
$promotion->setEarnings($money);
|
||||
self::assertEquals($money->getAmount(), $promotion->getEarnings()->getAmount());
|
||||
|
||||
$task = new Task();
|
||||
$task->setTitle('Promo Task A');
|
||||
$task->setCreatedBy(new NullAccount(1));
|
||||
|
||||
$promotion->addTask($task);
|
||||
|
||||
self::assertEquals('Promo Task A', $promotion->getTask(0)->getTitle());
|
||||
self::assertCount(1, $promotion->getTasks());
|
||||
self::assertTrue($promotion->removeTask(0));
|
||||
self::assertEquals(0, $promotion->countTasks());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user