Move models to framework

This commit is contained in:
Dennis Eichhorn 2018-10-02 21:23:06 +02:00
parent 6766ed562a
commit 847c8d2a42
15 changed files with 1451 additions and 0 deletions

188
Model/Message/Dom.php Normal file
View File

@ -0,0 +1,188 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Model\Message
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Model\Message;
use phpOMS\Contract\ArrayableInterface;
/**
* Dom class.
*
* @package phpOMS\Model\Message
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Dom implements \Serializable, ArrayableInterface
{
/**
* Message type.
*
* @var string
* @since 1.0.0
*/
public const TYPE = 'dom';
/**
* Selector string.
*
* @var string
* @since 1.0.0
*/
private $selector = '';
/**
* Dom content.
*
* @var string
* @since 1.0.0
*/
private $content = '';
/**
* Dom action.
*
* @var int
* @since 1.0.0
*/
private $action = DomAction::MODIFY;
/**
* Delay in ms.
*
* @var int
* @since 1.0.0
*/
private $delay = 0;
/**
* Set DOM content
*
* @param string $content DOM Content
*
* @return void
*
* @since 1.0.0
*/
public function setContent(string $content) : void
{
$this->content = $content;
}
/**
* Set selector.
*
* @param string $selector Selector
*
* @return void
*
* @since 1.0.0
*/
public function setSelector(string $selector) : void
{
$this->selector = $selector;
}
/**
* Set action.
*
* @param int $action action
*
* @return void
*
* @since 1.0.0
*/
public function setAction(int $action) : void
{
$this->action = $action;
}
/**
* Set delay.
*
* @param int $delay Delay in ms
*
* @return void
*
* @since 1.0.0
*/
public function setDelay(int $delay) : void
{
$this->delay = $delay;
}
/**
* Render message.
*
* @return string
*
* @since 1.0.0
*/
public function serialize() : string
{
return $this->__toString();
}
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* {@inheritdoc}
*/
public function unserialize($raw)
{
$unserialized = \json_decode($raw, true);
$this->delay = $unserialized['time'] ?? 0;
$this->selector = $unserialized['selector'] ?? '';
$this->action = $unserialized['action'] ?? '';
$this->content = $unserialized['content'] ?? '';
}
/**
* Stringify.
*
* @return string
*
* @since 1.0.0
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* Generate message array.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function toArray() : array
{
return [
'type' => self::TYPE,
'time' => $this->delay,
'selector' => $this->selector,
'action' => $this->action,
'content' => $this->content,
];
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Model\Message
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Model\Message;
use phpOMS\Stdlib\Base\Enum;
/**
* DomAction class.
*
* @package phpOMS\Model\Message
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
abstract class DomAction extends Enum
{
public const CREATE_BEFORE = 0;
public const CREATE_AFTER = 1;
public const DELETE = 2;
public const REPLACE = 3;
public const MODIFY = 4;
public const SHOW = 5;
public const HIDE = 6;
public const ACTIVATE = 7;
public const DEACTIVATE = 8;
}

View File

@ -0,0 +1,118 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Model\Message
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Model\Message;
use phpOMS\Contract\ArrayableInterface;
/**
* FormValidation class.
*
* @package phpOMS\Model\Message
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class FormValidation implements \Serializable, ArrayableInterface, \JsonSerializable
{
/**
* Message type.
*
* @var string
* @since 1.0.0
*/
public const TYPE = 'validation';
/**
* Form validation result.
*
* @var array
* @since 1.0.0
*/
private $validation = [];
/**
* Constructor.
*
* @param array $validation Invalid data
*
* @since 1.0.0
*/
public function __construct(array $validation = [])
{
$this->validation = $validation;
}
/**
* Render message.
*
* @return string
*
* @since 1.0.0
*/
public function serialize() : string
{
return $this->__toString();
}
/**
* Render message.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* {@inheritdoc}
*/
public function unserialize($raw)
{
$unserialized = \json_decode($raw, true);
$this->validation = $unserialized['validation'] ?? [];
}
/**
* Stringify.
*
* @return string
*
* @since 1.0.0
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* Generate message array.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function toArray() : array
{
return [
'type' => self::TYPE,
'validation' => $this->validation
];
}
}

230
Model/Message/Notify.php Normal file
View File

@ -0,0 +1,230 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Model\Message
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Model\Message;
use phpOMS\Contract\ArrayableInterface;
/**
* Notify class.
*
* @package phpOMS\Model\Message
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Notify implements \Serializable, ArrayableInterface
{
/**
* Message type.
*
* @var string
* @since 1.0.0
*/
public const TYPE = 'notify';
/**
* Notification title.
*
* @var string
* @since 1.0.0
*/
private $title = '';
/**
* Message.
*
* @var string
* @since 1.0.0
*/
private $message = '';
/**
* Delay in ms.
*
* @var int
* @since 1.0.0
*/
private $delay = 0;
/**
* Stay in ms.
*
* @var int
* @since 1.0.0
*/
private $stay = 0;
/**
* Level or type.
*
* @var int
* @since 1.0.0
*/
private $level = NotifyType::INFO;
/**
* Constructor.
*
* @param string $msg Message
* @param int $level Message level
*
* @since 1.0.0
*/
public function __construct(string $msg = '', int $level = NotifyType::INFO)
{
$this->message = $msg;
$this->level = $level;
}
/**
* Set delay.
*
* @param int $delay Delay in ms
*
* @return void
*
* @since 1.0.0
*/
public function setDelay(int $delay) : void
{
$this->delay = $delay;
}
/**
* Set delay.
*
* @param int $stay Stay in ms
*
* @return void
*
* @since 1.0.0
*/
public function setStay(int $stay) : void
{
$this->stay = $stay;
}
/**
* Set title.
*
* @param string $title Title
*
* @return void
*
* @since 1.0.0
*/
public function setTitle(string $title) : void
{
$this->title = $title;
}
/**
* Set message.
*
* @param string $message Message
*
* @return void
*
* @since 1.0.0
*/
public function setMessage(string $message) : void
{
$this->message = $message;
}
/**
* Set level/type.
*
* @param int $level Notification type/level
*
* @return void
*
* @since 1.0.0
*/
public function setLevel(int $level) : void
{
$this->level = $level;
}
/**
* Render message.
*
* @return string
*
* @since 1.0.0
*/
public function serialize() : string
{
return $this->__toString();
}
/**
* Render message.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* {@inheritdoc}
*/
public function unserialize($raw)
{
$unserialized = \json_decode($raw, true);
$this->delay = $unserialized['time'] ?? 0;
$this->stay = $unserialized['stay'] ?? '';
$this->message = $unserialized['msg'] ?? '';
$this->title = $unserialized['title'] ?? '';
$this->level = $unserialized['level'] ?? 0;
}
/**
* Stringify.
*
* @return string
*
* @since 1.0.0
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* Generate message array.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function toArray() : array
{
return [
'type' => self::TYPE,
'time' => $this->delay,
'stay' => $this->stay,
'msg' => $this->message,
'title' => $this->title,
'level' => $this->level,
];
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Model\Message
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Model\Message;
use phpOMS\Stdlib\Base\Enum;
/**
* NotifyType class.
*
* @package phpOMS\Model\Message
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
abstract class NotifyType extends Enum
{
public const BINARY = 0;
public const INFO = 1;
public const WARNING = 2;
public const ERROR = 3;
public const FATAL = 4;
}

168
Model/Message/Redirect.php Normal file
View File

@ -0,0 +1,168 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Model\Message
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Model\Message;
use phpOMS\Contract\ArrayableInterface;
/**
* Redirect class.
*
* @package phpOMS\Model\Message
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Redirect implements \Serializable, ArrayableInterface, \JsonSerializable
{
/**
* Message type.
*
* @var string
* @since 1.0.0
*/
public const TYPE = 'redirect';
/**
* Redirect uri.
*
* @var string
* @since 1.0.0
*/
private $uri = '';
/**
* Delay.
*
* @var int
* @since 1.0.0
*/
private $delay = 0;
/**
* Window.
*
* @var bool
* @since 1.0.0
*/
private $new = false;
/**
* Constructor.
*
* @param string $url Url
* @param bool $blank New window
*
* @since 1.0.0
*/
public function __construct(string $url = '', bool $blank = false)
{
$this->uri = $url;
$this->new = $blank;
}
/**
* Set delay.
*
* @param int $delay Delay in ms
*
* @return void
*
* @since 1.0.0
*/
public function setDelay(int $delay) : void
{
$this->delay = $delay;
}
/**
* Set uri.
*
* @param string $uri Uri
*
* @return void
*
* @since 1.0.0
*/
public function setUri(string $uri) : void
{
$this->uri = $uri;
}
/**
* Render message.
*
* @return string
*
* @since 1.0.0
*/
public function serialize() : string
{
return $this->__toString();
}
/**
* Render message.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* {@inheritdoc}
*/
public function unserialize($raw)
{
$unserialized = \json_decode($raw, true);
$this->delay = $unserialized['time'] ?? 0;
$this->uri = $unserialized['uri'] ?? '';
$this->new = $unserialized['new'] ?? '';
}
/**
* Stringify.
*
* @return string
*
* @since 1.0.0
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* Generate message array.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function toArray() : array
{
return [
'type' => self::TYPE,
'time' => $this->delay,
'uri' => $this->uri,
'new' => $this->new
];
}
}

132
Model/Message/Reload.php Normal file
View File

@ -0,0 +1,132 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Model\Message
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Model\Message;
use phpOMS\Contract\ArrayableInterface;
/**
* Reload class.
*
* @package phpOMS\Model\Message
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Reload implements \Serializable, ArrayableInterface, \JsonSerializable
{
/**
* Message type.
*
* @var string
* @since 1.0.0
*/
public const TYPE = 'reload';
/**
* Delay in ms.
*
* @var int
* @since 1.0.0
*/
private $delay = 0;
/**
* Constructor.
*
* @param int $delay Delay in ms
*
* @since 1.0.0
*/
public function __construct(int $delay = 0)
{
$this->delay = $delay;
}
/**
* Set delay.
*
* @param int $delay Delay in ms
*
* @return void
*
* @since 1.0.0
*/
public function setDelay(int $delay) : void
{
$this->delay = $delay;
}
/**
* Render message.
*
* @return string
*
* @since 1.0.0
*/
public function serialize() : string
{
return $this->__toString();
}
/**
* {@inheritdoc}
*/
public function unserialize($raw)
{
$unserialized = \json_decode($raw, true);
$this->delay = $unserialized['time'] ?? 0;
}
/**
* Stringify.
*
* @return string
*
* @since 1.0.0
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* Generate message array.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function toArray() : array
{
return [
'type' => self::TYPE,
'time' => $this->delay
];
}
/**
* Generate message json.
*
* @return array<string, mixed>
*
* @since 1.0.0
*/
public function jsonSerialize()
{
return $this->toArray();
}
}

