*/ protected array $fixtures = [ 'plugin.CakeAccounting.DeJournals', 'plugin.CakeAccounting.DeJournalEntries', 'plugin.CakeAccounting.DeJournalItems', 'plugin.CakeAccounting.DeJournalTypes', ]; /** * setUp method * * @return void */ protected function setUp(): void { parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); $this->disableErrorHandlerMiddleware(); $config = $this->getTableLocator()->exists('DeJournals') ? [] : ['className' => DeJournalsTable::class]; $this->DeJournals = $this->getTableLocator()->get('DeJournals', $config); } /** * tearDown method * * @return void */ protected function tearDown(): void { unset($this->DeJournals); parent::tearDown(); } /** * Test index method * * Tests the index action with a logged in user * * @return void * @throws Exception * * @uses DeJournalsController::index */ public function testIndexGetLoggedIn(): void { //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'index', ]; $this->get($url); $this->assertResponseCode(200); } /** * Test view method * * Tests the view action with a logged in user * * @return void * @throws Exception * * @uses DeJournalsController::view */ public function testViewGetLoggedIn(): void { $id = 1; //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'view', $id, ]; $this->get($url); $this->assertResponseCode(200); } /** * Test add method * * Tests the add action with a logged in user * * @return void * @throws Exception * * @uses DeJournalsController::add */ public function testAddGetLoggedIn(): void { $cntBefore = $this->DeJournals->find()->count(); //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'add', ]; $this->get($url); $this->assertResponseCode(200); $cntAfter = $this->DeJournals->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 DeJournalsController::add */ public function testAddPostLoggedInSuccess(): void { $cntBefore = $this->DeJournals->find()->count(); //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'add', ]; $data = [ 'name' => 'new journal', 'short_code' => 'NEW', 'default_account_number_credit' => '', 'default_account_number_debit' => '', 'de_journal_type_code' => DE_JOURNAL_TYPE_MISC, ]; $this->post($url, $data); $this->assertResponseCode(302); $this->assertRedirectContains('de-journals'); $cntAfter = $this->DeJournals->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 DeJournalsController::add */ public function testAddPostLoggedInFailure(): void { $cntBefore = $this->DeJournals->find()->count(); //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'add', ]; $data = [ 'name' => 'new journal', 'short_code' => '', 'default_account_number_credit' => '9999999999', 'default_account_number_debit' => '999999999999', 'de_journal_type_code' => 'not real code', ]; $this->post($url, $data); $this->assertResponseCode(200); $cntAfter = $this->DeJournals->find()->count(); $this->assertEquals($cntBefore, $cntAfter); } /** * Test edit method * * Tests the edit action with a logged in user * * @return void * @throws Exception * * @uses DeJournalsController::edit */ public function testEditGetLoggedIn(): void { //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'edit', 1, ]; $this->get($url); $this->assertResponseCode(200); } /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @return void * @throws Exception * * @uses DeJournalsController::edit */ public function testEditPutLoggedInSuccess(): void { //$this->loginUserByRole('admin'); $id = 1; $before = $this->DeJournals->get($id); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'edit', $id, ]; $data = [ // test new data here ]; $this->put($url, $data); $this->assertResponseCode(302); $this->assertRedirectContains('de-journals'); $after = $this->DeJournals->get($id); // assert saved properly below } /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @return void * @throws Exception * * @uses DeJournalsController::edit */ public function testEditPutLoggedInFailure(): void { //$this->loginUserByRole('admin'); $id = 1; $before = $this->DeJournals->get($id); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'edit', $id, ]; $data = [ 'name' => 'new journal', 'short_code' => '', 'default_account_number_credit' => '9999999999', 'default_account_number_debit' => '999999999999', 'de_journal_type_code' => 'not real code', ]; $this->put($url, $data); $this->assertResponseCode(200); $after = $this->DeJournals->get($id); // assert save failed below $this->assertEquals($before->name, $after->name); $this->assertEquals($before->short_code, $after->short_code); $this->assertEquals($before->name, $after->name); $this->assertEquals($before->default_account_number_credit, $after->default_account_number_credit); $this->assertEquals($before->default_account_number_debit, $after->default_account_number_debit); $this->assertEquals($before->de_journal_type_code, $after->de_journal_type_code); } /** * Test delete method * * Tests the delete action with a logged in user * * @return void *@throws Exception * * @uses DeJournalsController::delete */ public function testDeleteLoggedIn(): void { $cntBefore = $this->DeJournals->find()->count(); //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeAccounting', 'controller' => 'DeJournals', 'action' => 'delete', 1, ]; $this->delete($url); $this->assertResponseCode(302); $this->assertRedirectContains('de-journals'); $cntAfter = $this->DeJournals->find()->count(); $this->assertEquals($cntBefore - 1, $cntAfter); } }