first real commit in standalone repo
This commit is contained in:
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeContactUs\Test\TestCase\Controller;
|
||||
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeContactUs\Controller\ContactUsFormSubmissionsController;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* CakeContactUs\Controller\ContactUsFormSubmissionsController Test Case
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController
|
||||
*/
|
||||
class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
{
|
||||
use IntegrationTestTrait;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeContactUs.ContactUsFormSubmissions',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions');
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ContactUsFormSubmissions);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with a logged in user
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGetLoggedIn(): void
|
||||
{
|
||||
// $this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* Tests the view action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGetUnauthenticated(): void
|
||||
{
|
||||
$id = 1;
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'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 \CakeContactUs\Controller\ContactUsFormSubmissionsController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGetLoggedIn(): void
|
||||
{
|
||||
$id = 1;
|
||||
// $this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGetUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ContactUsFormSubmissions->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGetLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
|
||||
// $this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ContactUsFormSubmissions->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostLoggedInSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
|
||||
// $this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('contactusformsubmissions/view');
|
||||
|
||||
$cntAfter = $this->ContactUsFormSubmissions->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostLoggedInFailure(): void
|
||||
{
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
|
||||
// $this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ContactUsFormSubmissions->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGetUnauthenticated(): void
|
||||
{
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'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 \CakeContactUs\Controller\ContactUsFormSubmissionsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGetLoggedIn(): void
|
||||
{
|
||||
// $this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'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 \CakeContactUs\Controller\ContactUsFormSubmissionsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutLoggedInSuccess(): void
|
||||
{
|
||||
// $this->loginUserByRole('admin');
|
||||
$id = 1;
|
||||
$before = $this->ContactUsFormSubmissions->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('contactusformsubmissions/view');
|
||||
|
||||
$after = $this->ContactUsFormSubmissions->get($id);
|
||||
// assert saved properly below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutLoggedInFailure(): void
|
||||
{
|
||||
// $this->loginUserByRole('admin');
|
||||
$id = 1;
|
||||
$before = $this->ContactUsFormSubmissions->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->ContactUsFormSubmissions->get($id);
|
||||
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with an unauthenticated user (not logged in)
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::delete()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteUnauthenticated(): void
|
||||
{
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('login');
|
||||
|
||||
$cntAfter = $this->ContactUsFormSubmissions->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @uses \CakeContactUs\Controller\ContactUsFormSubmissionsController::delete()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteLoggedIn(): void
|
||||
{
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
|
||||
// $this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeContactUs',
|
||||
'controller' => 'ContactUsFormSubmissions',
|
||||
'action' => 'delete',
|
||||
1,
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('contactusformsubmissions');
|
||||
|
||||
$cntAfter = $this->ContactUsFormSubmissions->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user