tests wip

This commit is contained in:
2025-03-30 23:51:28 -07:00
parent 1ebebede87
commit ce74025f6c
2 changed files with 215 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Controller;
use App\Controller\ExternalProductCatalogsProductCatalogsController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use PHPUnit\Exception;
/**
* App\Controller\ExternalProductCatalogsProductCatalogsController Test Case
*
* @uses \App\Controller\ExternalProductCatalogsProductCatalogsController
*/
class ExternalProductCatalogsProductCatalogsControllerTest extends BaseControllerTest
{
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'CakeProducts.ExternalProductCatalogsProductCatalogs',
'CakeProducts.ExternalProductCatalogs',
'CakeProducts.ExternalProductCatalogs',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
// $this->enableCsrfToken();
// $this->enableSecurityToken();
$this->disableErrorHandlerMiddleware();
$this->ExternalProductCatalogsProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogsProductCatalogs');
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ExternalProductCatalogsProductCatalogs);
parent::tearDown();
}
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \App\Controller\ExternalProductCatalogsProductCatalogsController::add()
* @throws Exception
*
* @return void
*/
public function testAddGet(): void
{
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
// $this->loginUserByRole('admin');
$url = [
'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \App\Controller\ExternalProductCatalogsProductCatalogsController::add()
* @throws Exception
*
* @return void
*/
public function testAddPostSuccess(): void
{
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
// $this->loginUserByRole('admin');
$url = [
'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'add',
];
$data = [];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('externalproductcatalogsproductcatalogs/view');
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
}
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \App\Controller\ExternalProductCatalogsProductCatalogsController::add()
* @throws Exception
*
* @return void
*/
public function testAddPostFailure(): void
{
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
// $this->loginUserByRole('admin');
$url = [
'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'add',
];
$data = [];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @uses \App\Controller\ExternalProductCatalogsProductCatalogsController::delete()
* @throws Exception
*
* @return void
*/
public function testDelete(): void
{
$cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count();
// $this->loginUserByRole('admin');
$url = [
'controller' => 'ExternalProductCatalogsProductCatalogs',
'action' => 'delete',
1,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('externalproductcatalogsproductcatalogs');
$cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
}