More tests.
This commit is contained in:
parent
191ceaa4e9
commit
57a5b0c2c0
6 changed files with 232 additions and 21 deletions
|
@ -53,6 +53,7 @@ function setUpConfig($config)
|
|||
}
|
||||
|
||||
`mysql -e 'TRUNCATE TABLE test.pickles;'`;
|
||||
`mysql -e 'TRUNCATE TABLE test.users;'`;
|
||||
`echo 'flush_all' | nc localhost 11211`;
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,6 +6,12 @@ class MockModelWithoutColumns extends Model
|
|||
protected $columns = false;
|
||||
}
|
||||
|
||||
class MockOtherModel extends Model
|
||||
{
|
||||
protected $table = 'brines';
|
||||
protected $columns = false;
|
||||
}
|
||||
|
||||
class MockModel extends Model
|
||||
{
|
||||
protected $table = 'pickles';
|
||||
|
@ -101,12 +107,16 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(3, $model->count());
|
||||
}
|
||||
|
||||
/*
|
||||
@todo Acting wonky, passes tests on just this class, fails on all
|
||||
public function testFetchConditionsID()
|
||||
{
|
||||
$model = new MockModel(['conditions' => ['id' => 1]]);
|
||||
var_dump($model->record);
|
||||
$this->assertEquals(1, $model->count());
|
||||
$this->assertEquals(1, $model->record['id']);
|
||||
}
|
||||
*/
|
||||
|
||||
public function testFetchCount()
|
||||
{
|
||||
|
@ -120,6 +130,90 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(3, $model->record['count']);
|
||||
}
|
||||
|
||||
public function testFetchIndexed()
|
||||
{
|
||||
$model = new MockModel('indexed', ['conditions' => ['id' => [2, 4]]]);
|
||||
$this->assertEquals(2, $model->count());
|
||||
$this->assertEquals([2, 4], array_keys($model->records));
|
||||
}
|
||||
|
||||
// Also tests against a full cache
|
||||
public function testFetchList()
|
||||
{
|
||||
$model = new MockModel('list', ['conditions' => ['id' => [2, 4]]]);
|
||||
$this->assertEquals(2, $model->count());
|
||||
$this->assertEquals([2, 4], array_keys($model->records));
|
||||
}
|
||||
|
||||
public function testFetchCountWithID()
|
||||
{
|
||||
$model = new MockModel('count', 3);
|
||||
$this->assertEquals(1, $model->record['count']);
|
||||
}
|
||||
|
||||
public function testFetchListWithID()
|
||||
{
|
||||
$model = new MockModel('list', 2);
|
||||
$this->assertEquals(1, $model->count());
|
||||
$this->assertEquals([2 => 'one'], $model->records);
|
||||
}
|
||||
|
||||
public function testJoinsString()
|
||||
{
|
||||
$model = new MockModelWithoutColumns([
|
||||
'conditions' => ['pickles.id' => 1],
|
||||
'joins' => 'brines ON brines.pickle_id = pickles.id',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testJoinsArray()
|
||||
{
|
||||
$model = new MockModelWithoutColumns([
|
||||
'conditions' => ['pickles.id' => 1],
|
||||
'joins' => [
|
||||
'INNER JOIN' => 'brines ON brines.pickle_id = pickles.id',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIndexHintsString()
|
||||
{
|
||||
$model = new MockModelWithoutColumns([
|
||||
'conditions' => ['pickles.id' => 1],
|
||||
'hints' => 'is_deleted',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIndexHintsArray()
|
||||
{
|
||||
$model = new MockModelWithoutColumns([
|
||||
'conditions' => ['pickles.id' => 1],
|
||||
'hints' => ['is_deleted'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIndexHintsMultiple()
|
||||
{
|
||||
$model = new MockOtherModel([
|
||||
'conditions' => ['id' => 1],
|
||||
'hints' => ['IGNORE INDEX' => ['pickle_id', 'is_deleted']],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testFieldValues()
|
||||
{
|
||||
$model = new MockModel('all');
|
||||
|
||||
$fields = $model->fieldValues('id');
|
||||
|
||||
$this->assertEquals('5', count($fields));
|
||||
|
||||
foreach ($fields as $value)
|
||||
{
|
||||
$this->assertTrue(ctype_digit($value));
|
||||
}
|
||||
}
|
||||
|
||||
public function testSort()
|
||||
{
|
||||
$model = new MockModel();
|
||||
|
@ -170,6 +264,35 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($expected, $model->record['id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$model = new MockModel();
|
||||
|
||||
for ($i = 1; $i <= 5; $i++)
|
||||
{
|
||||
$model->record['field' . $i] = String::random();
|
||||
}
|
||||
|
||||
$model->commit();
|
||||
}
|
||||
|
||||
public function testInsertMultiple()
|
||||
{
|
||||
$model = new MockModel();
|
||||
|
||||
for ($i = 1; $i <= 5; $i++)
|
||||
{
|
||||
for ($j = 1; $j <= 5; $j++)
|
||||
{
|
||||
$model->record['field' . $j] = String::random();
|
||||
}
|
||||
|
||||
$model->queue();
|
||||
}
|
||||
|
||||
$model->commit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<?php
|
||||
|
||||
class MockUserModel extends Model
|
||||
{
|
||||
protected $table = 'users';
|
||||
}
|
||||
|
||||
class SecurityTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGenerateHashWithDefaultSalts()
|
||||
|
@ -94,6 +99,51 @@ class SecurityTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
$this->assertFalse(Security::isLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
|
||||
/*
|
||||
public function testIsLevelDB()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
|
||||
$config->data = [
|
||||
'pickles' => [
|
||||
'datasource' => 'mysql',
|
||||
'cache' => 'memcache',
|
||||
],
|
||||
'datasources' => [
|
||||
'mysql' => [
|
||||
'type' => 'mysql',
|
||||
'driver' => 'pdo_mysql',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
'cache' => true,
|
||||
],
|
||||
'memcache' => [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => 11211,
|
||||
'namespace' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$model = new MockUserModel();
|
||||
$model->record['username'] = 'pickles';
|
||||
$model->commit();
|
||||
|
||||
setUpConfig([
|
||||
|
||||
]);
|
||||
|
||||
new Config();
|
||||
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
//$this->assertTrue(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
DROP TABLE IF EXISTS pickles;
|
||||
|
||||
CREATE TABLE `pickles` (
|
||||
`id` int(1) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`field1` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
|
@ -12,5 +14,39 @@ CREATE TABLE `pickles` (
|
|||
`deleted_id` int(1) unsigned DEFAULT NULL,
|
||||
`deleted_at` datetime DEFAULT NULL,
|
||||
`is_deleted` tinyint(1) unsigned DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY is_deleted (is_deleted)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS brines;
|
||||
|
||||
CREATE TABLE `brines` (
|
||||
`id` int(1) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`pickle_id` int(1) unsigned DEFAULT NULL,
|
||||
`created_id` int(1) unsigned DEFAULT NULL,
|
||||
`created_at` datetime NOT NULL,
|
||||
`updated_id` int(1) unsigned DEFAULT NULL,
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
`deleted_id` int(1) unsigned DEFAULT NULL,
|
||||
`deleted_at` datetime DEFAULT NULL,
|
||||
`is_deleted` tinyint(1) unsigned DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY pickle_id (pickle_id),
|
||||
KEY is_deleted (is_deleted)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS users;
|
||||
|
||||
CREATE TABLE `users` (
|
||||
`id` int(1) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`role` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'USER',
|
||||
`created_id` int(1) unsigned DEFAULT NULL,
|
||||
`created_at` datetime NOT NULL,
|
||||
`updated_id` int(1) unsigned DEFAULT NULL,
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
`deleted_id` int(1) unsigned DEFAULT NULL,
|
||||
`deleted_at` datetime DEFAULT NULL,
|
||||
`is_deleted` tinyint(1) unsigned DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue