phpcs phpcbf
This commit is contained in:
@@ -3,347 +3,333 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeAddresses\Test\TestCase\Controller;
|
||||
|
||||
use CakeAddresses\Controller\AddressesController;
|
||||
use CakeAddresses\Model\Table\AddressesTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeAddresses\Controller\AddressesController Test Case
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController
|
||||
*/
|
||||
class AddressesControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
class AddressesControllerTest extends BaseControllerTest {
|
||||
|
||||
/**
|
||||
* Addresses Table
|
||||
*
|
||||
* @var \CakeAddresses\Model\Table\AddressesTable
|
||||
*/
|
||||
protected $Addresses;
|
||||
protected $Addresses;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeAddresses.Addresses',
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeAddresses.Addresses',
|
||||
// 'plugin.CakeAddresses.Cities',
|
||||
'plugin.CakeAddresses.Countries',
|
||||
'plugin.CakeAddresses.Countries',
|
||||
// 'plugin.CakeAddresses.Regions',
|
||||
'plugin.CakeAddresses.States',
|
||||
'plugin.CakeAddresses.States',
|
||||
// 'plugin.CakeAddresses.Subregions',
|
||||
];
|
||||
];
|
||||
|
||||
/**
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->Addresses = $this->getTableLocator()->get('CakeAddresses.Addresses');
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->Addresses = $this->getTableLocator()->get('CakeAddresses.Addresses');
|
||||
// $this->enableCsrfToken();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->Addresses);
|
||||
protected function tearDown(): void {
|
||||
unset($this->Addresses);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController::index()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGet(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
public function testIndexGet(): void {
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* Tests the view action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController::view()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGet(): void
|
||||
{
|
||||
$id = 1;
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
public function testViewGet(): void {
|
||||
$id = 1;
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController::add()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGet(): void
|
||||
{
|
||||
$cntBefore = $this->Addresses->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
public function testAddGet(): void {
|
||||
$cntBefore = $this->Addresses->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->Addresses->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
$cntAfter = $this->Addresses->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController::add()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->Addresses->find()->count();
|
||||
public function testAddPostSuccess(): void {
|
||||
$cntBefore = $this->Addresses->find()->count();
|
||||
|
||||
$this->loginUserByRole();
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'address_name' => 'new address',
|
||||
'contact_name' => 'john doe',
|
||||
'address_line1' => '123 Test ST',
|
||||
'address_line2' => '',
|
||||
'city' => 'Seattle',
|
||||
'city_id' => '',
|
||||
'state_id' => 1462,
|
||||
'postal_code' => '98056',
|
||||
'country_id' => 233,
|
||||
'phone_number' => '',
|
||||
'email' => '',
|
||||
'notes' => '',
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('addresses');
|
||||
$this->loginUserByRole();
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'address_name' => 'new address',
|
||||
'contact_name' => 'john doe',
|
||||
'address_line1' => '123 Test ST',
|
||||
'address_line2' => '',
|
||||
'city' => 'Seattle',
|
||||
'city_id' => '',
|
||||
'state_id' => 1462,
|
||||
'postal_code' => '98056',
|
||||
'country_id' => 233,
|
||||
'phone_number' => '',
|
||||
'email' => '',
|
||||
'notes' => '',
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('addresses');
|
||||
|
||||
$cntAfter = $this->Addresses->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
}
|
||||
$cntAfter = $this->Addresses->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController::add()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostFailure(): void
|
||||
{
|
||||
$cntBefore = $this->Addresses->find()->count();
|
||||
public function testAddPostFailure(): void {
|
||||
$cntBefore = $this->Addresses->find()->count();
|
||||
|
||||
$this->loginUserByRole();
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'address_name' => '',
|
||||
'contact_name' => '',
|
||||
'address_line1' => '',
|
||||
'address_line2' => '',
|
||||
'city' => 'Seattle',
|
||||
'city_id' => '',
|
||||
'state_id' => 1462,
|
||||
'postal_code' => '98056',
|
||||
'country_id' => 233,
|
||||
'phone_number' => '',
|
||||
'email' => '',
|
||||
'notes' => '',
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$this->loginUserByRole();
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'address_name' => '',
|
||||
'contact_name' => '',
|
||||
'address_line1' => '',
|
||||
'address_line2' => '',
|
||||
'city' => 'Seattle',
|
||||
'city_id' => '',
|
||||
'state_id' => 1462,
|
||||
'postal_code' => '98056',
|
||||
'country_id' => 233,
|
||||
'phone_number' => '',
|
||||
'email' => '',
|
||||
'notes' => '',
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->Addresses->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
$cntAfter = $this->Addresses->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController::edit()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGet(): void
|
||||
{
|
||||
$id = 1;
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
public function testEditGet(): void {
|
||||
$id = 1;
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'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 \CakeAddresses\Controller\AddressesController::edit()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutSuccess(): void
|
||||
{
|
||||
$this->loginUserByRole();
|
||||
$id = 1;
|
||||
$before = $this->Addresses->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
'address_name' => 'new address',
|
||||
'contact_name' => 'john doe',
|
||||
'address_line1' => '123 Test ST',
|
||||
'address_line2' => '',
|
||||
'city' => 'Seattle',
|
||||
'city_id' => '',
|
||||
'state_id' => 1462,
|
||||
'postal_code' => '98056',
|
||||
'country_id' => 233,
|
||||
'phone_number' => '',
|
||||
'email' => '',
|
||||
'notes' => '',
|
||||
];
|
||||
$this->put($url, $data);
|
||||
public function testEditPutSuccess(): void {
|
||||
$this->loginUserByRole();
|
||||
$id = 1;
|
||||
$before = $this->Addresses->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
'address_name' => 'new address',
|
||||
'contact_name' => 'john doe',
|
||||
'address_line1' => '123 Test ST',
|
||||
'address_line2' => '',
|
||||
'city' => 'Seattle',
|
||||
'city_id' => '',
|
||||
'state_id' => 1462,
|
||||
'postal_code' => '98056',
|
||||
'country_id' => 233,
|
||||
'phone_number' => '',
|
||||
'email' => '',
|
||||
'notes' => '',
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('addresses');
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('addresses');
|
||||
|
||||
$after = $this->Addresses->get($id);
|
||||
// assert saved properly below
|
||||
}
|
||||
$after = $this->Addresses->get($id);
|
||||
// assert saved properly below
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController::edit()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutFailure(): void
|
||||
{
|
||||
$id = 1;
|
||||
$before = $this->Addresses->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'address_name' => '',
|
||||
'contact_name' => '',
|
||||
'address_line1' => '',
|
||||
'address_line2' => '',
|
||||
'city' => 'Seattle',
|
||||
'city_id' => '',
|
||||
'state_id' => 1462,
|
||||
'postal_code' => '98056',
|
||||
'country_id' => 233,
|
||||
'phone_number' => '',
|
||||
'email' => '',
|
||||
'notes' => '',
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->Addresses->get($id);
|
||||
public function testEditPutFailure(): void {
|
||||
$id = 1;
|
||||
$before = $this->Addresses->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'address_name' => '',
|
||||
'contact_name' => '',
|
||||
'address_line1' => '',
|
||||
'address_line2' => '',
|
||||
'city' => 'Seattle',
|
||||
'city_id' => '',
|
||||
'state_id' => 1462,
|
||||
'postal_code' => '98056',
|
||||
'country_id' => 233,
|
||||
'phone_number' => '',
|
||||
'email' => '',
|
||||
'notes' => '',
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->Addresses->get($id);
|
||||
|
||||
// assert save failed below
|
||||
}
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\AddressesController::delete()
|
||||
* @throws Exception
|
||||
* @throws \PHPUnit\Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$cntBefore = $this->Addresses->find()->count();
|
||||
public function testDelete(): void {
|
||||
$cntBefore = $this->Addresses->find()->count();
|
||||
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Addresses',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
|
||||
$cntAfter = $this->Addresses->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
|
||||
$cntAfter = $this->Addresses->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user