1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/tests/Unit/CompareCollectionTest.php
David Bomba 43e57d0117
Fixes for self-update (#3514)
* minor fix for payment notifications

* styleci

* Limit Self updating to self hosters only
:

* Fixes for designs

* Minor fixes for self-update
2020-03-21 16:37:30 +11:00

123 lines
3.7 KiB
PHP

<?php
namespace Tests\Unit;
use Tests\TestCase;
/**
* @test
* @covers App\Utils\Number
*/
class CompareCollectionTest extends TestCase
{
public function setUp() :void
{
parent::setUp();
$this->map = collect([
['action' => 'view_client_client_id', 'permission' => 'view_client', 'route' => 'clients.show', 'key' => 'client_id', 'name' => trans('texts.view')],
['action' => 'edit_client_client_id', 'permission' => 'edit_client', 'route' => 'clients.edit', 'key' => 'client_id', 'name' => trans('texts.edit')],
['action' => 'create_task_client_id', 'permission' => 'create_task', 'route' => 'task.create', 'key' => 'client_id', 'name' => trans('texts.new_task')],
['action' => 'create_invoice_client_id', 'permission' => 'create_invoice', 'route' => 'invoice.create', 'key' => 'client_id', 'name' => trans('texts.new_invoice')],
['action' => 'enter_payment_client_id', 'permission' => 'create_payment', 'route' => 'payment.create', 'key' => 'client_id', 'name' => trans('texts.enter_payment')],
['action' => 'enter_credit_client_id', 'permission' => 'create_credit', 'route' => 'credit.create', 'key' => 'client_id', 'name' => trans('texts.enter_credit')],
['action' => 'enter_expense_client_id', 'permission' => 'create_expense', 'route' => 'expense.create', 'key' => 'client_id', 'name' => trans('texts.enter_expense')]
]);
$this->view_permission = ['view_client'];
$this->edit_permission = ['view_client', 'edit_client'];
$this->is_admin = true;
$this->is_not_admin = false;
}
public function testCompareResultOfComparison()
{
$this->assertEquals(7, $this->map->count());
}
public function testViewPermission()
{
$this->assertEquals(1, $this->checkPermissions($this->view_permission, $this->is_not_admin)->count());
}
public function testViewAndEditPermission()
{
$this->assertEquals(2, $this->checkPermissions($this->edit_permission, $this->is_not_admin)->count());
}
public function testAdminPermissions()
{
$this->assertEquals(7, $this->checkPermissions($this->view_permission, $this->is_admin)->count());
}
public function testActionViewClientFilter()
{
$actions = [
'view_client_client_id'
];
$this->assertEquals(1, $this->map->whereIn('action', $actions)->count());
}
public function testNoActionClientFilter()
{
$actions = [
''
];
$this->assertEquals(0, $this->map->whereIn('action', $actions)->count());
}
public function testActionsAndPermissionsFilter()
{
$actions = [
'view_client_client_id'
];
$this->filterActions($actions);
$this->assertEquals(1, $this->checkPermissions($this->view_permission, $this->is_not_admin)->count());
}
public function testActionAndPermissionsFilterFailure()
{
$actions = [
'edit_client_client_id'
];
$data = $this->filterActions($actions);
$this->assertEquals(0, $data->whereIn('permission', $this->view_permission)->count());
}
public function testEditActionAndPermissionsFilter()
{
$actions = [
'edit_client_client_id'
];
$data = $this->filterActions($actions);
$this->assertEquals(1, $data->whereIn('permission', $this->edit_permission)->count());
}
public function checkPermissions($permission, $is_admin)
{
if ($is_admin === true) {
return $this->map;
}
return $this->map->whereIn('permission', $permission);
}
public function filterActions($actions)
{
return $this->map->whereIn('action', $actions);
}
}