Initial
61
tests/_support/Autoloader/FatalLocator.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Autoloader;
|
||||
|
||||
use CodeIgniter\Autoloader\FileLocator;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class FatalLocator
|
||||
*
|
||||
* A locator replacement designed to throw
|
||||
* exceptions when used to indicate when
|
||||
* a lookup actually happens.
|
||||
*/
|
||||
class FatalLocator extends FileLocator
|
||||
{
|
||||
/**
|
||||
* Throws.
|
||||
*
|
||||
* @param string $file The namespaced file to locate
|
||||
* @param string $folder The folder within the namespace that we should look for the file.
|
||||
* @param string $ext The file extension the file should have.
|
||||
*
|
||||
* @return false|string The path to the file, or false if not found.
|
||||
*/
|
||||
public function locateFile(string $file, ?string $folder = null, string $ext = 'php')
|
||||
{
|
||||
$folder = $folder ?? 'null';
|
||||
|
||||
throw new RuntimeException("locateFile({$file}, {$folder}, {$ext})");
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches through all of the defined namespaces looking for a file.
|
||||
* Returns an array of all found locations for the defined file.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $locator->search('Config/Routes.php');
|
||||
* // Assuming PSR4 namespaces include foo and bar, might return:
|
||||
* [
|
||||
* 'app/Modules/foo/Config/Routes.php',
|
||||
* 'app/Modules/bar/Config/Routes.php',
|
||||
* ]
|
||||
*/
|
||||
public function search(string $path, string $ext = 'php', bool $prioritizeApp = true): array
|
||||
{
|
||||
$prioritizeApp = $prioritizeApp ? 'true' : 'false';
|
||||
|
||||
throw new RuntimeException("search({$path}, {$ext}, {$prioritizeApp})");
|
||||
}
|
||||
}
|
||||
14
tests/_support/Autoloader/UnnamespacedClass.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class UnnamespacedClass
|
||||
{
|
||||
}
|
||||
21
tests/_support/Autoloader/functions.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (! function_exists('autoload_foo')) {
|
||||
function autoload_foo(): string
|
||||
{
|
||||
return 'I am autoloaded by Autoloader through $files!';
|
||||
}
|
||||
}
|
||||
|
||||
if (! defined('AUTOLOAD_CONSTANT')) {
|
||||
define('AUTOLOAD_CONSTANT', 'foo');
|
||||
}
|
||||
26
tests/_support/Cache/RestrictiveHandler.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Cache;
|
||||
|
||||
use CodeIgniter\Cache\Handlers\DummyHandler;
|
||||
|
||||
/**
|
||||
* Handler with unnecessarily restrictive
|
||||
* key limit for testing validateKey.
|
||||
*/
|
||||
class RestrictiveHandler extends DummyHandler
|
||||
{
|
||||
/**
|
||||
* Maximum key length.
|
||||
*/
|
||||
public const MAX_KEY_LENGTH = 10;
|
||||
}
|
||||
21
tests/_support/Commands/AbstractInfo.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
|
||||
abstract class AbstractInfo extends BaseCommand
|
||||
{
|
||||
protected $group = 'demo';
|
||||
protected $name = 'app:pablo';
|
||||
protected $description = 'Displays basic application information.';
|
||||
}
|
||||
44
tests/_support/Commands/AppInfo.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use CodeIgniter\CodeIgniter;
|
||||
use RuntimeException;
|
||||
|
||||
class AppInfo extends BaseCommand
|
||||
{
|
||||
protected $group = 'demo';
|
||||
protected $name = 'app:info';
|
||||
protected $arguments = ['draft' => 'unused'];
|
||||
protected $description = 'Displays basic application information.';
|
||||
|
||||
public function run(array $params)
|
||||
{
|
||||
CLI::write('CI Version: ' . CLI::color(CodeIgniter::CI_VERSION, 'red'));
|
||||
}
|
||||
|
||||
public function bomb()
|
||||
{
|
||||
try {
|
||||
CLI::color('test', 'white', 'Background');
|
||||
} catch (RuntimeException $oops) {
|
||||
$this->showError($oops);
|
||||
}
|
||||
}
|
||||
|
||||
public function helpme()
|
||||
{
|
||||
$this->call('help');
|
||||
}
|
||||
}
|
||||
11
tests/_support/Commands/Foobar.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Config\App;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
return [
|
||||
'foo' => 'The command will use this as foo.',
|
||||
'bar' => 'The command will use this as bar.',
|
||||
'baz' => 'The baz is here.',
|
||||
'bas' => CLI::color('bas', 'green') . (new App())->baseURL,
|
||||
];
|
||||
34
tests/_support/Commands/InvalidCommand.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use CodeIgniter\CodeIgniter;
|
||||
use ReflectionException;
|
||||
|
||||
class InvalidCommand extends BaseCommand
|
||||
{
|
||||
protected $group = 'demo';
|
||||
protected $name = 'app:invalid';
|
||||
protected $description = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
throw new ReflectionException();
|
||||
}
|
||||
|
||||
public function run(array $params)
|
||||
{
|
||||
CLI::write('CI Version: ' . CLI::color(CodeIgniter::CI_VERSION, 'red'));
|
||||
}
|
||||
}
|
||||
49
tests/_support/Commands/LanguageCommand.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\GeneratorTrait;
|
||||
|
||||
class LanguageCommand extends BaseCommand
|
||||
{
|
||||
use GeneratorTrait;
|
||||
|
||||
protected $group = 'Generators';
|
||||
protected $name = 'publish:language';
|
||||
protected $description = 'Publishes a language file.';
|
||||
protected $usage = 'publish:language [options]';
|
||||
protected $options = [
|
||||
'--lang' => 'The language folder to save the file.',
|
||||
'--sort' => 'Turn on/off the sortImports flag.',
|
||||
];
|
||||
|
||||
public function run(array $params)
|
||||
{
|
||||
$this->setHasClassName(false);
|
||||
$params[0] = 'Foobar';
|
||||
$params['lang'] = $params['lang'] ?? 'en';
|
||||
|
||||
$this->component = 'Language';
|
||||
$this->directory = 'Language\\' . $params['lang'];
|
||||
|
||||
$sort = (isset($params['sort']) && $params['sort'] === 'off') ? false : true;
|
||||
$this->setSortImports($sort);
|
||||
|
||||
$this->execute($params);
|
||||
}
|
||||
|
||||
protected function prepare(string $class): string
|
||||
{
|
||||
return file_get_contents(__DIR__ . '/Foobar.php') ?: '';
|
||||
}
|
||||
}
|
||||
28
tests/_support/Commands/ParamsReveal.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
|
||||
class ParamsReveal extends BaseCommand
|
||||
{
|
||||
protected $group = 'demo';
|
||||
protected $name = 'reveal';
|
||||
protected $usage = 'reveal [options] [arguments]';
|
||||
protected $description = 'Reveal params';
|
||||
public static $args;
|
||||
|
||||
public function run(array $params)
|
||||
{
|
||||
static::$args = $params;
|
||||
}
|
||||
}
|
||||
77
tests/_support/Commands/Unsuffixable.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\GeneratorTrait;
|
||||
|
||||
class Unsuffixable extends BaseCommand
|
||||
{
|
||||
use GeneratorTrait;
|
||||
|
||||
/**
|
||||
* The Command's Group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Generators';
|
||||
|
||||
/**
|
||||
* The Command's Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'make:foo';
|
||||
|
||||
/**
|
||||
* The Command's Description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '';
|
||||
|
||||
/**
|
||||
* The Command's Usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'make:foo [arguments] [options]';
|
||||
|
||||
/**
|
||||
* The Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'Class name',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* Actually execute a command.
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$this->component = 'Command';
|
||||
$this->directory = 'Commands';
|
||||
$this->template = 'command.tpl.php';
|
||||
|
||||
$this->setEnabledSuffixing(false);
|
||||
$this->execute($params);
|
||||
}
|
||||
}
|
||||
26
tests/_support/Config/BadRegistrar.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Config;
|
||||
|
||||
/**
|
||||
* Class BadRegistrar
|
||||
*
|
||||
* Doesn't provides a basic registrar class for testing BaseConfig registration functions,
|
||||
* because it doesn't return an associative array
|
||||
*/
|
||||
class BadRegistrar
|
||||
{
|
||||
public static function RegistrarConfig()
|
||||
{
|
||||
return 'I am not worthy';
|
||||
}
|
||||
}
|
||||
14
tests/_support/Config/Filters.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Config\Filters;
|
||||
|
||||
$filters->aliases['test-customfilter'] = \Tests\Support\Filters\Customfilter::class;
|
||||
138
tests/_support/Config/Registrar.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Config;
|
||||
|
||||
/**
|
||||
* Class Registrar
|
||||
*
|
||||
* Provides a basic registrar class for testing BaseConfig registration functions.
|
||||
*/
|
||||
class Registrar
|
||||
{
|
||||
/**
|
||||
* DB config array for testing purposes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $dbConfig = [
|
||||
'MySQLi' => [
|
||||
'DSN' => '',
|
||||
'hostname' => '127.0.0.1',
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => 'db_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8',
|
||||
'DBCollat' => 'utf8_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
],
|
||||
'Postgre' => [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'postgres',
|
||||
'password' => 'postgres',
|
||||
'database' => 'test',
|
||||
'DBDriver' => 'Postgre',
|
||||
'DBPrefix' => 'db_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8',
|
||||
'DBCollat' => 'utf8_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 5432,
|
||||
],
|
||||
'SQLite3' => [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'database.db',
|
||||
'DBDriver' => 'SQLite3',
|
||||
'DBPrefix' => 'db_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8',
|
||||
'DBCollat' => 'utf8_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
],
|
||||
'SQLSRV' => [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'sa',
|
||||
'password' => '1Secure*Password1',
|
||||
'database' => 'test',
|
||||
'DBDriver' => 'SQLSRV',
|
||||
'DBPrefix' => 'db_',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8',
|
||||
'DBCollat' => 'utf8_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 1433,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Override database config
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function Database()
|
||||
{
|
||||
$config = [];
|
||||
|
||||
// Under GitHub Actions, we can set an ENV var named 'DB'
|
||||
// so that we can test against multiple databases.
|
||||
if ($group = getenv('DB')) {
|
||||
if (! empty(self::$dbConfig[$group])) {
|
||||
$config['tests'] = self::$dbConfig[$group];
|
||||
}
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrates Publisher security.
|
||||
*
|
||||
* @see PublisherRestrictionsTest::testRegistrarsNotAllowed()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function Publisher()
|
||||
{
|
||||
return [
|
||||
'restrictions' => [SUPPORTPATH => '*'],
|
||||
];
|
||||
}
|
||||
}
|
||||
15
tests/_support/Config/Routes.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Config;
|
||||
|
||||
// This is a simple file to include for testing the RouteCollection class.
|
||||
$routes->add('testing', 'TestController::index', ['as' => 'testing-index']);
|
||||
46
tests/_support/Config/Services.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Config;
|
||||
|
||||
use CodeIgniter\HTTP\URI;
|
||||
use Config\Services as BaseServices;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Services Class
|
||||
*
|
||||
* Provides a replacement uri Service
|
||||
* to demonstrate overriding core services.
|
||||
*/
|
||||
class Services extends BaseServices
|
||||
{
|
||||
/**
|
||||
* The URI class provides a way to model and manipulate URIs.
|
||||
*
|
||||
* @param string $uri
|
||||
*
|
||||
* @return URI
|
||||
*/
|
||||
public static function uri(?string $uri = null, bool $getShared = true)
|
||||
{
|
||||
// Intercept our test case
|
||||
if ($uri === 'testCanReplaceFrameworkServices') {
|
||||
throw new RuntimeException('Service originated from ' . static::class);
|
||||
}
|
||||
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('uri', $uri);
|
||||
}
|
||||
|
||||
return new URI($uri);
|
||||
}
|
||||
}
|
||||
35
tests/_support/Config/TestRegistrar.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Config;
|
||||
|
||||
/**
|
||||
* Class Registrar
|
||||
*
|
||||
* Provides a basic registrar class for testing BaseConfig registration functions.
|
||||
*/
|
||||
class TestRegistrar
|
||||
{
|
||||
public static function RegistrarConfig()
|
||||
{
|
||||
return [
|
||||
'bar' => [
|
||||
'first',
|
||||
'second',
|
||||
],
|
||||
'format' => 'nice',
|
||||
'fruit' => [
|
||||
'apple',
|
||||
'banana',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
22
tests/_support/Controllers/Hello.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class Hello extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return 'Hello';
|
||||
}
|
||||
}
|
||||
92
tests/_support/Controllers/Popcorn.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* This is a testing only controller, intended to blow up in multiple
|
||||
* ways to make sure we catch them.
|
||||
*/
|
||||
class Popcorn extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
public function index()
|
||||
{
|
||||
return 'Hi there';
|
||||
}
|
||||
|
||||
public function pop()
|
||||
{
|
||||
$this->respond('Oops', 567, 'Surprise');
|
||||
}
|
||||
|
||||
public function popper()
|
||||
{
|
||||
throw new RuntimeException('Surprise', 500);
|
||||
}
|
||||
|
||||
public function weasel()
|
||||
{
|
||||
$this->respond('', 200);
|
||||
}
|
||||
|
||||
public function oops()
|
||||
{
|
||||
$this->failUnauthorized();
|
||||
}
|
||||
|
||||
public function goaway()
|
||||
{
|
||||
return redirect()->to('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1834
|
||||
*/
|
||||
public function index3()
|
||||
{
|
||||
return $this->response->setJSON(['lang' => $this->request->getLocale()]);
|
||||
}
|
||||
|
||||
public function canyon()
|
||||
{
|
||||
echo 'Hello-o-o ' . $this->request->getGet('foo');
|
||||
}
|
||||
|
||||
public function cat()
|
||||
{
|
||||
}
|
||||
|
||||
public function json()
|
||||
{
|
||||
$this->respond(['answer' => 42]);
|
||||
}
|
||||
|
||||
public function xml()
|
||||
{
|
||||
$this->respond('<my><pet>cat</pet></my>');
|
||||
}
|
||||
|
||||
public function toindex()
|
||||
{
|
||||
return redirect()->route('testing-index');
|
||||
}
|
||||
|
||||
public function echoJson()
|
||||
{
|
||||
return $this->response->setJSON($this->request->getJSON());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class Migration_Create_test_tables extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// User Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 80],
|
||||
'email' => ['type' => 'VARCHAR', 'constraint' => 100],
|
||||
'country' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
])->addKey('id', true)->createTable('user', true);
|
||||
|
||||
// Job Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'description' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
'created_at' => ['type' => 'INTEGER', 'constraint' => 11, 'null' => true],
|
||||
'updated_at' => ['type' => 'INTEGER', 'constraint' => 11, 'null' => true],
|
||||
'deleted_at' => ['type' => 'INTEGER', 'constraint' => 11, 'null' => true],
|
||||
])->addKey('id', true)->createTable('job', true);
|
||||
|
||||
// Misc Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'key' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('id', true)->createTable('misc', true);
|
||||
|
||||
// Database Type test table
|
||||
// missing types :
|
||||
// TINYINT,MEDIUMINT,BIT,YEAR,BINARY , VARBINARY, TINYTEXT,LONGTEXT,YEAR,JSON,Spatial data types
|
||||
// id must be interger else SQLite3 error on not null for autoinc field
|
||||
$data_type_fields = [
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 20, 'auto_increment' => true],
|
||||
'type_varchar' => ['type' => 'VARCHAR', 'constraint' => 40, 'null' => true],
|
||||
'type_char' => ['type' => 'CHAR', 'constraint' => 10, 'null' => true],
|
||||
'type_text' => ['type' => 'TEXT', 'null' => true],
|
||||
'type_smallint' => ['type' => 'SMALLINT', 'null' => true],
|
||||
'type_integer' => ['type' => 'INTEGER', 'null' => true],
|
||||
'type_float' => ['type' => 'FLOAT', 'null' => true],
|
||||
'type_numeric' => ['type' => 'NUMERIC', 'constraint' => '18,2', 'null' => true],
|
||||
'type_date' => ['type' => 'DATE', 'null' => true],
|
||||
'type_time' => ['type' => 'TIME', 'null' => true],
|
||||
'type_datetime' => ['type' => 'DATETIME', 'null' => true],
|
||||
'type_timestamp' => ['type' => 'TIMESTAMP', 'null' => true],
|
||||
'type_bigint' => ['type' => 'BIGINT', 'null' => true],
|
||||
'type_real' => ['type' => 'REAL', 'null' => true],
|
||||
'type_enum' => ['type' => 'ENUM', 'constraint' => ['appel', 'pears'], 'null' => true],
|
||||
'type_set' => ['type' => 'SET', 'constraint' => ['one', 'two'], 'null' => true],
|
||||
'type_mediumtext' => ['type' => 'MEDIUMTEXT', 'null' => true],
|
||||
'type_double' => ['type' => 'DOUBLE', 'null' => true],
|
||||
'type_decimal' => ['type' => 'DECIMAL', 'constraint' => '18,4', 'null' => true],
|
||||
'type_blob' => ['type' => 'BLOB', 'null' => true],
|
||||
'type_boolean' => ['type' => 'BOOLEAN', 'null' => true],
|
||||
];
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre') {
|
||||
unset(
|
||||
$data_type_fields['type_real'],
|
||||
$data_type_fields['type_decimal']
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'SQLSRV') {
|
||||
unset($data_type_fields['type_timestamp']);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre' || $this->db->DBDriver === 'SQLSRV') {
|
||||
unset(
|
||||
$data_type_fields['type_enum'],
|
||||
$data_type_fields['type_set'],
|
||||
$data_type_fields['type_mediumtext'],
|
||||
$data_type_fields['type_double'],
|
||||
$data_type_fields['type_blob']
|
||||
);
|
||||
}
|
||||
|
||||
$this->forge->addField($data_type_fields)->addKey('id', true)->createTable('type_test', true);
|
||||
|
||||
// Empty Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'created_at' => ['type' => 'DATE', 'null' => true],
|
||||
'updated_at' => ['type' => 'DATE', 'null' => true],
|
||||
])->addKey('id', true)->createTable('empty', true);
|
||||
|
||||
// Secondary Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'key' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('id', true)->createTable('secondary', true);
|
||||
|
||||
// Stringify Primary key Table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'VARCHAR', 'constraint' => 3],
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('id', true)->createTable('stringifypkey', true);
|
||||
|
||||
// Table without auto increment field
|
||||
$this->forge->addField([
|
||||
'key' => ['type' => 'VARCHAR', 'constraint' => 40, 'unique' => true],
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('key', true)->createTable('without_auto_increment', true);
|
||||
|
||||
// IP Table
|
||||
$this->forge->addField([
|
||||
'ip' => ['type' => 'VARCHAR', 'constraint' => 100],
|
||||
'ip2' => ['type' => 'VARCHAR', 'constraint' => 100],
|
||||
])->createTable('ip_table', true);
|
||||
|
||||
// Database session table
|
||||
if ($this->db->DBDriver === 'MySQLi') {
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'VARCHAR', 'constraint' => 128, 'null' => false],
|
||||
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => false],
|
||||
'timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL',
|
||||
'data' => ['type' => 'BLOB', 'null' => false],
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->createTable('ci_sessions', true);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre') {
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'VARCHAR', 'constraint' => 128, 'null' => false],
|
||||
'ip_address inet NOT NULL',
|
||||
'timestamp timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL',
|
||||
"data bytea DEFAULT '' NOT NULL",
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->createTable('ci_sessions', true);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('user', true);
|
||||
$this->forge->dropTable('job', true);
|
||||
$this->forge->dropTable('misc', true);
|
||||
$this->forge->dropTable('type_test', true);
|
||||
$this->forge->dropTable('empty', true);
|
||||
$this->forge->dropTable('secondary', true);
|
||||
$this->forge->dropTable('stringifypkey', true);
|
||||
$this->forge->dropTable('without_auto_increment', true);
|
||||
$this->forge->dropTable('ip_table', true);
|
||||
|
||||
if (in_array($this->db->DBDriver, ['MySQLi', 'Postgre'], true)) {
|
||||
$this->forge->dropTable('ci_sessions', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
tests/_support/Database/Seeds/AnotherSeeder.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Database\Seeds;
|
||||
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
class AnotherSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$row = [
|
||||
'name' => 'Jerome Lohan',
|
||||
'email' => 'jlo@lohanenterprises.com',
|
||||
'country' => 'UK',
|
||||
];
|
||||
|
||||
$this->db->table('user')->insert($row);
|
||||
}
|
||||
}
|
||||
177
tests/_support/Database/Seeds/CITestSeeder.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Database\Seeds;
|
||||
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
class CITestSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
// Job Data
|
||||
$data = [
|
||||
'user' => [
|
||||
[
|
||||
'name' => 'Derek Jones',
|
||||
'email' => 'derek@world.com',
|
||||
'country' => 'US',
|
||||
],
|
||||
[
|
||||
'name' => 'Ahmadinejad',
|
||||
'email' => 'ahmadinejad@world.com',
|
||||
'country' => 'Iran',
|
||||
],
|
||||
[
|
||||
'name' => 'Richard A Causey',
|
||||
'email' => 'richard@world.com',
|
||||
'country' => 'US',
|
||||
],
|
||||
[
|
||||
'name' => 'Chris Martin',
|
||||
'email' => 'chris@world.com',
|
||||
'country' => 'UK',
|
||||
],
|
||||
],
|
||||
'job' => [
|
||||
[
|
||||
'name' => 'Developer',
|
||||
'description' => 'Awesome job, but sometimes makes you bored',
|
||||
],
|
||||
[
|
||||
'name' => 'Politician',
|
||||
'description' => 'This is not really a job',
|
||||
],
|
||||
[
|
||||
'name' => 'Accountant',
|
||||
'description' => 'Boring job, but you will get free snack at lunch',
|
||||
],
|
||||
[
|
||||
'name' => 'Musician',
|
||||
'description' => 'Only Coldplay can actually called Musician',
|
||||
],
|
||||
],
|
||||
'misc' => [
|
||||
[
|
||||
'key' => '\\xxxfoo456',
|
||||
'value' => 'Entry with \\xxx',
|
||||
],
|
||||
[
|
||||
'key' => '\\%foo456',
|
||||
'value' => 'Entry with \\%',
|
||||
],
|
||||
[
|
||||
'key' => 'spaces and tabs',
|
||||
'value' => ' One two three tab',
|
||||
],
|
||||
],
|
||||
'stringifypkey' => [
|
||||
[
|
||||
'id' => 'A01',
|
||||
'value' => 'test',
|
||||
],
|
||||
],
|
||||
'without_auto_increment' => [
|
||||
[
|
||||
'key' => 'key',
|
||||
'value' => 'value',
|
||||
],
|
||||
],
|
||||
'type_test' => [
|
||||
[
|
||||
'type_varchar' => 'test',
|
||||
'type_char' => 'test',
|
||||
'type_enum' => 'appel',
|
||||
'type_set' => 'one',
|
||||
'type_text' => 'test text',
|
||||
'type_mediumtext' => 'test medium text',
|
||||
'type_smallint' => 1,
|
||||
'type_integer' => 123,
|
||||
'type_float' => 10.1,
|
||||
'type_real' => 11.21,
|
||||
'type_double' => 23.22,
|
||||
'type_decimal' => 123123.2234,
|
||||
'type_numeric' => 123.23,
|
||||
'type_blob' => 'test blob',
|
||||
'type_date' => '2020-01-11T22:11:00.000+02:00',
|
||||
'type_time' => '2020-07-18T15:22:00.000+02:00',
|
||||
'type_datetime' => '2020-06-18T05:12:24.000+02:00',
|
||||
'type_timestamp' => '2019-07-18T21:53:21.000+02:00',
|
||||
'type_bigint' => 2342342,
|
||||
'type_boolean' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// set SQL times to more correct format
|
||||
if ($this->db->DBDriver === 'SQLite3') {
|
||||
$data['type_test'][0]['type_date'] = '2020/01/11';
|
||||
$data['type_test'][0]['type_time'] = '15:22:00';
|
||||
$data['type_test'][0]['type_datetime'] = '2020/06/18 05:12:24';
|
||||
$data['type_test'][0]['type_timestamp'] = '2019/07/18 21:53:21';
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre') {
|
||||
$data['type_test'][0]['type_time'] = '15:22:00';
|
||||
$data['type_test'][0]['type_boolean'] = true;
|
||||
unset(
|
||||
$data['type_test'][0]['type_enum'],
|
||||
$data['type_test'][0]['type_set'],
|
||||
$data['type_test'][0]['type_mediumtext'],
|
||||
$data['type_test'][0]['type_real'],
|
||||
$data['type_test'][0]['type_double'],
|
||||
$data['type_test'][0]['type_decimal'],
|
||||
$data['type_test'][0]['type_blob']
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'SQLSRV') {
|
||||
$data['type_test'][0]['type_date'] = '2020-01-11';
|
||||
$data['type_test'][0]['type_time'] = '15:22:00.000';
|
||||
$data['type_test'][0]['type_datetime'] = '2020-06-18 05:12:24.000';
|
||||
|
||||
unset(
|
||||
$data['type_test'][0]['type_timestamp'],
|
||||
$data['type_test'][0]['type_enum'],
|
||||
$data['type_test'][0]['type_set'],
|
||||
$data['type_test'][0]['type_mediumtext'],
|
||||
$data['type_test'][0]['type_double'],
|
||||
$data['type_test'][0]['type_blob']
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'MySQLi') {
|
||||
$data['ci_sessions'][] = [
|
||||
'id' => '1f5o06b43phsnnf8if6bo33b635e4p2o',
|
||||
'ip_address' => '127.0.0.1',
|
||||
'timestamp' => '2021-06-25 21:54:14',
|
||||
'data' => '__ci_last_regenerate|i:1624650854;_ci_previous_url|s:40:\"http://localhost/index.php/home/index\";',
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->db->DBDriver === 'Postgre') {
|
||||
$data['ci_sessions'][] = [
|
||||
'id' => '1f5o06b43phsnnf8if6bo33b635e4p2o',
|
||||
'ip_address' => '127.0.0.1',
|
||||
'timestamp' => '2021-06-25 21:54:14.991403+02',
|
||||
'data' => '\x' . bin2hex('__ci_last_regenerate|i:1624650854;_ci_previous_url|s:40:\"http://localhost/index.php/home/index\";'),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($data as $table => $dummy_data) {
|
||||
$this->db->table($table)->truncate();
|
||||
|
||||
foreach ($dummy_data as $single_dummy_data) {
|
||||
$this->db->table($table)->insert($single_dummy_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
43
tests/_support/Entity/Cast/CastBase64.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Entity\Cast;
|
||||
|
||||
use CodeIgniter\Entity\Cast\BaseCast;
|
||||
|
||||
class CastBase64 extends BaseCast
|
||||
{
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @param mixed $value Data
|
||||
* @param array $params Additional param
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($value, array $params = []): string
|
||||
{
|
||||
return base64_decode($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set
|
||||
*
|
||||
* @param mixed $value Data
|
||||
* @param array $params Additional param
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function set($value, array $params = []): string
|
||||
{
|
||||
return base64_encode($value);
|
||||
}
|
||||
}
|
||||
30
tests/_support/Entity/Cast/CastPassParameters.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Entity\Cast;
|
||||
|
||||
use CodeIgniter\Entity\Cast\BaseCast;
|
||||
|
||||
class CastPassParameters extends BaseCast
|
||||
{
|
||||
/**
|
||||
* Set
|
||||
*
|
||||
* @param mixed $value Data
|
||||
* @param array $params Additional param
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function set($value, array $params = [])
|
||||
{
|
||||
return $value . ':' . json_encode($params);
|
||||
}
|
||||
}
|
||||
16
tests/_support/Entity/Cast/NotExtendsBaseCast.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Entity\Cast;
|
||||
|
||||
class NotExtendsBaseCast
|
||||
{
|
||||
}
|
||||
21
tests/_support/Entity/User.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Entity;
|
||||
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class User extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
'country' => 'India',
|
||||
];
|
||||
}
|
||||
10
tests/_support/Files/able/apple.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
10
tests/_support/Files/able/fig_3.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
10
tests/_support/Files/able/prune_ripe.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
10
tests/_support/Files/baker/banana.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
29
tests/_support/Filters/Customfilter.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Filters;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class Customfilter implements \CodeIgniter\Filters\FilterInterface
|
||||
{
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
$request->url = 'http://hellowworld.com';
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
1
tests/_support/HTTP/Files/CookiesHolder.txt
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
1
tests/_support/HTTP/Files/tmp/fileA.txt
Normal file
@@ -0,0 +1 @@
|
||||
text
|
||||
1
tests/_support/HTTP/Files/tmp/fileB.txt
Normal file
@@ -0,0 +1 @@
|
||||
more text
|
||||
1
tests/_support/HTTP/Files/tmp/fileC.csv
Normal file
@@ -0,0 +1 @@
|
||||
separated;"text"
|
||||
|
BIN
tests/_support/HTTP/Files/tmp/fileD.zip
Normal file
BIN
tests/_support/HTTP/Files/tmp/fileE.zip.rar
Normal file
10
tests/_support/Helpers/baguette_helper.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
BIN
tests/_support/Images/EXIFsamples/landscape_0.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/landscape_1.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/landscape_2.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/landscape_3.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/landscape_4.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/landscape_5.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/landscape_6.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/landscape_7.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/landscape_8.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_0.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_1.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_2.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_3.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_4.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_5.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_6.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_7.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/EXIFsamples/portrait_8.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tests/_support/Images/Steveston_dusk.JPG
Normal file
|
After Width: | Height: | Size: 119 KiB |
BIN
tests/_support/Images/ci-logo.gif
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
tests/_support/Images/ci-logo.jpeg
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
tests/_support/Images/ci-logo.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
tests/_support/Images/ci-logo.webp
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
33
tests/_support/Language/SecondMockLanguage.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Language;
|
||||
|
||||
use CodeIgniter\Language\Language;
|
||||
|
||||
class SecondMockLanguage extends Language
|
||||
{
|
||||
/**
|
||||
* Expose the protected *load* method
|
||||
*/
|
||||
public function loadem(string $file, string $locale = 'en', bool $return = false)
|
||||
{
|
||||
return $this->load($file, $locale, $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose the loaded language files
|
||||
*/
|
||||
public function loaded(string $locale = 'en')
|
||||
{
|
||||
return $this->loadedFiles[$locale];
|
||||
}
|
||||
}
|
||||
17
tests/_support/Language/ab-CD/Allin.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'one' => 'Pyramid of Giza',
|
||||
'tre' => 'Colossus of Rhodes',
|
||||
'fiv' => 'Temple of Artemis',
|
||||
'sev' => 'Hanging Gardens of Babylon',
|
||||
];
|
||||
17
tests/_support/Language/ab/Allin.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'two' => 'gluttony',
|
||||
'tre' => 'greed',
|
||||
'six' => 'envy',
|
||||
'sev' => 'pride',
|
||||
];
|
||||
16
tests/_support/Language/en-ZZ/More.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'strongForce' => 'These are not the droids you are looking for',
|
||||
'notaMoon' => "It's made of cheese",
|
||||
'wisdom' => 'There is no try',
|
||||
];
|
||||
17
tests/_support/Language/en/Allin.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'for' => 'four calling birds',
|
||||
'fiv' => 'five golden rings',
|
||||
'six' => 'six geese a laying',
|
||||
'sev' => 'seven swans a swimming',
|
||||
];
|
||||
15
tests/_support/Language/en/Core.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'missingExtension' => '{0} extension could not be found.',
|
||||
'bazillion' => 'billions and billions', // adds a new setting
|
||||
];
|
||||
19
tests/_support/Language/en/Foo.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'bar' => 'Foo Bar Translated',
|
||||
'bar.min_length1' => 'The {field} field is very short.',
|
||||
'bar.min_length2' => 'Supplied value ({value}) for {field} must have at least {param} characters.',
|
||||
'baz' => [
|
||||
'min_length3.short' => 'The {field} field is very short.',
|
||||
],
|
||||
];
|
||||
15
tests/_support/Language/en/Language.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
// Language system language settings
|
||||
return [
|
||||
'languageGetLineInvalidArgumentException' => 'Get line must be a string or array of strings.',
|
||||
];
|
||||
16
tests/_support/Language/en/More.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'strongForce' => 'These are not the droids you are looking for',
|
||||
'notaMoon' => "That's no moon... it's a space station",
|
||||
'cannotMove' => 'I have a very bad feeling about this',
|
||||
];
|
||||
20
tests/_support/Language/en/Nested.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'a' => [
|
||||
'b' => [
|
||||
'c' => [
|
||||
'd' => 'e',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
14
tests/_support/Language/ru/Language.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
'languageGetLineInvalidArgumentException' => 'Whatever this would be, translated',
|
||||
];
|
||||
63
tests/_support/Log/Handlers/TestHandler.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Log\Handlers;
|
||||
|
||||
/**
|
||||
* Class TestHandler
|
||||
*
|
||||
* A simple LogHandler that stores the logs in memory.
|
||||
* Only used for testing purposes.
|
||||
*/
|
||||
class TestHandler extends \CodeIgniter\Log\Handlers\FileHandler
|
||||
{
|
||||
/**
|
||||
* Local storage for logs.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $logs = [];
|
||||
|
||||
/**
|
||||
* Where would the log be written?
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
$this->handles = $config['handles'] ?? [];
|
||||
$this->destination = $this->path . 'log-' . date('Y-m-d') . '.' . $this->fileExtension;
|
||||
|
||||
self::$logs = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles logging the message.
|
||||
* If the handler returns false, then execution of handlers
|
||||
* will stop. Any handlers that have not run, yet, will not
|
||||
* be run.
|
||||
*
|
||||
* @param $level
|
||||
* @param $message
|
||||
*/
|
||||
public function handle($level, $message): bool
|
||||
{
|
||||
$date = date($this->dateFormat);
|
||||
|
||||
self::$logs[] = strtoupper($level) . ' - ' . $date . ' --> ' . $message;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getLogs()
|
||||
{
|
||||
return self::$logs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php namespace Tests\Support\MigrationTestMigrations\Database\Migrations;
|
||||
|
||||
class Migration_another_migration extends \CodeIgniter\Database\Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->forge->addField([
|
||||
'key' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 255,
|
||||
],
|
||||
]);
|
||||
$this->forge->createTable('foo', true);
|
||||
|
||||
$this->db->table('foo')->insert([
|
||||
'key' => 'foobar',
|
||||
]);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('foo', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\MigrationTestMigrations\Database\Migrations;
|
||||
|
||||
class Migration_some_migration extends \CodeIgniter\Database\Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->forge->addField([
|
||||
'key' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 255,
|
||||
],
|
||||
]);
|
||||
$this->forge->createTable('foo', true);
|
||||
|
||||
$this->db->table('foo')->insert([
|
||||
'key' => 'foobar',
|
||||
]);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('foo', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\MigrationTestMigrations\Database\Migrations;
|
||||
|
||||
class Migration_another_migration extends \CodeIgniter\Database\Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$fields = [
|
||||
'value' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 255,
|
||||
],
|
||||
];
|
||||
$this->forge->addColumn('foo', $fields);
|
||||
|
||||
$this->db->table('foo')->insert([
|
||||
'key' => 'foobar',
|
||||
'value' => 'raboof',
|
||||
]);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
if ($this->db->tableExists('foo')) {
|
||||
$this->forge->dropColumn('foo', 'value');
|
||||
}
|
||||
}
|
||||
}
|
||||
28
tests/_support/Models/EntityModel.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class EntityModel extends Model
|
||||
{
|
||||
protected $table = 'job';
|
||||
protected $returnType = '\Tests\Support\Models\SimpleEntity';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $dateFormat = 'int';
|
||||
protected $deletedField = 'deleted_at';
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'description',
|
||||
'created_at',
|
||||
];
|
||||
}
|
||||
119
tests/_support/Models/EventModel.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class EventModel extends Model
|
||||
{
|
||||
protected $table = 'user';
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'email',
|
||||
'country',
|
||||
'deleted_at',
|
||||
];
|
||||
protected $beforeInsert = ['beforeInsertMethod'];
|
||||
protected $afterInsert = ['afterInsertMethod'];
|
||||
protected $beforeUpdate = ['beforeUpdateMethod'];
|
||||
protected $afterUpdate = ['afterUpdateMethod'];
|
||||
protected $beforeDelete = ['beforeDeleteMethod'];
|
||||
protected $afterDelete = ['afterDeleteMethod'];
|
||||
protected $beforeFind = ['beforeFindMethod'];
|
||||
protected $afterFind = ['afterFindMethod'];
|
||||
|
||||
// Cache of the most recent eventData from a trigger
|
||||
public $eventData;
|
||||
|
||||
// Testing directive to set $returnData on beforeFind event
|
||||
public $beforeFindReturnData = false;
|
||||
|
||||
// Holds stuff for testing events
|
||||
protected $tokens = [];
|
||||
|
||||
protected function beforeInsertMethod(array $data)
|
||||
{
|
||||
$this->tokens[] = 'beforeInsert';
|
||||
$this->eventData = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterInsertMethod(array $data)
|
||||
{
|
||||
$this->tokens[] = 'afterInsert';
|
||||
$this->eventData = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function beforeUpdateMethod(array $data)
|
||||
{
|
||||
$this->tokens[] = 'beforeUpdate';
|
||||
$this->eventData = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterUpdateMethod(array $data)
|
||||
{
|
||||
$this->tokens[] = 'afterUpdate';
|
||||
$this->eventData = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function beforeDeleteMethod(array $data)
|
||||
{
|
||||
$this->tokens[] = 'beforeDelete';
|
||||
$this->eventData = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterDeleteMethod(array $data)
|
||||
{
|
||||
$this->tokens[] = 'afterDelete';
|
||||
$this->eventData = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function beforeFindMethod(array $data)
|
||||
{
|
||||
$this->tokens[] = 'beforeFind';
|
||||
$this->eventData = $data;
|
||||
|
||||
if ($this->beforeFindReturnData) {
|
||||
$data['data'] = 'foobar';
|
||||
$data['returnData'] = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterFindMethod(array $data)
|
||||
{
|
||||
$this->tokens[] = 'afterFind';
|
||||
$this->eventData = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function hasToken(string $token)
|
||||
{
|
||||
return in_array($token, $this->tokens, true);
|
||||
}
|
||||
}
|
||||
37
tests/_support/Models/FabricatorModel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
use Faker\Generator;
|
||||
|
||||
class FabricatorModel extends Model
|
||||
{
|
||||
protected $table = 'job';
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = true;
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'int';
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
// Return a faked entity
|
||||
public function fake(Generator &$faker)
|
||||
{
|
||||
return (object) [
|
||||
'name' => $faker->ipv4,
|
||||
'description' => $faker->words(10),
|
||||
];
|
||||
}
|
||||
}
|
||||
28
tests/_support/Models/JobModel.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class JobModel extends Model
|
||||
{
|
||||
protected $table = 'job';
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $dateFormat = 'int';
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
public $name = '';
|
||||
public $description = '';
|
||||
}
|
||||
27
tests/_support/Models/SecondaryModel.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class SecondaryModel extends Model
|
||||
{
|
||||
protected $table = 'secondary';
|
||||
protected $primaryKey = 'id';
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $dateFormat = 'int';
|
||||
protected $allowedFields = [
|
||||
'key',
|
||||
'value',
|
||||
];
|
||||
}
|
||||
24
tests/_support/Models/SimpleEntity.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
/**
|
||||
* Class SimpleEntity
|
||||
*
|
||||
* Simple Entity-type class for testing creating and saving entities
|
||||
* in the model so we can support Entity/Repository type patterns.
|
||||
*/
|
||||
class SimpleEntity extends Entity
|
||||
{
|
||||
}
|
||||
20
tests/_support/Models/StringifyPkeyModel.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class StringifyPkeyModel extends Model
|
||||
{
|
||||
protected $table = 'stringifypkey';
|
||||
protected $returnType = 'object';
|
||||
}
|
||||
31
tests/_support/Models/UserModel.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class UserModel extends Model
|
||||
{
|
||||
protected $table = 'user';
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'email',
|
||||
'country',
|
||||
'deleted_at',
|
||||
];
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
public $name = '';
|
||||
public $email = '';
|
||||
public $country = '';
|
||||
}
|
||||
28
tests/_support/Models/UserObjModel.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class UserObjModel extends Model
|
||||
{
|
||||
protected $table = 'user';
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'email',
|
||||
'country',
|
||||
'deleted_at',
|
||||
];
|
||||
protected $returnType = \Tests\Support\Entity\User::class;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
}
|
||||
36
tests/_support/Models/ValidErrorsModel.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ValidErrorsModel extends Model
|
||||
{
|
||||
protected $table = 'job';
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $dateFormat = 'int';
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
protected $validationRules = [
|
||||
'name' => [
|
||||
'required',
|
||||
'min_length[10]',
|
||||
'errors' => [
|
||||
'min_length' => 'Minimum Length Error',
|
||||
],
|
||||
],
|
||||
'token' => 'in_list[{id}]',
|
||||
];
|
||||
}
|
||||
39
tests/_support/Models/ValidModel.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ValidModel extends Model
|
||||
{
|
||||
protected $table = 'job';
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $dateFormat = 'int';
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
protected $validationRules = [
|
||||
'name' => [
|
||||
'required',
|
||||
'min_length[3]',
|
||||
],
|
||||
'token' => 'permit_empty|in_list[{id}]',
|
||||
];
|
||||
protected $validationMessages = [
|
||||
'name' => [
|
||||
'required' => 'You forgot to name the baby.',
|
||||
'min_length' => 'Too short, man!',
|
||||
],
|
||||
];
|
||||
}
|
||||
25
tests/_support/Models/WithoutAutoIncrementModel.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class WithoutAutoIncrementModel extends Model
|
||||
{
|
||||
protected $table = 'without_auto_increment';
|
||||
protected $primaryKey = 'key';
|
||||
protected $allowedFields = [
|
||||
'key',
|
||||
'value',
|
||||
];
|
||||
protected $useAutoIncrement = false;
|
||||
}
|
||||
56
tests/_support/Publishers/TestPublisher.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Publishers;
|
||||
|
||||
use CodeIgniter\Publisher\Publisher;
|
||||
|
||||
final class TestPublisher extends Publisher
|
||||
{
|
||||
/**
|
||||
* Return value for publish()
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $result = true;
|
||||
|
||||
/**
|
||||
* Base path to use for the source.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $source = SUPPORTPATH . 'Files';
|
||||
|
||||
/**
|
||||
* Base path to use for the destination.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $destination = WRITEPATH;
|
||||
|
||||
/**
|
||||
* Fakes an error on the given file.
|
||||
*/
|
||||
public static function setResult(bool $result)
|
||||
{
|
||||
self::$result = $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fakes a publish event so no files are actually copied.
|
||||
*/
|
||||
public function publish(): bool
|
||||
{
|
||||
$this->addPath('');
|
||||
|
||||
return self::$result;
|
||||
}
|
||||
}
|
||||
21
tests/_support/RESTful/Worker.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\RESTful;
|
||||
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
|
||||
/**
|
||||
* An extendable controller to provide a RESTful API for a resource.
|
||||
*/
|
||||
class Worker extends ResourceController
|
||||
{
|
||||
}
|
||||
21
tests/_support/RESTful/Worker2.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\RESTful;
|
||||
|
||||
use CodeIgniter\RESTful\ResourcePresenter;
|
||||
|
||||
/**
|
||||
* An extendable controller to provide a RESTful API for a resource.
|
||||
*/
|
||||
class Worker2 extends ResourcePresenter
|
||||
{
|
||||
}
|
||||
66
tests/_support/Services.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter;
|
||||
|
||||
use CIUnitTestCase;
|
||||
use Config\Services as ConfigServices;
|
||||
|
||||
/**
|
||||
* Services class for testing.
|
||||
*/
|
||||
class Services
|
||||
{
|
||||
/**
|
||||
* Mock objects for testing which are returned if exist.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $mocks = [];
|
||||
|
||||
/**
|
||||
* Reset shared instances and mocks for testing.
|
||||
*/
|
||||
public static function reset()
|
||||
{
|
||||
static::$mocks = [];
|
||||
|
||||
CIUnitTestCase::setPrivateProperty(ConfigServices::class, 'instances', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject mock object for testing.
|
||||
*
|
||||
* @param $mock
|
||||
*/
|
||||
public static function injectMock(string $name, $mock)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
static::$mocks[$name] = $mock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a service
|
||||
*/
|
||||
public static function __callStatic(string $name, array $arguments)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
|
||||
// Returns mock if exists
|
||||
if (isset(static::$mocks[$name])) {
|
||||
return static::$mocks[$name];
|
||||
}
|
||||
|
||||
if (method_exists(ConfigServices::class, $name)) {
|
||||
return ConfigServices::$name(...$arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
tests/_support/SomeEntity.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class SomeEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
'foo' => null,
|
||||
'bar' => null,
|
||||
];
|
||||
}
|
||||
35
tests/_support/Validation/TestRules.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\Validation;
|
||||
|
||||
class TestRules
|
||||
{
|
||||
public function customError(string $str, ?string &$error = null)
|
||||
{
|
||||
$error = 'My lovely error';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function check_object_rule(object $value, ?string $fields, array $data = [])
|
||||
{
|
||||
$find = false;
|
||||
|
||||
foreach ($value as $key => $val) {
|
||||
if ($key === 'first') {
|
||||
$find = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $find;
|
||||
}
|
||||
}
|
||||
BIN
tests/_support/Validation/uploads/phpUxc0ty
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
54
tests/_support/View/SampleClass.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\View;
|
||||
|
||||
/**
|
||||
* Class SampleClass
|
||||
*
|
||||
* This class is only used to provide a reference point
|
||||
* during tests to make sure that things work as expected.
|
||||
*/
|
||||
class SampleClass
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return 'Hello World';
|
||||
}
|
||||
|
||||
public function hello()
|
||||
{
|
||||
return 'Hello';
|
||||
}
|
||||
|
||||
public function echobox($params)
|
||||
{
|
||||
if (is_array($params)) {
|
||||
$params = implode(',', $params);
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
public static function staticEcho($params)
|
||||
{
|
||||
if (is_array($params)) {
|
||||
$params = implode(',', $params);
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function work($p1, $p2, $p4)
|
||||
{
|
||||
return 'Right on';
|
||||
}
|
||||
}
|
||||
35
tests/_support/View/SampleClassWithInitController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tests\Support\View;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Class SampleClassWithInitController
|
||||
*
|
||||
* This class is only used to provide a reference point
|
||||
* during tests to make sure that things work as expected.
|
||||
*/
|
||||
class SampleClassWithInitController
|
||||
{
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return get_class($this->response);
|
||||
}
|
||||
}
|
||||
1
tests/_support/View/Views/simple.php
Normal file
@@ -0,0 +1 @@
|
||||
<h1><?= $testString ?></h1>
|
||||
1
tests/_support/View/Views/simpler.php
Normal file
@@ -0,0 +1 @@
|
||||
<h1>{testString}</h1>
|
||||
1
tests/_support/View/Views/simples.php
Normal file
@@ -0,0 +1 @@
|
||||
<h1><?= $testString ?? 'is_not' ?></h1>
|
||||