147
Views/PaginationView.php Normal file
View File

@ -0,0 +1,147 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Views
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\Views;
use phpOMS\Views\View;
/**
* Pagination view.
*
* @package phpOMS\Views
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class PaginationView extends View
{
/**
* Maximum amount of pages.
*
* @var int
* @since 1.0.0
*/
protected $maxPages = 7;
/**
* Current page id.
*
* @var int
* @since 1.0.0
*/
protected $page = 50;
/**
* How many pages exists?
*
* @var int
* @since 1.0.0
*/
protected $pages = 100;
/**
* How many results exists?
*
* @var int
* @since 1.0.0
*/
protected $results = 0;
/**
* @return int
*
* @since 1.0.0
*/
public function getMaxPages() : int
{
return $this->maxPages;
}
/**
* @param int $maxPages
*
* @return void
*
* @since 1.0.0
*/
public function setMaxPages(int $maxPages)
{
$this->maxPages = $maxPages;
}
/**
* @return int
*
* @since 1.0.0
*/
public function getPages() : int
{
return $this->pages;
}
/**
* @param int $pages
*
* @return void
*
* @since 1.0.0
*/
public function setPages(int $pages)
{
$this->pages = $pages;
}
/**
* @return int
*
* @since 1.0.0
*/
public function getPage() : int
{
return $this->page;
}
/**
* @param int $page
*
* @return void
*
* @since 1.0.0
*/
public function setPage(int $page = 1)
{
$this->page = $page;
}
/**
* @return int
*
* @since 1.0.0
*/
public function getResults() : int
{
return $this->results;
}
/**
* @param int $results
*
* @return void
*
* @since 1.0.0
*/
public function setResults(int $results = 0)
{
$this->results = $results;
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\phpOMS\Model\Message;
use phpOMS\Model\Message\DomAction;
class DomActionTest extends \PHPUnit\Framework\TestCase
{
public function testEnums()
{
self::assertEquals(9, count(DomAction::getConstants()));
self::assertEquals(DomAction::getConstants(), array_unique(DomAction::getConstants()));
self::assertEquals(0, DomAction::CREATE_BEFORE);
self::assertEquals(1, DomAction::CREATE_AFTER);
self::assertEquals(2, DomAction::DELETE);
self::assertEquals(3, DomAction::REPLACE);
self::assertEquals(4, DomAction::MODIFY);
self::assertEquals(5, DomAction::SHOW);
self::assertEquals(6, DomAction::HIDE);
self::assertEquals(7, DomAction::ACTIVATE);
self::assertEquals(8, DomAction::DEACTIVATE);
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\phpOMS\Model\Message;
use phpOMS\Model\Message\Dom;
use phpOMS\Model\Message\DomAction;
class DomTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes()
{
$obj = new Dom();
self::assertInstanceOf('\phpOMS\Model\Message\Dom', $obj);
/* Testing members */
self::assertObjectHasAttribute('delay', $obj);
self::assertObjectHasAttribute('content', $obj);
self::assertObjectHasAttribute('selector', $obj);
self::assertObjectHasAttribute('action', $obj);
}
public function testDefault()
{
$obj = new Dom();
/* Testing default values */
self::assertEquals(0, $obj->toArray()['time']);
self::assertEquals('', $obj->toArray()['selector']);
self::assertEquals('', $obj->toArray()['content']);
self::assertEquals(DomAction::MODIFY, $obj->toArray()['action']);
}
public function testSetGet()
{
$obj = new Dom();
$obj->setDelay(3);
$obj->setAction(DomAction::SHOW);
$obj->setContent('msg');
$obj->setSelector('#sel');
self::assertEquals([
'type' => 'dom',
'time' => 3,
'selector' => '#sel',
'action' => DomAction::SHOW,
'content' => 'msg',
], $obj->toArray());
self::assertEquals(\json_encode([
'type' => 'dom',
'time' => 3,
'selector' => '#sel',
'action' => DomAction::SHOW,
'content' => 'msg',
]), $obj->serialize());
self::assertEquals([
'type' => 'dom',
'time' => 3,
'selector' => '#sel',
'action' => DomAction::SHOW,
'content' => 'msg',
], $obj->jsonSerialize());
$obj2 = new Dom();
$obj2->unserialize($obj->serialize());
self::assertEquals($obj, $obj2);
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\phpOMS\Model\Message;
use phpOMS\Model\Message\FormValidation;
class FormValidationTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes()
{
$obj = new FormValidation([]);
self::assertInstanceOf('\phpOMS\Model\Message\FormValidation', $obj);
/* Testing members */
self::assertObjectHasAttribute('validation', $obj);
}
public function testDefault()
{
$obj = new FormValidation([]);
/* Testing default values */
self::assertEmpty($obj->toArray()['validation']);
}
public function testSetGet()
{
$arr = ['a' => true, 'b' => false];
$obj = new FormValidation($arr);
self::assertEquals(['type' => 'validation', 'validation' => $arr], $obj->toArray());
self::assertEquals(\json_encode(['type' => 'validation', 'validation' => $arr]), $obj->serialize());
self::assertEquals(['type' => 'validation', 'validation' => $arr], $obj->jsonSerialize());
$obj2 = new FormValidation();
$obj2->unserialize($obj->serialize());
self::assertEquals($obj, $obj2);
}
}

View File

@ -0,0 +1,87 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\phpOMS\Model\Message;
use phpOMS\Model\Message\Notify;
use phpOMS\Model\Message\NotifyType;
class NotifyTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes()
{
$obj = new Notify();
self::assertInstanceOf('\phpOMS\Model\Message\Notify', $obj);
/* Testing members */
self::assertObjectHasAttribute('delay', $obj);
self::assertObjectHasAttribute('title', $obj);
self::assertObjectHasAttribute('stay', $obj);
self::assertObjectHasAttribute('message', $obj);
self::assertObjectHasAttribute('level', $obj);
}
public function testDefault()
{
$obj = new Notify();
/* Testing default values */
self::assertEquals(0, $obj->toArray()['time']);
self::assertEquals('', $obj->toArray()['title']);
self::assertEquals('', $obj->toArray()['msg']);
self::assertEquals(0, $obj->toArray()['stay']);
self::assertEquals(NotifyType::INFO, $obj->toArray()['level']);
}
public function testSetGet()
{
$obj = new Notify('message', NotifyType::WARNING);
$obj->setDelay(3);
$obj->setStay(5);
$obj->setLevel(NotifyType::ERROR);
$obj->setMessage('msg');
$obj->setTitle('title');
self::assertEquals([
'type' => 'notify',
'time' => 3,
'stay' => 5,
'msg' => 'msg',
'title' => 'title',
'level' => NotifyType::ERROR
], $obj->toArray());
self::assertEquals(\json_encode([
'type' => 'notify',
'time' => 3,
'stay' => 5,
'msg' => 'msg',
'title' => 'title',
'level' => NotifyType::ERROR
]), $obj->serialize());
self::assertEquals([
'type' => 'notify',
'time' => 3,
'stay' => 5,
'msg' => 'msg',
'title' => 'title',
'level' => NotifyType::ERROR
], $obj->jsonSerialize());
$obj2 = new Notify();
$obj2->unserialize($obj->serialize());
self::assertEquals($obj, $obj2);
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\phpOMS\Model\Message;
use phpOMS\Model\Message\NotifyType;
class NotifyTypeTest extends \PHPUnit\Framework\TestCase
{
public function testEnums()
{
self::assertEquals(5, count(NotifyType::getConstants()));
self::assertEquals(NotifyType::getConstants(), array_unique(NotifyType::getConstants()));
self::assertEquals(0, NotifyType::BINARY);
self::assertEquals(1, NotifyType::INFO);
self::assertEquals(2, NotifyType::WARNING);
self::assertEquals(3, NotifyType::ERROR);
self::assertEquals(4, NotifyType::FATAL);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\phpOMS\Model\Message;
use phpOMS\Model\Message\Redirect;
class RedirectTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes()
{
$obj = new Redirect('');
self::assertInstanceOf('\phpOMS\Model\Message\Redirect', $obj);
/* Testing members */
self::assertObjectHasAttribute('uri', $obj);
self::assertObjectHasAttribute('delay', $obj);
self::assertObjectHasAttribute('new', $obj);
}
public function testDefault()
{
$obj = new Redirect('');
/* Testing default values */
self::assertEmpty($obj->toArray()['uri']);
self::assertEquals(0, $obj->toArray()['time']);
self::assertEquals(false, $obj->toArray()['new']);
}
public function testSetGet()
{
$obj = new Redirect('url', true);
self::assertEquals(['type' => 'redirect', 'time' => 0, 'uri' => 'url', 'new' => true], $obj->toArray());
self::assertEquals(\json_encode(['type' => 'redirect', 'time' => 0, 'uri' => 'url', 'new' => true]), $obj->serialize());
self::assertEquals(['type' => 'redirect', 'time' => 0, 'uri' => 'url', 'new' => true], $obj->jsonSerialize());
$obj->setDelay(6);
$obj->setUri('test');
self::assertEquals(['type' => 'redirect', 'time' => 6, 'uri' => 'test', 'new' => true], $obj->toArray());
$obj2 = new Redirect();
$obj2->unserialize($obj->serialize());
self::assertEquals($obj, $obj2);
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\phpOMS\Model\Message;
use phpOMS\Model\Message\Reload;
class ReloadTest extends \PHPUnit\Framework\TestCase
{
public function testAttributes()
{
$obj = new Reload();
self::assertInstanceOf('\phpOMS\Model\Message\Reload', $obj);
/* Testing members */
self::assertObjectHasAttribute('delay', $obj);
}
public function testDefault()
{
$obj = new Reload();
/* Testing default values */
self::assertEquals(0, $obj->toArray()['time']);
}
public function testSetGet()
{
$obj = new Reload(5);
self::assertEquals(['type' => 'reload', 'time' => 5], $obj->toArray());
self::assertEquals(\json_encode(['type' => 'reload', 'time' => 5]), $obj->serialize());
self::assertEquals(['type' => 'reload', 'time' => 5], $obj->jsonSerialize());
$obj->setDelay(6);
self::assertEquals(['type' => 'reload', 'time' => 6], $obj->toArray());
$obj2 = new Reload();
$obj2->unserialize($obj->serialize());
self::assertEquals($obj, $obj2);
}
}