Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Apr 4, 2024
1 parent 9dfab49 commit 6bf3a21
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class AuthSandboxControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'app.Users',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class AuthSandboxControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'app.Users',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function initialize(): void {

$this->fetchTable('Sandbox.SandboxPosts')->ensureDemoData();

// Creating demo data
$user = $this->user();
// For demo purposes we use Configure instead of session
Configure::write('Auth.User.id', $user->id);
Expand Down
13 changes: 9 additions & 4 deletions plugins/Sandbox/templates/PluginExamples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
<div class="col-6">
<h3>Own plugins</h3>

<h4>CakeDecimal plugin <i>(NEW)</i></h4>
<h4>CakeDecimal plugin</h4>
<ul>
<li><?php echo $this->Html->link('Decimals and CakePHP', ['controller' => 'DecimalExamples', 'action' => 'index']); ?></li>
</ul>

<h4>Templating plugin <i>(NEW)</i></h4>
<h4>Templating plugin</h4>
<ul>
<li><?php echo $this->Html->link('Templating, (Font) icons and HTML snippets', ['controller' => 'TemplatingExamples', 'action' => 'index']); ?></li>
</ul>

<h4>Favorites plugin <i>(NEW)</i></h4>
<ul>
<li><?php echo $this->Html->link('Favorites (Star, Like, Reactions)', ['controller' => 'FavoriteExamples', 'action' => 'index']); ?></li>
</ul>

<h4>Queue plugin</h4>
<ul>
<li><?php echo $this->Html->link('Queue and CakePHP', ['controller' => 'QueueExamples', 'action' => 'index']); ?></li>
Expand Down Expand Up @@ -99,7 +104,7 @@
<div class="col-6">
<h3>Other plugins</h3>

<h4>StateMachine plugin <i>(NEW)</i></h4>
<h4>StateMachine plugin</h4>
<ul>
<li><?php echo $this->Html->link('Workflow Examples using StateMachine', ['plugin' => 'StateMachineSandbox', 'controller' => 'StateMachineSandbox', 'action' => 'index']); ?></li>
</ul>
Expand Down Expand Up @@ -154,7 +159,7 @@
<h3>TODO</h3>
<ul>
<li>Wysiwyg</li>
<li>Like / Favorite</li>
<li>Comments</li>
<li>... (see <a href="https://github.com/FriendsOfCake/awesome-cakephp" target="blank">awesome-cakephp</a>)</li>
</ul>

Expand Down
30 changes: 30 additions & 0 deletions plugins/Sandbox/tests/Fixture/SandboxProfilesFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

namespace Sandbox\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* SandboxProfilesFixture
*/
class SandboxProfilesFixture extends TestFixture {

/**
* Init method
*
* @return void
*/
public function init(): void {
$this->records = [
[
'id' => 1,
'username' => 'Lorem ipsum dolor sit amet',
'balance' => 1.5,
'extra' => 1.5,
],
];
parent::init();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AjaxExamplesControllerTest extends IntegrationTestCase {
protected bool $disableErrorHandlerMiddleware = true;

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'plugin.Data.Countries',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class BootstrapControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'plugin.Sandbox.SandboxAnimals',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class CalendarControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'plugin.Sandbox.Events',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class CaptchasControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'plugin.Captcha.Captchas',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class CsvControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'plugin.Data.Countries',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);

namespace Sandbox\Test\TestCase\Controller;

use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;

/**
* @uses \Sandbox\Controller\DecimalExamplesController
*/
class DecimalExamplesControllerTest extends TestCase {

use IntegrationTestTrait;

/**
* @var list<string>
*/
protected array $fixtures = [
'plugin.Sandbox.SandboxProfiles',
];

/**
* @uses \Sandbox\Controller\DecimalExamplesController::index()
* @return void
*/
public function testIndex(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'DecimalExamples', 'action' => 'index']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

/**
* @uses \Sandbox\Controller\DecimalExamplesController::forms()
* @return void
*/
public function testForms(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'DecimalExamples', 'action' => 'forms']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

/**
* @uses \Sandbox\Controller\DecimalExamplesController::validation()
* @return void
*/
public function testValidation(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'DecimalExamples', 'action' => 'validation']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

/**
* @uses \Sandbox\Controller\DecimalExamplesController::api()
* @return void
*/
public function testApi(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'DecimalExamples', 'action' => 'api']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);

namespace Sandbox\Test\TestCase\Controller;

use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;

/**
* @uses \Sandbox\Controller\FavoriteExamplesController
*/
class FavoriteExamplesControllerTest extends TestCase {

use IntegrationTestTrait;

/**
* @var list<string>
*/
protected array $fixtures = [
'plugin.Sandbox.SandboxPosts',
'plugin.Sandbox.SandboxUsers',
'plugin.Favorites.Favorites',
];

/**
* @uses \Sandbox\Controller\FavoriteExamplesController::index()
* @return void
*/
public function testIndex(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'FavoriteExamples', 'action' => 'index']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

/**
* @uses \Sandbox\Controller\FavoriteExamplesController::star()
* @return void
*/
public function testStar(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'FavoriteExamples', 'action' => 'star']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

/**
* @uses \Sandbox\Controller\FavoriteExamplesController::like()
* @return void
*/
public function testLike(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'FavoriteExamples', 'action' => 'like']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

/**
* @uses \Sandbox\Controller\FavoriteExamplesController::favorite()
* @return void
*/
public function testFavorite(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'FavoriteExamples', 'action' => 'favorite']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

namespace Sandbox\Test\TestCase\Controller;

use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;

/**
* @uses \Sandbox\Controller\LocalizedController
*/
class LocalizedControllerTest extends TestCase {

use IntegrationTestTrait;

/**
* @uses \Sandbox\Controller\LocalizedController::index()
* @return void
*/
public function testIndex(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'Localized', 'action' => 'index']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

/**
* @uses \Sandbox\Controller\LocalizedController::basic()
* @return void
*/
public function testBasic(): void {
$this->disableErrorHandlerMiddleware();

$this->get(['plugin' => 'Sandbox', 'controller' => 'Localized', 'action' => 'basic']);

$this->assertResponseCode(200);
$this->assertNoRedirect();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class MenuControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'plugin.Sandbox.SandboxCategories',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class QueueExamplesControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'plugin.Queue.QueuedJobs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class SearchExamplesControllerTest extends IntegrationTestCase {

/**
* @var array
* @var array<string>
*/
protected array $fixtures = [
'plugin.Data.Countries',
Expand Down
Loading

0 comments on commit 6bf3a21

Please sign in to comment.