152 lines
3.4 KiB
PHP
152 lines
3.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace CakeAddresses\Test\TestCase\Controller;
|
|
|
|
use CakeAddresses\Controller\CountriesController;
|
|
use PHPUnit\Exception;
|
|
|
|
/**
|
|
* CakeAddresses\Controller\CountriesController Test Case
|
|
*
|
|
* @uses \CakeAddresses\Controller\CountriesController
|
|
*/
|
|
class CountriesControllerTest extends BaseControllerTest
|
|
{
|
|
/**
|
|
* AnsibleGroups Table
|
|
*
|
|
* @var \CakeAddresses\Model\Table\CountriesTable
|
|
*/
|
|
protected $Countries;
|
|
|
|
/**
|
|
* Fixtures
|
|
*
|
|
* @var array<string>
|
|
*/
|
|
protected array $fixtures = [
|
|
'plugin.CakeAddresses.Regions',
|
|
'plugin.CakeAddresses.Subregions',
|
|
'plugin.CakeAddresses.Countries',
|
|
'plugin.CakeAddresses.States',
|
|
// 'plugin.CakeAddresses.Cities',
|
|
];
|
|
|
|
/**
|
|
* setUp method
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->Countries = $this->getTableLocator()->get('Countries');
|
|
$this->enableCsrfToken();
|
|
}
|
|
|
|
/**
|
|
* tearDown method
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function tearDown(): void
|
|
{
|
|
unset($this->Countries);
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* Test index method
|
|
*
|
|
* Tests the index action with an unauthenticated user (not logged in)
|
|
*
|
|
* @uses \CakeAddresses\Controller\CountriesController::index()
|
|
* @throws Exception
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testIndexGetUnauthenticated(): void
|
|
{
|
|
$url = [
|
|
'plugin' => 'CakeAddresses',
|
|
'controller' => 'Countries',
|
|
'action' => 'index',
|
|
];
|
|
$this->get($url);
|
|
$this->assertResponseCode(302);
|
|
$this->assertRedirectContains('login');
|
|
}
|
|
|
|
/**
|
|
* Test index method
|
|
*
|
|
* Tests the index action with a logged in user
|
|
*
|
|
* @uses \CakeAddresses\Controller\CountriesController::index()
|
|
* @throws Exception
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testIndexGetLoggedIn(): void
|
|
{
|
|
$this->loginUserByRole();
|
|
$url = [
|
|
'plugin' => 'CakeAddresses',
|
|
'controller' => 'Countries',
|
|
'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\CountriesController::view()
|
|
* @throws Exception
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testViewGetUnauthenticated(): void
|
|
{
|
|
$id = 233;
|
|
$url = [
|
|
'plugin' => 'CakeAddresses',
|
|
'controller' => 'Countries',
|
|
'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 \CakeAddresses\Controller\CountriesController::view()
|
|
* @throws Exception
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testViewGetLoggedIn(): void
|
|
{
|
|
$id = 233;
|
|
$this->loginUserByRole();
|
|
$url = [
|
|
'plugin' => 'CakeAddresses',
|
|
'controller' => 'Countries',
|
|
'action' => 'view',
|
|
$id,
|
|
];
|
|
$this->get($url);
|
|
$this->assertResponseCode(200);
|
|
}
|
|
}
|