CakeAddresses/tests/TestCase/Controller/CitiesControllerTest.php

104 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Controller;
use CakeAddresses\Controller\CitiesController;
use PHPUnit\Exception;
/**
* CakeAddresses\Controller\CitiesController Test Case
*
* @uses \CakeAddresses\Controller\CitiesController
*/
class CitiesControllerTest extends BaseControllerTest
{
/**
* Cities Table
*
* @var \CakeAddresses\Model\Table\CitiesTable
*/
protected $Cities;
/**
* 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->Cities = $this->getTableLocator()->get('Cities');
$this->enableCsrfToken();
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Cities);
parent::tearDown();
}
/**
* Test select method
*
* Tests the select action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\CitiesController::select()
* @throws Exception
*
* @return void
*/
public function testSelectGetUnauthenticated(): void
{
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Cities',
'action' => 'select',
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test select method
*
* Tests the select action with a logged in user
*
* @uses \CakeAddresses\Controller\CitiesController::select()
* @throws Exception
*
* @return void
*/
public function testSelectGetLoggedIn(): void
{
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Cities',
'action' => 'select',
];
$this->get($url);
$this->assertResponseCode(200);
}
}