tests wip
CI / testsuite (mysql, 8.1, ) (push) Failing after 4s Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 4s Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 4s Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 4s Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s Details
CI / Coding Standard & Static Analysis (push) Failing after 0s Details

This commit is contained in:
Brandon Shipley 2025-03-30 23:51:28 -07:00
parent 1ebebede87
commit ce74025f6c
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
2 changed files with 215 additions and 0 deletions

View File

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Controller;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
use Cake\Log\Log;
use CakeProducts\Controller\AppController;
/**
* ExternalProductCatalogsProductCatalogs Controller
*
*/
class ExternalProductCatalogsProductCatalogsController extends AppController
{
/**
* Add method
*
* @return Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
Log::debug('inside external product catalogs product catalogs controller add');
$productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray();
$this->set(compact( 'productCatalogs'));
}
/**
* Delete method
*
* @param string|null $id Customers Contact id.
* @return Response|null Redirects to index.
* @throws RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id);
if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) {
$this->Flash->success(__('The customers contact has been deleted.'));
} else {
$this->Flash->error(__('The customers contact could not be deleted. Please, try again.'));
}
return $this->redirect($this->referer([
'controller' => 'ExternalProductCatalogs',
'action' => 'view',
$externalProductCatalogProductCatalog->external_product_catalog_id,
]));
}
}

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);
}
}