first standalone plugin commit
This commit is contained in:
154
tests/TestCase/Controller/RegionsControllerTest.php
Normal file
154
tests/TestCase/Controller/RegionsControllerTest.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeAddresses\Test\TestCase\Controller;
|
||||
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeAddresses\Controller\RegionsController;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeAddresses\Controller\RegionsController Test Case
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\RegionsController
|
||||
*/
|
||||
class RegionsControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
* Regions Table
|
||||
*
|
||||
* @var \CakeAddresses\Model\Table\RegionsTable
|
||||
*/
|
||||
protected $Regions;
|
||||
|
||||
/**
|
||||
* 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->Regions = $this->getTableLocator()->get('Regions');
|
||||
$this->enableCsrfToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->Regions);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeAddresses\Controller\RegionsController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Regions',
|
||||
'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\RegionsController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGetLoggedIn(): void
|
||||
{
|
||||
$this->loginUserByRole();
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Regions',
|
||||
'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\RegionsController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGetUnauthenticated(): void
|
||||
{
|
||||
$id = 1;
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Regions',
|
||||
'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\RegionsController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGetLoggedIn(): void
|
||||
{
|
||||
$id = 1;
|
||||
|
||||
$this->loginUserByRole();
|
||||
$url = [
|
||||
'plugin' => 'CakeAddresses',
|
||||
'controller' => 'Regions',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user