274 lines
6.8 KiB
PHP
274 lines
6.8 KiB
PHP
|
<?php
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace CakeAccounting\Test\TestCase\Controller;
|
||
|
|
||
|
use Cake\ORM\Table;
|
||
|
use CakeAccounting\Controller\DeJournalEntriesController;
|
||
|
use CakeAccounting\Model\Table\DeJournalEntriesTable;
|
||
|
use PHPUnit\Exception;
|
||
|
|
||
|
/**
|
||
|
* CakeAccounting\Controller\DeJournalEntriesController Test Case
|
||
|
*
|
||
|
* @uses DeJournalEntriesController
|
||
|
*/
|
||
|
class DeJournalEntriesControllerTest extends BaseControllerTest
|
||
|
{
|
||
|
/**
|
||
|
* @var DeJournalEntriesTable|Table
|
||
|
*/
|
||
|
protected DeJournalEntriesTable|Table $DeJournalEntries;
|
||
|
|
||
|
/**
|
||
|
* Fixtures
|
||
|
*
|
||
|
* @var array<string>
|
||
|
*/
|
||
|
protected array $fixtures = [
|
||
|
'plugin.CakeAccounting.DeAccounts',
|
||
|
'plugin.CakeAccounting.DeJournalEntries',
|
||
|
'plugin.CakeAccounting.DeJournals',
|
||
|
'plugin.CakeAccounting.DeJournalItems',
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* setUp method
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
protected function setUp(): void
|
||
|
{
|
||
|
parent::setUp();
|
||
|
$this->DeJournalEntries = $this->getTableLocator()->get('DeJournalEntries');
|
||
|
$this->enableCsrfToken();
|
||
|
$this->enableSecurityToken();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* tearDown method
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
protected function tearDown(): void
|
||
|
{
|
||
|
unset($this->DeJournalEntries);
|
||
|
|
||
|
parent::tearDown();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test index method
|
||
|
*
|
||
|
* Tests the index action with an unauthenticated user (not logged in)
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeJournalEntriesController::index
|
||
|
*/
|
||
|
public function testIndexGetUnauthenticated(): void
|
||
|
{
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeJournalEntries',
|
||
|
'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 DeJournalEntriesController::index
|
||
|
*/
|
||
|
public function testIndexGetLoggedIn(): void
|
||
|
{
|
||
|
$this->loginUserByRole('admin');
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeJournalEntries',
|
||
|
'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 DeJournalEntriesController::view
|
||
|
*/
|
||
|
public function testViewGetUnauthenticated(): void
|
||
|
{
|
||
|
$id = 1;
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeJournalEntries',
|
||
|
'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 DeJournalEntriesController::view
|
||
|
*/
|
||
|
public function testViewGetLoggedIn(): void
|
||
|
{
|
||
|
$id = 1;
|
||
|
$this->loginUserByRole('admin');
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeJournalEntries',
|
||
|
'action' => 'view',
|
||
|
$id,
|
||
|
];
|
||
|
$this->get($url);
|
||
|
$this->assertResponseCode(200);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test add method
|
||
|
*
|
||
|
* Tests the add action with an unauthenticated user (not logged in)
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeJournalEntriesController::add
|
||
|
*/
|
||
|
public function testAddGetUnauthenticated(): void
|
||
|
{
|
||
|
$cntBefore = $this->DeJournalEntries->find()->count();
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeJournalEntries',
|
||
|
'action' => 'add',
|
||
|
];
|
||
|
$this->get($url);
|
||
|
$this->assertResponseCode(302);
|
||
|
$this->assertRedirectContains('login');
|
||
|
|
||
|
$cntAfter = $this->DeJournalEntries->find()->count();
|
||
|
$this->assertEquals($cntBefore, $cntAfter);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test add method
|
||
|
*
|
||
|
* Tests the add action with a logged in user
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeJournalEntriesController::add
|
||
|
*/
|
||
|
public function testAddGetLoggedIn(): void
|
||
|
{
|
||
|
$cntBefore = $this->DeJournalEntries->find()->count();
|
||
|
|
||
|
$this->loginUserByRole('admin');
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeJournalEntries',
|
||
|
'action' => 'add',
|
||
|
];
|
||
|
$this->get($url);
|
||
|
$this->assertResponseCode(200);
|
||
|
|
||
|
$cntAfter = $this->DeJournalEntries->find()->count();
|
||
|
$this->assertEquals($cntBefore, $cntAfter);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test add method
|
||
|
*
|
||
|
* Tests a POST request to the add action with a logged in user
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeJournalEntriesController::add
|
||
|
*/
|
||
|
public function testAddPostLoggedInSuccess(): void
|
||
|
{
|
||
|
$cntBefore = $this->DeJournalEntries->find()->count();
|
||
|
|
||
|
$this->loginUserByRole('admin');
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeJournalEntries',
|
||
|
'action' => 'add',
|
||
|
];
|
||
|
$data = [
|
||
|
'de_journal_id' => 1,
|
||
|
'notes' => 'test notes',
|
||
|
'de_journal_items' => [
|
||
|
[
|
||
|
'account_number_credit' => 31000,
|
||
|
'account_number_debit' => 11000,
|
||
|
'external_account_number_credit' => '',
|
||
|
'external_account_number_debit' => '',
|
||
|
'amount' => 500,
|
||
|
],
|
||
|
],
|
||
|
];
|
||
|
$this->post($url, $data);
|
||
|
$this->assertResponseCode(302);
|
||
|
$this->assertRedirectContains('de-journal-entries');
|
||
|
|
||
|
$cntAfter = $this->DeJournalEntries->find()->count();
|
||
|
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test add method
|
||
|
*
|
||
|
* Tests a POST request to the add action with a logged in user
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws Exception
|
||
|
*
|
||
|
* @uses DeJournalEntriesController::add
|
||
|
*/
|
||
|
public function testAddPostLoggedInFailure(): void
|
||
|
{
|
||
|
$cntBefore = $this->DeJournalEntries->find()->count();
|
||
|
|
||
|
$this->loginUserByRole('admin');
|
||
|
$url = [
|
||
|
'plugin' => 'CakeAccounting',
|
||
|
'controller' => 'DeJournalEntries',
|
||
|
'action' => 'add',
|
||
|
];
|
||
|
$data = [];
|
||
|
$this->post($url, $data);
|
||
|
$this->assertResponseCode(200);
|
||
|
|
||
|
$cntAfter = $this->DeJournalEntries->find()->count();
|
||
|
$this->assertEquals($cntBefore, $cntAfter);
|
||
|
}
|
||
|
}
|