bring into standalone plugin for distribution
This commit is contained in:
33
tests/Fixture/ExternalProductCatalogsFixture.php
Normal file
33
tests/Fixture/ExternalProductCatalogsFixture.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\Fixture;
|
||||
|
||||
use Cake\TestSuite\Fixture\TestFixture;
|
||||
|
||||
/**
|
||||
* ExternalProductCatalogsFixture
|
||||
*/
|
||||
class ExternalProductCatalogsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 1,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'base_url' => 'http://localhost:8766',
|
||||
'api_url' => 'http://localhost:8766/api',
|
||||
'created' => '2024-11-22 09:39:37',
|
||||
'deleted' => '2024-11-22 09:39:37',
|
||||
'enabled' => 1,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
36
tests/Fixture/ProductCatalogsFixture.php
Normal file
36
tests/Fixture/ProductCatalogsFixture.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\Fixture;
|
||||
|
||||
use Cake\TestSuite\Fixture\TestFixture;
|
||||
|
||||
/**
|
||||
* ProductCatalogsFixture
|
||||
*/
|
||||
class ProductCatalogsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'name' => 'Automotive',
|
||||
'catalog_description' => '',
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
|
||||
'name' => 'Software',
|
||||
'catalog_description' => '',
|
||||
'enabled' => true,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
101
tests/Fixture/ProductCategoriesFixture.php
Normal file
101
tests/Fixture/ProductCategoriesFixture.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\Fixture;
|
||||
|
||||
use Cake\TestSuite\Fixture\TestFixture;
|
||||
|
||||
/**
|
||||
* ProductCategoriesFixture
|
||||
*/
|
||||
class ProductCategoriesFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 1,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'name' => 'Engine',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 1,
|
||||
'rght' => 4,
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b',
|
||||
'name' => 'Engine Internals',
|
||||
'category_description' => '',
|
||||
'parent_id' => 1,
|
||||
'lft' => 2,
|
||||
'rght' => 3,
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83',
|
||||
'name' => 'Electrical',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 5,
|
||||
'rght' => 8,
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'name' => 'Wiring',
|
||||
'category_description' => '',
|
||||
'parent_id' => 3,
|
||||
'lft' => 6,
|
||||
'rght' => 7,
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a',
|
||||
'name' => 'Suspension',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 9,
|
||||
'rght' => 12,
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'id' => 6,
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e',
|
||||
'name' => 'Coilovers',
|
||||
'category_description' => '',
|
||||
'parent_id' => 5,
|
||||
'lft' => 10,
|
||||
'rght' => 11,
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'id' => 7,
|
||||
'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
|
||||
'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a',
|
||||
'name' => 'Support',
|
||||
'category_description' => '',
|
||||
'parent_id' => null,
|
||||
'lft' => 1,
|
||||
'rght' => 2,
|
||||
'enabled' => true,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
31
tests/Fixture/ProductCategoryAttributeOptionsFixture.php
Normal file
31
tests/Fixture/ProductCategoryAttributeOptionsFixture.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\Fixture;
|
||||
|
||||
use Cake\TestSuite\Fixture\TestFixture;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributeOptionsFixture
|
||||
*/
|
||||
class ProductCategoryAttributeOptionsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
|
||||
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'attribute_value' => 'Lorem ipsum dolor sit amet',
|
||||
'attribute_label' => 'Lorem ipsum dolor sit amet',
|
||||
'enabled' => 1,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
31
tests/Fixture/ProductCategoryAttributesFixture.php
Normal file
31
tests/Fixture/ProductCategoryAttributesFixture.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\Fixture;
|
||||
|
||||
use Cake\TestSuite\Fixture\TestFixture;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributesFixture
|
||||
*/
|
||||
class ProductCategoryAttributesFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
'name' => 'Color',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'attribute_type_id' => 1,
|
||||
'enabled' => 1,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
30
tests/Fixture/ProductsFixture.php
Normal file
30
tests/Fixture/ProductsFixture.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\Fixture;
|
||||
|
||||
use Cake\TestSuite\Fixture\TestFixture;
|
||||
|
||||
/**
|
||||
* ProductsFixture
|
||||
*/
|
||||
class ProductsFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'name' => '12AWG RED TXL Wire',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'product_type_id' => 1,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
||||
25
tests/TestCase/Controller/BaseControllerTest.php
Normal file
25
tests/TestCase/Controller/BaseControllerTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
class BaseControllerTest extends TestCase
|
||||
{
|
||||
use IntegrationTestTrait;
|
||||
|
||||
public function loginUserByRole(string $role = 'admin'): void
|
||||
{
|
||||
$this->session(['Auth.User.id' => 1]);
|
||||
$this->session(['Auth.id' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testTest()
|
||||
{
|
||||
$this->assertEquals(1, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,446 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Controller\ExternalProductCatalogsController;
|
||||
use CakeProducts\Model\Table\ExternalProductCatalogsTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeProducts\Controller\ExternalProductCatalogsController Test Case
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController
|
||||
*/
|
||||
class ExternalProductCatalogsControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
* Test subject table
|
||||
*
|
||||
* @var ExternalProductCatalogsTable|Table
|
||||
*/
|
||||
protected $ExternalProductCatalogs;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ExternalProductCatalogs',
|
||||
'plugin.CakeProducts.ProductCatalogs',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->enableCsrfToken();
|
||||
$this->enableSecurityToken();
|
||||
$this->ExternalProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogs');
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ExternalProductCatalogs);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* Tests the view action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGetUnauthenticated(): void
|
||||
{
|
||||
$id = 1;
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* Tests the view action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGetLoggedIn(): void
|
||||
{
|
||||
$id = 1;
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGetUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ExternalProductCatalogs->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ExternalProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGetLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ExternalProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ExternalProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostLoggedInSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->ExternalProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2',
|
||||
'base_url' => 'http://localhost:8766',
|
||||
'api_url' => 'http://localhost:8766/api/v1/',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('external-product-catalogs');
|
||||
|
||||
$cntAfter = $this->ExternalProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostLoggedInFailure(): void
|
||||
{
|
||||
$cntBefore = $this->ExternalProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'product_catalog_id' => 999999,
|
||||
'base_url' => '',
|
||||
'api_url' => 'http://localhost:8766/api/v1/',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ExternalProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'edit',
|
||||
1,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'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
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutLoggedInSuccess(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = 1;
|
||||
$before = $this->ExternalProductCatalogs->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'base_url' => 'http://localhost:8766',
|
||||
'api_url' => 'http://localhost:8766/api/v1/',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('external-product-catalogs');
|
||||
|
||||
$after = $this->ExternalProductCatalogs->get($id);
|
||||
// assert saved properly below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutLoggedInFailure(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = 1;
|
||||
$before = $this->ExternalProductCatalogs->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'product_catalog_id' => 9999999,
|
||||
'base_url' => '',
|
||||
'api_url' => 'http://localhost:8766/api/v1/',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->ExternalProductCatalogs->get($id);
|
||||
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::delete()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ExternalProductCatalogs->find()->count();
|
||||
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ExternalProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ExternalProductCatalogsController::delete()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ExternalProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ExternalProductCatalogs',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('external-product-catalogs');
|
||||
|
||||
$cntAfter = $this->ExternalProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
450
tests/TestCase/Controller/ProductCatalogsControllerTest.php
Normal file
450
tests/TestCase/Controller/ProductCatalogsControllerTest.php
Normal file
@@ -0,0 +1,450 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Controller\ProductCatalogsController;
|
||||
use CakeProducts\Model\Table\ProductCatalogsTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeProducts\Controller\ProductCatalogsController Test Case
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController
|
||||
*/
|
||||
class ProductCatalogsControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
* Test subject table
|
||||
*
|
||||
* @var ProductCatalogsTable|Table
|
||||
*/
|
||||
protected $ProductCatalogs;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCatalogs',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->enableCsrfToken();
|
||||
$this->enableSecurityToken();
|
||||
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
|
||||
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCatalogs);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses ProductCatalogsController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with a logged in user
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCatalogsController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* Tests the view action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses ProductCatalogsController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGetUnauthenticated(): void
|
||||
{
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* Tests the view action with a logged in user
|
||||
*
|
||||
* @uses ProductCatalogsController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGetLoggedIn(): void
|
||||
{
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses ProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGetUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @uses ProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGetLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses ProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostLoggedInSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => 'new catalog',
|
||||
'catalog_description' => 'description',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses ProductCatalogsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostLoggedInFailure(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'catalog_description' => '',
|
||||
'enabled' => '',
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses ProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGetUnauthenticated(): void
|
||||
{
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with a logged in user
|
||||
*
|
||||
* @uses ProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses ProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutLoggedInSuccess(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
// $before = $this->ProductCatalogs->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
'name' => 'edited name',
|
||||
'catalog_description' => 'new catalog description',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
|
||||
$after = $this->ProductCatalogs->get($id);
|
||||
$this->assertEquals($data['name'], $after->name);
|
||||
$this->assertEquals($data['catalog_description'], $after->catalog_description);
|
||||
// assert saved properly below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses ProductCatalogsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutLoggedInFailure(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$before = $this->ProductCatalogs->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'catalog_description' => 'edited description',
|
||||
'enabled' => '',
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->ProductCatalogs->get($id);
|
||||
$this->assertEquals($before->name, $after->name);
|
||||
$this->assertEquals($before->catalog_description, $after->catalog_description);
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses ProductCatalogsController::delete()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @uses ProductCatalogsController::delete()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCatalogs->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '115153f3-2f59-4234-8ff8-e1b205761428';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCatalogs',
|
||||
'action' => 'delete',
|
||||
$id,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-catalogs');
|
||||
|
||||
$cntAfter = $this->ProductCatalogs->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
455
tests/TestCase/Controller/ProductCategoriesControllerTest.php
Normal file
455
tests/TestCase/Controller/ProductCategoriesControllerTest.php
Normal file
@@ -0,0 +1,455 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Controller\ProductCategoriesController;
|
||||
use CakeProducts\Model\Table\ProductCategoriesTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeProducts\Controller\ProductCategoriesController Test Case
|
||||
*
|
||||
* @uses ProductCategoriesController
|
||||
*/
|
||||
class ProductCategoriesControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
* Test subject table
|
||||
*
|
||||
* @var ProductCategoriesTable|Table
|
||||
*/
|
||||
protected $ProductCategories;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCatalogs',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->enableCsrfToken();
|
||||
$this->enableSecurityToken();
|
||||
$this->ProductCategories = $this->getTableLocator()->get('ProductCategories');
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCategories);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoriesController::index
|
||||
*/
|
||||
public function testIndexGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'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 ProductCategoriesController::index
|
||||
*/
|
||||
public function testIndexGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'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 ProductCategoriesController::view
|
||||
*/
|
||||
public function testViewGetUnauthenticated(): void
|
||||
{
|
||||
$id = 1;
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'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 ProductCategoriesController::view
|
||||
*/
|
||||
public function testViewGetLoggedIn(): void
|
||||
{
|
||||
$id = 1;
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'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 ProductCategoriesController::add
|
||||
*/
|
||||
public function testAddGetUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategories->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ProductCategories->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoriesController::add
|
||||
*/
|
||||
public function testAddGetLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategories->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCategories->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 ProductCategoriesController::add
|
||||
*/
|
||||
public function testAddPostLoggedInSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategories->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => 'Electrical Plugs',
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'category_description' => 'electrical',
|
||||
'parent_id' => 3,
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-categories');
|
||||
|
||||
$cntAfter = $this->ProductCategories->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 ProductCategoriesController::add
|
||||
*/
|
||||
public function testAddPostLoggedInFailure(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategories->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'product_catalog_id' => '',
|
||||
'category_description' => 'electrical',
|
||||
'parent_id' => '',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCategories->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoriesController::edit
|
||||
*/
|
||||
public function testEditGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'edit',
|
||||
1,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoriesController::edit
|
||||
*/
|
||||
public function testEditGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'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 ProductCategoriesController::edit
|
||||
*/
|
||||
public function testEditPutLoggedInSuccess(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = 1;
|
||||
$before = $this->ProductCategories->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
'name' => 'Electrical v2',
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'category_description' => 'electrical v2',
|
||||
'parent_id' => '',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-categories');
|
||||
|
||||
$after = $this->ProductCategories->get($id);
|
||||
$this->assertEquals($data['name'], $after->name);
|
||||
$this->assertEquals($data['product_catalog_id'], $after->product_catalog_id);
|
||||
$this->assertEquals($data['category_description'], $after->category_description);
|
||||
$this->assertNull($after->parent_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 ProductCategoriesController::edit
|
||||
*/
|
||||
public function testEditPutLoggedInFailure(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = 1;
|
||||
$before = $this->ProductCategories->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'product_catalog_id' => '',
|
||||
'category_description' => 'electrical',
|
||||
'parent_id' => '',
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->ProductCategories->get($id);
|
||||
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoriesController::delete
|
||||
*/
|
||||
public function testDeleteUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategories->find()->count();
|
||||
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ProductCategories->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
*@throws Exception
|
||||
*
|
||||
* @uses ProductCategoriesController::delete
|
||||
*/
|
||||
public function testDeleteLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategories->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategories',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-categories');
|
||||
|
||||
$cntAfter = $this->ProductCategories->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use CakeProducts\Controller\ProductCategoryAttributeOptionsController;
|
||||
use CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeProducts\Controller\ProductCategoryAttributeOptionsController Test Case
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController
|
||||
*/
|
||||
class ProductCategoryAttributeOptionsControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var ProductCategoryAttributeOptionsTable|Table
|
||||
*/
|
||||
protected $ProductCategoryAttributeOptions;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCategoryAttributeOptions',
|
||||
'plugin.CakeProducts.ProductCategoryAttributes',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->enableCsrfToken();
|
||||
$this->enableSecurityToken();
|
||||
$config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class];
|
||||
$this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCategoryAttributeOptions);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses CustomersContactsController::add
|
||||
*/
|
||||
public function testAddGetUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributeOptions',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses CustomersContactsController::add
|
||||
*/
|
||||
public function testAddGetLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributeOptions',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributeOptions->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 CustomersContactsController::add
|
||||
*/
|
||||
public function testAddPostLoggedInHasNoEffect(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributeOptions',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses CustomersContactsController::delete
|
||||
*/
|
||||
public function testDeleteUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributeOptions',
|
||||
'action' => 'delete',
|
||||
'e06f1723-2456-483a-b3c4-004603e032a8',
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
*@throws Exception
|
||||
*
|
||||
* @uses CustomersContactsController::delete
|
||||
*/
|
||||
public function testDeleteLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributeOptions',
|
||||
'action' => 'delete',
|
||||
'e06f1723-2456-483a-b3c4-004603e032a8',
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-category-attributes');
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributeOptions->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,498 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Controller\ProductCategoryAttributesController;
|
||||
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeProducts\Controller\ProductCategoryAttributesController Test Case
|
||||
*
|
||||
* @uses ProductCategoryAttributesController
|
||||
*/
|
||||
class ProductCategoryAttributesControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var ProductCategoryAttributesTable|Table
|
||||
*/
|
||||
protected $ProductCategoryAttributes;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCategoryAttributes',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->enableCsrfToken();
|
||||
$this->enableSecurityToken();
|
||||
$config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class];
|
||||
$this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCategoryAttributes);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoryAttributesController::index
|
||||
*/
|
||||
public function testIndexGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'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 ProductCategoryAttributesController::index
|
||||
*/
|
||||
public function testIndexGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'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 ProductCategoryAttributesController::view
|
||||
*/
|
||||
public function testViewGetUnauthenticated(): void
|
||||
{
|
||||
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'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 ProductCategoryAttributesController::view
|
||||
*/
|
||||
public function testViewGetLoggedIn(): void
|
||||
{
|
||||
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'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 ProductCategoryAttributesController::add
|
||||
*/
|
||||
public function testAddGetUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributes->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributes->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoryAttributesController::add
|
||||
*/
|
||||
public function testAddGetLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributes->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributes->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 ProductCategoryAttributesController::add
|
||||
*/
|
||||
public function testAddPostLoggedInSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributes->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => 'Size',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'attribute_type_id' => 2,
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-category-attributes');
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributes->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 ProductCategoryAttributesController::add
|
||||
*/
|
||||
public function testAddPostLoggedInSuccessConstrainedWithOptions(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributes->find()->count();
|
||||
$cntOptionsBefore = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => 'Size',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'attribute_type_id' => 1,
|
||||
'enabled' => true,
|
||||
'product_category_attribute_options' => [
|
||||
[
|
||||
'attribute_value' => 'XL',
|
||||
'attribute_label' => 'XL',
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'attribute_value' => 'L',
|
||||
'attribute_label' => 'L',
|
||||
'enabled' => true,
|
||||
]
|
||||
],
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-category-attributes');
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributes->find()->count();
|
||||
$cntOptionsAfter = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count();
|
||||
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
$this->assertEquals($cntOptionsBefore + 2, $cntOptionsAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoryAttributesController::add
|
||||
*/
|
||||
public function testAddPostLoggedInFailure(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributes->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'product_category_id' => 1,
|
||||
'attribute_type_id' => 1,
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributes->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoryAttributesController::edit
|
||||
*/
|
||||
public function testEditGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'edit',
|
||||
'37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoryAttributesController::edit
|
||||
*/
|
||||
public function testEditGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'edit',
|
||||
'37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
];
|
||||
$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 ProductCategoryAttributesController::edit
|
||||
*/
|
||||
public function testEditPutLoggedInSuccess(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
|
||||
$before = $this->ProductCategoryAttributes->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
'name' => 'Color',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'attribute_type_id' => 1,
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-category-attributes');
|
||||
|
||||
$after = $this->ProductCategoryAttributes->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 ProductCategoryAttributesController::edit
|
||||
*/
|
||||
public function testEditPutLoggedInFailure(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c';
|
||||
$before = $this->ProductCategoryAttributes->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'name' => '',
|
||||
'product_category_id' => 1,
|
||||
'attribute_type_id' => 1,
|
||||
'enabled' => true,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->ProductCategoryAttributes->get($id);
|
||||
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductCategoryAttributesController::delete
|
||||
*/
|
||||
public function testDeleteUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributes->find()->count();
|
||||
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'delete',
|
||||
'37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributes->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
*@throws Exception
|
||||
*
|
||||
* @uses ProductCategoryAttributesController::delete
|
||||
*/
|
||||
public function testDeleteLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryAttributes->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductCategoryAttributes',
|
||||
'action' => 'delete',
|
||||
'37078cf0-0130-4b93-bb7e-abe7d665ed2c',
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-category-attributes');
|
||||
|
||||
$cntAfter = $this->ProductCategoryAttributes->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
452
tests/TestCase/Controller/ProductsControllerTest.php
Normal file
452
tests/TestCase/Controller/ProductsControllerTest.php
Normal file
@@ -0,0 +1,452 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Controller\ProductsController;
|
||||
use CakeProducts\Model\Table\ProductCatalogsTable;
|
||||
use CakeProducts\Model\Table\ProductsTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeProducts\Controller\ProductsController Test Case
|
||||
*
|
||||
* @uses ProductsController
|
||||
*/
|
||||
class ProductsControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
* Test subject table
|
||||
*
|
||||
* @var ProductsTable|Table
|
||||
*/
|
||||
protected $Products;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.Products',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
// 'plugin.CakeProducts.ProductCatalogs',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->enableCsrfToken();
|
||||
$this->enableSecurityToken();
|
||||
$config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class];
|
||||
$this->Products = $this->getTableLocator()->get('Products', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->Products);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductsController::index
|
||||
*/
|
||||
public function testIndexGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'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 ProductsController::index
|
||||
*/
|
||||
public function testIndexGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'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 ProductsController::view
|
||||
*/
|
||||
public function testViewGetUnauthenticated(): void
|
||||
{
|
||||
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'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 ProductsController::view
|
||||
*/
|
||||
public function testViewGetLoggedIn(): void
|
||||
{
|
||||
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'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 ProductsController::add
|
||||
*/
|
||||
public function testAddGetUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->Products->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->Products->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductsController::add
|
||||
*/
|
||||
public function testAddGetLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->Products->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->Products->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 ProductsController::add
|
||||
*/
|
||||
public function testAddPostLoggedInSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->Products->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'name' => '16AWG WIRE RED',
|
||||
'product_type_id' => 1,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('products');
|
||||
|
||||
$cntAfter = $this->Products->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 ProductsController::add
|
||||
*/
|
||||
public function testAddPostLoggedInFailure(): void
|
||||
{
|
||||
$cntBefore = $this->Products->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'product_catalog_id' => '',
|
||||
'product_category_id' => '',
|
||||
'name' => '',
|
||||
'product_type_id' => 1,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->Products->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductsController::edit
|
||||
*/
|
||||
public function testEditGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'edit',
|
||||
'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductsController::edit
|
||||
*/
|
||||
public function testEditGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'edit',
|
||||
'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
];
|
||||
$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 ProductsController::edit
|
||||
*/
|
||||
public function testEditPutLoggedInSuccess(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
|
||||
$before = $this->Products->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'name' => 'edited product name',
|
||||
'product_type_id' => 1,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('products');
|
||||
|
||||
$after = $this->Products->get($id);
|
||||
$this->assertEquals($data['name'], $after->name);
|
||||
// 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 ProductsController::edit
|
||||
*/
|
||||
public function testEditPutLoggedInFailure(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
|
||||
$before = $this->Products->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'product_catalog_id' => '',
|
||||
'product_category_id' => '',
|
||||
'name' => 'edited name not gonna take',
|
||||
'product_type_id' => 1,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->Products->get($id);
|
||||
$this->assertEquals($before->name, $after->name);
|
||||
$this->assertEquals($before->product_category_id, $after->product_category_id);
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*
|
||||
* @uses ProductsController::delete
|
||||
*/
|
||||
public function testDeleteUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->Products->find()->count();
|
||||
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'delete',
|
||||
'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->Products->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @return void
|
||||
*@throws Exception
|
||||
*
|
||||
* @uses ProductsController::delete
|
||||
*/
|
||||
public function testDeleteLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->Products->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'Products',
|
||||
'action' => 'delete',
|
||||
'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('products');
|
||||
|
||||
$cntAfter = $this->Products->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
107
tests/TestCase/Model/Table/ExternalProductCatalogsTableTest.php
Normal file
107
tests/TestCase/Model/Table/ExternalProductCatalogsTableTest.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Model\Table;
|
||||
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Model\Table\ExternalProductCatalogsTable;
|
||||
|
||||
/**
|
||||
* CakeProducts\Model\Table\ExternalProductCatalogsTable Test Case
|
||||
*/
|
||||
class ExternalProductCatalogsTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var \CakeProducts\Model\Table\ExternalProductCatalogsTable
|
||||
*/
|
||||
protected $ExternalProductCatalogs;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ExternalProductCatalogs',
|
||||
'plugin.CakeProducts.ProductCatalogs',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('ExternalProductCatalogs') ? [] : ['className' => ExternalProductCatalogsTable::class];
|
||||
$this->ExternalProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogs', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ExternalProductCatalogs);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* TestInitialize method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::initialize()
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
// verify all associations loaded
|
||||
$expectedAssociations = [
|
||||
'ProductCatalogs',
|
||||
];
|
||||
$associations = $this->ExternalProductCatalogs->associations();
|
||||
|
||||
$this->assertCount(count($expectedAssociations), $associations);
|
||||
foreach ($expectedAssociations as $expectedAssociation) {
|
||||
$this->assertTrue($this->ExternalProductCatalogs->hasAssociation($expectedAssociation));
|
||||
}
|
||||
|
||||
// verify all behaviors loaded
|
||||
$expectedBehaviors = [
|
||||
'Timestamp',
|
||||
];
|
||||
$behaviors = $this->ExternalProductCatalogs->behaviors();
|
||||
|
||||
$this->assertCount(count($expectedBehaviors), $behaviors);
|
||||
foreach ($expectedBehaviors as $expectedBehavior) {
|
||||
$this->assertTrue($this->ExternalProductCatalogs->hasBehavior($expectedBehavior));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::validationDefault()
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::buildRules()
|
||||
*/
|
||||
public function testBuildRules(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
96
tests/TestCase/Model/Table/ProductCatalogsTableTest.php
Normal file
96
tests/TestCase/Model/Table/ProductCatalogsTableTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Model\Table;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Model\Table\ProductCatalogsTable;
|
||||
|
||||
/**
|
||||
* CakeProducts\Model\Table\ProductCatalogsTable Test Case
|
||||
*/
|
||||
class ProductCatalogsTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var ProductCatalogsTable|Table
|
||||
*/
|
||||
protected $ProductCatalogs;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCatalogs',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class];
|
||||
$this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCatalogs);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* TestInitialize method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductCatalogsTable::initialize
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
// verify all associations loaded
|
||||
$expectedAssociations = [
|
||||
'ProductCategories',
|
||||
'ExternalProductCatalogs',
|
||||
];
|
||||
$associations = $this->ProductCatalogs->associations();
|
||||
|
||||
$this->assertCount(count($expectedAssociations), $associations);
|
||||
foreach ($expectedAssociations as $expectedAssociation) {
|
||||
$this->assertTrue($this->ProductCatalogs->hasAssociation($expectedAssociation));
|
||||
}
|
||||
|
||||
// verify all behaviors loaded
|
||||
$expectedBehaviors = [];
|
||||
$behaviors = $this->ProductCatalogs->behaviors();
|
||||
|
||||
$this->assertCount(count($expectedBehaviors), $behaviors);
|
||||
foreach ($expectedBehaviors as $expectedBehavior) {
|
||||
$this->assertTrue($this->ProductCatalogs->hasBehavior($expectedBehavior));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductCatalogsTable::validationDefault
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
111
tests/TestCase/Model/Table/ProductCategoriesTableTest.php
Normal file
111
tests/TestCase/Model/Table/ProductCategoriesTableTest.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Model\Table;
|
||||
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Model\Table\ProductCategoriesTable;
|
||||
|
||||
/**
|
||||
* CakeProducts\Model\Table\ProductCategoriesTable Test Case
|
||||
*/
|
||||
class ProductCategoriesTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var \CakeProducts\Model\Table\ProductCategoriesTable
|
||||
*/
|
||||
protected $ProductCategories;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
'plugin.CakeProducts.ProductCatalogs',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('ProductCategories') ? [] : ['className' => ProductCategoriesTable::class];
|
||||
$this->ProductCategories = $this->getTableLocator()->get('ProductCategories', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCategories);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* TestInitialize method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::initialize()
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
// verify all associations loaded
|
||||
$expectedAssociations = [
|
||||
'ProductCatalogs',
|
||||
'ParentProductCategories',
|
||||
'ChildProductCategories',
|
||||
// 'Products',
|
||||
// 'ProductCategoryAttributes',
|
||||
];
|
||||
$associations = $this->ProductCategories->associations();
|
||||
|
||||
$this->assertCount(count($expectedAssociations), $associations);
|
||||
foreach ($expectedAssociations as $expectedAssociation) {
|
||||
$this->assertTrue($this->ProductCategories->hasAssociation($expectedAssociation));
|
||||
}
|
||||
|
||||
// verify all behaviors loaded
|
||||
$expectedBehaviors = [
|
||||
'Tree',
|
||||
];
|
||||
$behaviors = $this->ProductCategories->behaviors();
|
||||
|
||||
$this->assertCount(count($expectedBehaviors), $behaviors);
|
||||
foreach ($expectedBehaviors as $expectedBehavior) {
|
||||
$this->assertTrue($this->ProductCategories->hasBehavior($expectedBehavior));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::validationDefault()
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeProducts\Model\Table\ProductCategoriesTable::buildRules()
|
||||
*/
|
||||
public function testBuildRules(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Model\Table;
|
||||
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable;
|
||||
|
||||
/**
|
||||
* CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable Test Case
|
||||
*/
|
||||
class ProductCategoryAttributeOptionsTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var ProductCategoryAttributeOptionsTable
|
||||
*/
|
||||
protected $ProductCategoryAttributeOptions;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCategoryAttributeOptions',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class];
|
||||
$this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCategoryAttributeOptions);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* TestInitialize method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductCategoryAttributeOptionsTable::initialize
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
// verify all associations loaded
|
||||
$expectedAssociations = [
|
||||
'ProductCategoryAttributes',
|
||||
];
|
||||
$associations = $this->ProductCategoryAttributeOptions->associations();
|
||||
|
||||
$this->assertCount(count($expectedAssociations), $associations);
|
||||
foreach ($expectedAssociations as $expectedAssociation) {
|
||||
$this->assertTrue($this->ProductCategoryAttributeOptions->hasAssociation($expectedAssociation));
|
||||
}
|
||||
|
||||
// verify all behaviors loaded
|
||||
$expectedBehaviors = [];
|
||||
$behaviors = $this->ProductCategoryAttributeOptions->behaviors();
|
||||
|
||||
$this->assertCount(count($expectedBehaviors), $behaviors);
|
||||
foreach ($expectedBehaviors as $expectedBehavior) {
|
||||
$this->assertTrue($this->ProductCategoryAttributeOptions->hasBehavior($expectedBehavior));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductCategoryAttributeOptionsTable::validationDefault
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductCategoryAttributeOptionsTable::buildRules
|
||||
*/
|
||||
public function testBuildRules(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Model\Table;
|
||||
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
|
||||
|
||||
/**
|
||||
* CakeProducts\Model\Table\ProductCategoryAttributesTable Test Case
|
||||
*/
|
||||
class ProductCategoryAttributesTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var ProductCategoryAttributesTable
|
||||
*/
|
||||
protected $ProductCategoryAttributes;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductCategoryAttributes',
|
||||
'plugin.CakeProducts.ProductCategoryAttributeOptions',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class];
|
||||
$this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCategoryAttributes);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* TestInitialize method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductCategoryAttributesTable::initialize
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
// verify all associations loaded
|
||||
$expectedAssociations = [
|
||||
'ProductCategories',
|
||||
'ProductCategoryAttributeOptions',
|
||||
];
|
||||
$associations = $this->ProductCategoryAttributes->associations();
|
||||
|
||||
$this->assertCount(count($expectedAssociations), $associations);
|
||||
foreach ($expectedAssociations as $expectedAssociation) {
|
||||
$this->assertTrue($this->ProductCategoryAttributes->hasAssociation($expectedAssociation));
|
||||
}
|
||||
|
||||
// verify all behaviors loaded
|
||||
$expectedBehaviors = [];
|
||||
$behaviors = $this->ProductCategoryAttributes->behaviors();
|
||||
|
||||
$this->assertCount(count($expectedBehaviors), $behaviors);
|
||||
foreach ($expectedBehaviors as $expectedBehavior) {
|
||||
$this->assertTrue($this->ProductCategoryAttributes->hasBehavior($expectedBehavior));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductCategoryAttributesTable::validationDefault
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductCategoryAttributesTable::buildRules
|
||||
*/
|
||||
public function testBuildRules(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
105
tests/TestCase/Model/Table/ProductsTableTest.php
Normal file
105
tests/TestCase/Model/Table/ProductsTableTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Model\Table;
|
||||
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Model\Table\ProductsTable;
|
||||
|
||||
/**
|
||||
* CakeProducts\Model\Table\ProductsTable Test Case
|
||||
*/
|
||||
class ProductsTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var ProductsTable
|
||||
*/
|
||||
protected $Products;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.Products',
|
||||
'plugin.CakeProducts.ProductCategories',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class];
|
||||
$this->Products = $this->getTableLocator()->get('Products', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->Products);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* TestInitialize method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductsTable::initialize
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
// verify all associations loaded
|
||||
$expectedAssociations = [
|
||||
'ProductCategories',
|
||||
];
|
||||
$associations = $this->Products->associations();
|
||||
|
||||
$this->assertCount(count($expectedAssociations), $associations);
|
||||
foreach ($expectedAssociations as $expectedAssociation) {
|
||||
$this->assertTrue($this->Products->hasAssociation($expectedAssociation));
|
||||
}
|
||||
|
||||
// verify all behaviors loaded
|
||||
$expectedBehaviors = [];
|
||||
$behaviors = $this->Products->behaviors();
|
||||
|
||||
$this->assertCount(count($expectedBehaviors), $behaviors);
|
||||
foreach ($expectedBehaviors as $expectedBehavior) {
|
||||
$this->assertTrue($this->Products->hasBehavior($expectedBehavior));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductsTable::validationDefault
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
* @uses ProductsTable::buildRules
|
||||
*/
|
||||
public function testBuildRules(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
55
tests/bootstrap.php
Normal file
55
tests/bootstrap.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Test suite bootstrap for CakeProducts.
|
||||
*
|
||||
* This function is used to find the location of CakePHP whether CakePHP
|
||||
* has been installed as a dependency of the plugin, or the plugin is itself
|
||||
* installed as a dependency of an application.
|
||||
*/
|
||||
$findRoot = function ($root) {
|
||||
do {
|
||||
$lastRoot = $root;
|
||||
$root = dirname($root);
|
||||
if (is_dir($root . '/vendor/cakephp/cakephp')) {
|
||||
return $root;
|
||||
}
|
||||
} while ($root !== $lastRoot);
|
||||
|
||||
throw new Exception('Cannot find the root of the application, unable to run tests');
|
||||
};
|
||||
$root = $findRoot(__FILE__);
|
||||
unset($findRoot);
|
||||
|
||||
chdir($root);
|
||||
|
||||
require_once $root . '/vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* Define fallback values for required constants and configuration.
|
||||
* To customize constants and configuration remove this require
|
||||
* and define the data required by your plugin here.
|
||||
*/
|
||||
require_once $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
|
||||
|
||||
if (file_exists($root . '/config/bootstrap.php')) {
|
||||
require $root . '/config/bootstrap.php';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load schema from a SQL dump file.
|
||||
*
|
||||
* If your plugin does not use database fixtures you can
|
||||
* safely delete this.
|
||||
*
|
||||
* If you want to support multiple databases, consider
|
||||
* using migrations to provide schema for your plugin,
|
||||
* and using \Migrations\TestSuite\Migrator to load schema.
|
||||
*/
|
||||
use Cake\TestSuite\Fixture\SchemaLoader;
|
||||
|
||||
// Load a schema dump file.
|
||||
(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
|
||||
1
tests/schema.sql
Normal file
1
tests/schema.sql
Normal file
@@ -0,0 +1 @@
|
||||
-- Test database schema for CakeProducts
|
||||
Reference in New Issue
Block a user