first real commit in standalone repo
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeContactUs\Test\TestCase\Controller\Component;
|
||||
|
||||
use Cake\Controller\ComponentRegistry;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeContactUs\Controller\Component\ContactUsComponent;
|
||||
|
||||
/**
|
||||
* CakeContactUs\Controller\Component\ContactUsComponent Test Case
|
||||
*/
|
||||
class ContactUsComponentTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var \CakeContactUs\Controller\Component\ContactUsComponent
|
||||
*/
|
||||
protected $ContactUs;
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$registry = new ComponentRegistry();
|
||||
$this->ContactUs = new ContactUsComponent($registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ContactUs);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeContactUs\Test\TestCase\Model\Table;
|
||||
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeContactUs\Model\Table\ContactUsFormSubmissionsTable;
|
||||
|
||||
/**
|
||||
* CakeContactUs\Model\Table\ContactUsFormSubmissionsTable Test Case
|
||||
*/
|
||||
class ContactUsFormSubmissionsTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable
|
||||
*/
|
||||
protected $ContactUsFormSubmissions;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeContactUs.ContactUsFormSubmissions',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('ContactUsFormSubmissions') ? [] : ['className' => ContactUsFormSubmissionsTable::class];
|
||||
$this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ContactUsFormSubmissions);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* TestInitialize method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable::initialize()
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
// verify all associations loaded
|
||||
$expectedAssociations = [];
|
||||
$associations = $this->ContactUsFormSubmissions->associations();
|
||||
|
||||
$this->assertCount(count($expectedAssociations), $associations);
|
||||
foreach ($expectedAssociations as $expectedAssociation) {
|
||||
$this->assertTrue($this->ContactUsFormSubmissions->hasAssociation($expectedAssociation));
|
||||
}
|
||||
|
||||
// verify all behaviors loaded
|
||||
$expectedBehaviors = [];
|
||||
$behaviors = $this->ContactUsFormSubmissions->behaviors();
|
||||
|
||||
$this->assertCount(count($expectedBehaviors), $behaviors);
|
||||
foreach ($expectedBehaviors as $expectedBehavior) {
|
||||
$this->assertTrue($this->ContactUsFormSubmissions->hasBehavior($expectedBehavior));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable::validationDefault()
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user