Add more unit tests

This commit is contained in:
Dennis Eichhorn 2018-10-02 22:11:31 +02:00
parent 847c8d2a42
commit a8f7b0c375
5 changed files with 83 additions and 15 deletions

View File

@ -62,7 +62,7 @@ class PermissionAbstract implements \JsonSerializable
/**
* Providing module id.
*
* @var int|null
* @var int
* @since 1.0.0
*/
protected $from = 0;
@ -192,11 +192,11 @@ class PermissionAbstract implements \JsonSerializable
/**
* Get providing module id.
*
* @return int|null
* @return int
*
* @since 1.0.0
*/
public function getFrom() : ?int
public function getFrom() : int
{
return $this->from;
}
@ -210,7 +210,7 @@ class PermissionAbstract implements \JsonSerializable
*
* @since 1.0.0
*/
public function setFrom(int $from = null) : void
public function setFrom(int $from = 0) : void
{
$this->from = $from;
}
@ -353,14 +353,14 @@ class PermissionAbstract implements \JsonSerializable
public function jsonSerialize()
{
return [
'id' => $this->id,
'unit' => $this->unit,
'app' => $this->app,
'module' => $this->module,
'from' => $this->from,
'type' => $this->type,
'element' => $this->element,
'component' => $this->component,
'id' => $this->id,
'unit' => $this->unit,
'app' => $this->app,
'module' => $this->module,
'from' => $this->from,
'type' => $this->type,
'element' => $this->element,
'component' => $this->component,
'permission' => $this->permission,
];
}

View File

@ -39,7 +39,7 @@ class PaginationView extends View
* @var int
* @since 1.0.0
*/
protected $page = 50;
protected $page = 1;
/**
* How many pages exists?
@ -47,7 +47,7 @@ class PaginationView extends View
* @var int
* @since 1.0.0
*/
protected $pages = 100;
protected $pages = 1;
/**
* How many results exists?

View File

@ -151,6 +151,12 @@ class AccountTest extends \PHPUnit\Framework\TestCase
]);
self::assertEquals(4, \count($account->getPermissions()));
$account->addPermissions([[
new class extends PermissionAbstract {},
new class extends PermissionAbstract {},
]]);
self::assertEquals(6, \count($account->getPermissions()));
self::assertFalse($account->hasPermission(PermissionType::READ, 1, 'a', 'a', 1, 1, 1));
self::assertTrue($account->hasPermission(PermissionType::NONE));

View File

@ -28,11 +28,26 @@ class PermissionAbstractTest extends \PHPUnit\Framework\TestCase
self::assertEquals(null, $perm->getUnit());
self::assertEquals(null, $perm->getApp());
self::assertEquals(null, $perm->getModule());
self::assertEquals(null, $perm->getFrom());
self::assertEquals(0, $perm->getFrom());
self::assertEquals(null, $perm->getType());
self::assertEquals(null, $perm->getElement());
self::assertEquals(null, $perm->getComponent());
self::assertEquals(PermissionType::NONE, $perm->getPermission());
self::assertEquals(
[
'id' => 0,
'unit' => null,
'app' => null,
'module' => null,
'from' => 0,
'type' => null,
'element' => null,
'component' => null,
'permission' => PermissionType::NONE,
],
$perm->jsonSerialize()
);
}
public function testAbstractGetSet()

View File

@ -0,0 +1,47 @@
<?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\Views;
require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Views\PaginationView;
class PaginationViewTest extends \PHPUnit\Framework\TestCase
{
public function testDefault()
{
$view = new PaginationView();
self::assertEquals(7, $view->getMaxPages());
self::assertEquals(1, $view->getPages());
self::assertEquals(1, $view->getPage());
self::assertEquals(0, $view->getResults());
}
public function testGetSet()
{
$view = new PaginationView();
$view->setMaxPages(9);
self::assertEquals(9, $view->getMaxPages());
$view->setPages(2);
self::assertEquals(2, $view->getPages());
$view->setPage(3);
self::assertEquals(3, $view->getPage());
$view->setResults(12);
self::assertEquals(12, $view->getResults());
}
}