147 lines
3.4 KiB
PHP
147 lines
3.4 KiB
PHP
|
<?php
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace CakeAccounting\Test\TestCase\Controller;
|
||
|
|
||
|
use Cake\ORM\Table;
|
||
|
use CakeAccounting\Controller\DeAccountStatementsController;
|
||
|
use CakeAccounting\Model\Table\DeAccountStatementsTable;
|
||
|
use PHPUnit\Exception;
|
||
|
|
||
|
/**
|
||
|
* CakeAccounting\Controller\DeAccountStatementsController Test Case
|
||
|
*
|
||
|
* @uses DeAccountStatementsController
|
||
|
*/
|
||
|
class DeAccountStatementsControllerTest extends BaseControllerTest
|
||
|
{
|
||
|
/**
|
||
|
* @var $DeAccountStatementsTable|Table
|
||
|
*/
|
||
|
protected DeAccountStatementsTable|Table $DeAccountStatements;
|
||
|
|
||
|
/**
|
||
|
* Fixtures
|
||
|
*
|
||
|
* @var array<string>
|
||
|
*/
|
||
|
protected array $fixtures = [
|
||
|
'plugin.CakeAccounting.DeAccountStatements',
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* setUp method
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
protected function setUp(): void
|
||
|
{
|
||
|
parent::setUp();
|
||
|
$this->DeAccountStatements = $this->getTableLocator()->get('DeAccountStatements');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* tearDown method
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
protected function tearDown(): void
|
||
|
{
|
||
|
unset($this->DeAccountStatements);
|
||
|
|
||
|
parent::tearDown();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test index method
|
||
|
*
|
||
|
* Tests the index action with an unauthenticated user (not logged in)
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeAccountStatementsController::index
|
||
|
*/
|
||
|
public function testIndexGetUnauthenticated(): void
|
||
|
{
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeAccountStatements',
|
||
|
'action' => 'index',
|
||
|
];
|
||
|
$this->get($url);
|
||
|
$this->assertResponseCode(302);
|
||
|
$this->assertRedirectContains('login');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test index method
|
||
|
*
|
||
|
* Tests the index action with a logged in user
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeAccountStatementsController::index
|
||
|
*/
|
||
|
public function testIndexGetLoggedIn(): void
|
||
|
{
|
||
|
$this->loginUserByRole('admin');
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeAccountStatements',
|
||
|
'action' => 'index',
|
||
|
];
|
||
|
$this->get($url);
|
||
|
$this->assertResponseCode(200);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test view method
|
||
|
*
|
||
|
* Tests the view action with an unauthenticated user (not logged in)
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeAccountStatementsController::view
|
||
|
*/
|
||
|
public function testViewGetUnauthenticated(): void
|
||
|
{
|
||
|
$id = '4614401e-fe0c-45cf-9f17-c45c7848960e';
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeAccountStatements',
|
||
|
'action' => 'view',
|
||
|
$id,
|
||
|
];
|
||
|
$this->get($url);
|
||
|
$this->assertResponseCode(302);
|
||
|
$this->assertRedirectContains('login');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test view method
|
||
|
*
|
||
|
* Tests the view action with a logged in user
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeAccountStatementsController::view
|
||
|
*/
|
||
|
public function testViewGetLoggedIn(): void
|
||
|
{
|
||
|
$id = '4614401e-fe0c-45cf-9f17-c45c7848960e';
|
||
|
$this->loginUserByRole('admin');
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeAccountStatements',
|
||
|
'action' => 'view',
|
||
|
$id,
|
||
|
];
|
||
|
$this->get($url);
|
||
|
$this->assertResponseCode(200);
|
||
|
}
|
||
|
}
|