This commit is contained in:
Markus
2022-04-28 09:40:10 +02:00
commit 795794f992
9586 changed files with 1146991 additions and 0 deletions

View 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',
];
}

View 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);
}
}

View 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),
];
}
}

View 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 = '';
}

View 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',
];
}

View 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
{
}

View 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';
}

View 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 = '';
}

View 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';
}

View 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}]',
];
}

View 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!',
],
];
}

View 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;
}