code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function testFieldParsing() {
$result = $this->testDb->fields($this->Model, 'Vendor', "Vendor.id, COUNT(Model.vendor_id) AS `Vendor`.`count`");
$expected = array('`Vendor`.`id`', 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, 'Vendor', "`Vendor`.`id`, COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`");
$expected = array('`Vendor`.`id`', 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, 'Post', "CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name, Node.created");
$expected = array("CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name", "`Node`.`created`");
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, 'round( (3.55441 * fooField), 3 ) AS test');
$this->assertEqual($result, array('round( (3.55441 * fooField), 3 ) AS test'));
$result = $this->testDb->fields($this->Model, null, 'ROUND(`Rating`.`rate_total` / `Rating`.`rate_count`,2) AS rating');
$this->assertEqual($result, array('ROUND(`Rating`.`rate_total` / `Rating`.`rate_count`,2) AS rating'));
$result = $this->testDb->fields($this->Model, null, 'ROUND(Rating.rate_total / Rating.rate_count,2) AS rating');
$this->assertEqual($result, array('ROUND(Rating.rate_total / Rating.rate_count,2) AS rating'));
$result = $this->testDb->fields($this->Model, 'Post', "Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name");
$expected = array("`Node`.`created`", "CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name");
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, 'Post', "2.2,COUNT(*), SUM(Something.else) as sum, Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name,Post.title,Post.1,1.1");
$expected = array(
'2.2', 'COUNT(*)', 'SUM(`Something`.`else`) as sum', '`Node`.`created`',
"CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name", '`Post`.`title`', '`Post`.`1`', '1.1'
);
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, "(`Provider`.`star_total` / `Provider`.`total_ratings`) as `rating`");
$expected = array("(`Provider`.`star_total` / `Provider`.`total_ratings`) as `rating`");
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, 'Post');
$expected = array(
'`Post`.`id`', '`Post`.`client_id`', '`Post`.`name`', '`Post`.`login`',
'`Post`.`passwd`', '`Post`.`addr_1`', '`Post`.`addr_2`', '`Post`.`zip_code`',
'`Post`.`city`', '`Post`.`country`', '`Post`.`phone`', '`Post`.`fax`',
'`Post`.`url`', '`Post`.`email`', '`Post`.`comments`', '`Post`.`last_login`',
'`Post`.`created`', '`Post`.`updated`'
);
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, 'Other');
$expected = array(
'`Other`.`id`', '`Other`.`client_id`', '`Other`.`name`', '`Other`.`login`',
'`Other`.`passwd`', '`Other`.`addr_1`', '`Other`.`addr_2`', '`Other`.`zip_code`',
'`Other`.`city`', '`Other`.`country`', '`Other`.`phone`', '`Other`.`fax`',
'`Other`.`url`', '`Other`.`email`', '`Other`.`comments`', '`Other`.`last_login`',
'`Other`.`created`', '`Other`.`updated`'
);
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, array(), false);
$expected = array('id', 'client_id', 'name', 'login', 'passwd', 'addr_1', 'addr_2', 'zip_code', 'city', 'country', 'phone', 'fax', 'url', 'email', 'comments', 'last_login', 'created', 'updated');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, 'COUNT(*)');
$expected = array('COUNT(*)');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, 'SUM(Thread.unread_buyer) AS ' . $this->testDb->name('sum_unread_buyer'));
$expected = array('SUM(`Thread`.`unread_buyer`) AS `sum_unread_buyer`');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, 'name, count(*)');
$expected = array('`TestModel`.`name`', 'count(*)');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, 'count(*), name');
$expected = array('count(*)', '`TestModel`.`name`');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields(
$this->Model, null, 'field1, field2, field3, count(*), name'
);
$expected = array(
'`TestModel`.`field1`', '`TestModel`.`field2`',
'`TestModel`.`field3`', 'count(*)', '`TestModel`.`name`'
);
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, array('dayofyear(now())'));
$expected = array('dayofyear(now())');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, array('MAX(Model.field) As Max'));
$expected = array('MAX(`Model`.`field`) As Max');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, array('Model.field AS AnotherName'));
$expected = array('`Model`.`field` AS `AnotherName`');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, array('field AS AnotherName'));
$expected = array('`field` AS `AnotherName`');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, null, array(
'TestModel.field AS AnotherName'
));
$expected = array('`TestModel`.`field` AS `AnotherName`');
$this->assertEqual($result, $expected);
$result = $this->testDb->fields($this->Model, 'Foo', array(
'id', 'title', '(user_count + discussion_count + post_count) AS score'
));
$expected = array(
'`Foo`.`id`',
'`Foo`.`title`',
'(user_count + discussion_count + post_count) AS score'
);
$this->assertEqual($result, $expected);
} | testFieldParsing method
@access public
@return void | testFieldParsing | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testFieldsWithExpression() {
$expression = $this->testDb->expression("CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col");
$result = $this->testDb->fields($this->Model, null, array("id", $expression));
$expected = array(
'`TestModel`.`id`',
"CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col"
);
$this->assertEqual($result, $expected);
} | test that fields() will accept objects made from DboSource::expression
@return void | testFieldsWithExpression | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testOrderWithExpression() {
$expression = $this->testDb->expression("CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col");
$result = $this->testDb->order($expression);
$expected = " ORDER BY CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col";
$this->assertEqual($result, $expected);
} | test that order() will accept objects made from DboSource::expression
@return void | testOrderWithExpression | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testMergeAssociations() {
$data = array('Article2' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article',
'body' => 'First Article Body', 'published' => 'Y',
'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
));
$merge = array('Topic' => array(array(
'id' => '1', 'topic' => 'Topic', 'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
)));
$expected = array(
'Article2' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article',
'body' => 'First Article Body', 'published' => 'Y',
'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'Topic' => array(
'id' => '1', 'topic' => 'Topic', 'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Topic', 'hasOne');
$this->assertEqual($data, $expected);
$data = array('Article2' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article',
'body' => 'First Article Body', 'published' => 'Y',
'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
));
$merge = array('User2' => array(array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)));
$expected = array(
'Article2' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article',
'body' => 'First Article Body', 'published' => 'Y',
'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
);
$this->testDb->__mergeAssociation($data, $merge, 'User2', 'belongsTo');
$this->assertEqual($data, $expected);
$data = array(
'Article2' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
)
);
$merge = array(array('Comment' => false));
$expected = array(
'Article2' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'Comment' => array()
);
$this->testDb->__mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->assertEqual($data, $expected);
$data = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
)
);
$merge = array(
array(
'Comment' => array(
'id' => '1', 'comment' => 'Comment 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
),
array(
'Comment' => array(
'id' => '2', 'comment' => 'Comment 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
)
);
$expected = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'Comment' => array(
array(
'id' => '1', 'comment' => 'Comment 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
array(
'id' => '2', 'comment' => 'Comment 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->assertEqual($data, $expected);
$data = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
)
);
$merge = array(
array(
'Comment' => array(
'id' => '1', 'comment' => 'Comment 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
),
array(
'Comment' => array(
'id' => '2', 'comment' => 'Comment 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
)
);
$expected = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'Comment' => array(
array(
'id' => '1', 'comment' => 'Comment 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
),
array(
'id' => '2', 'comment' => 'Comment 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
)
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->assertEqual($data, $expected);
$data = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
)
);
$merge = array(
array(
'Comment' => array(
'id' => '1', 'comment' => 'Comment 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
'Tag' => array(
array('id' => 1, 'tag' => 'Tag 1'),
array('id' => 2, 'tag' => 'Tag 2')
)
),
array(
'Comment' => array(
'id' => '2', 'comment' => 'Comment 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
'Tag' => array()
)
);
$expected = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'Comment' => array(
array(
'id' => '1', 'comment' => 'Comment 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
'Tag' => array(
array('id' => 1, 'tag' => 'Tag 1'),
array('id' => 2, 'tag' => 'Tag 2')
)
),
array(
'id' => '2', 'comment' => 'Comment 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
'User2' => array(
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
'Tag' => array()
)
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->assertEqual($data, $expected);
$data = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
)
);
$merge = array(
array(
'Tag' => array(
'id' => '1', 'tag' => 'Tag 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
),
array(
'Tag' => array(
'id' => '2', 'tag' => 'Tag 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
),
array(
'Tag' => array(
'id' => '3', 'tag' => 'Tag 3', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
)
);
$expected = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'Tag' => array(
array(
'id' => '1', 'tag' => 'Tag 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
array(
'id' => '2', 'tag' => 'Tag 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
),
array(
'id' => '3', 'tag' => 'Tag 3', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Tag', 'hasAndBelongsToMany');
$this->assertEqual($data, $expected);
$data = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
)
);
$merge = array(
array(
'Tag' => array(
'id' => '1', 'tag' => 'Tag 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
),
array(
'Tag' => array(
'id' => '2', 'tag' => 'Tag 2', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
),
array(
'Tag' => array(
'id' => '3', 'tag' => 'Tag 3', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
)
);
$expected = array(
'Article' => array(
'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'Tag' => array('id' => '1', 'tag' => 'Tag 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')
);
$this->testDb->__mergeAssociation($data, $merge, 'Tag', 'hasOne');
$this->assertEqual($data, $expected);
} | testMergeAssociations method
@access public
@return void | testMergeAssociations | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testRenderStatement() {
$result = $this->testDb->renderStatement('select', array(
'fields' => 'id', 'table' => 'table', 'conditions' => 'WHERE 1=1',
'alias' => '', 'joins' => '', 'order' => '', 'limit' => '', 'group' => ''
));
$this->assertPattern('/^\s*SELECT\s+id\s+FROM\s+table\s+WHERE\s+1=1\s*$/', $result);
$result = $this->testDb->renderStatement('update', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => ''));
$this->assertPattern('/^\s*UPDATE\s+table\s+SET\s+value=2\s+WHERE\s+1=1\s*$/', $result);
$result = $this->testDb->renderStatement('update', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => 'alias', 'joins' => ''));
$this->assertPattern('/^\s*UPDATE\s+table\s+AS\s+alias\s+SET\s+value=2\s+WHERE\s+1=1\s*$/', $result);
$result = $this->testDb->renderStatement('delete', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => ''));
$this->assertPattern('/^\s*DELETE\s+FROM\s+table\s+WHERE\s+1=1\s*$/', $result);
$result = $this->testDb->renderStatement('delete', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => 'alias', 'joins' => ''));
$this->assertPattern('/^\s*DELETE\s+alias\s+FROM\s+table\s+AS\s+alias\s+WHERE\s+1=1\s*$/', $result);
} | testRenderStatement method
@access public
@return void | testRenderStatement | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testStatements() {
$Article =& ClassRegistry::init('Article');
$result = $this->testDb->update($Article, array('field1'), array('value1'));
$this->assertFalse($result);
$result = $this->testDb->getLastQuery();
$this->assertPattern('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . '\s+SET\s+`field1`\s*=\s*\'value1\'\s+WHERE\s+1 = 1\s*$/', $result);
$result = $this->testDb->update($Article, array('field1'), array('2'), '2=2');
$this->assertFalse($result);
$result = $this->testDb->getLastQuery();
$this->assertPattern('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . ' AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+SET\s+`Article`\.`field1`\s*=\s*2\s+WHERE\s+2\s*=\s*2\s*$/', $result);
$result = $this->testDb->delete($Article);
$this->assertTrue($result);
$result = $this->testDb->getLastQuery();
$this->assertPattern('/^\s*DELETE\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+WHERE\s+1 = 1\s*$/', $result);
$result = $this->testDb->delete($Article, true);
$this->assertTrue($result);
$result = $this->testDb->getLastQuery();
$this->assertPattern('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+1\s*=\s*1\s*$/', $result);
$result = $this->testDb->delete($Article, '2=2');
$this->assertTrue($result);
$result = $this->testDb->getLastQuery();
$this->assertPattern('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+2\s*=\s*2\s*$/', $result);
$result = $this->testDb->hasAny($Article, '1=2');
$this->assertFalse($result);
$result = $this->testDb->insertMulti('articles', array('field'), array('(1)', '(2)'));
$this->assertFalse($result);
$result = $this->testDb->getLastQuery();
$this->assertPattern('/^\s*INSERT INTO\s+' . $this->testDb->fullTableName('articles') . '\s+\(`field`\)\s+VALUES\s+\(1\),\s*\(2\)\s*$/', $result);
} | testStatements method
@access public
@return void | testStatements | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testSchema() {
$Schema =& new CakeSchema();
$Schema->tables = array('table' => array(), 'anotherTable' => array());
$this->expectError();
$result = $this->testDb->dropSchema(null);
$this->assertTrue($result === null);
$result = $this->testDb->dropSchema($Schema, 'non_existing');
$this->assertTrue(empty($result));
$result = $this->testDb->dropSchema($Schema, 'table');
$this->assertPattern('/^\s*DROP TABLE IF EXISTS\s+' . $this->testDb->fullTableName('table') . ';\s*$/s', $result);
} | testSchema method
@access public
@return void | testSchema | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testMagicMethodQuerying() {
$result = $this->testDb->query('findByFieldName', array('value'), $this->Model);
$expected = array('first', array(
'conditions' => array('TestModel.field_name' => 'value'),
'fields' => null, 'order' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);
$result = $this->testDb->query('findByFindBy', array('value'), $this->Model);
$expected = array('first', array(
'conditions' => array('TestModel.find_by' => 'value'),
'fields' => null, 'order' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);
$result = $this->testDb->query('findAllByFieldName', array('value'), $this->Model);
$expected = array('all', array(
'conditions' => array('TestModel.field_name' => 'value'),
'fields' => null, 'order' => null, 'limit' => null,
'page' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);
$result = $this->testDb->query('findAllById', array('a'), $this->Model);
$expected = array('all', array(
'conditions' => array('TestModel.id' => 'a'),
'fields' => null, 'order' => null, 'limit' => null,
'page' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);
$result = $this->testDb->query('findByFieldName', array(array('value1', 'value2', 'value3')), $this->Model);
$expected = array('first', array(
'conditions' => array('TestModel.field_name' => array('value1', 'value2', 'value3')),
'fields' => null, 'order' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);
$result = $this->testDb->query('findByFieldName', array(null), $this->Model);
$expected = array('first', array(
'conditions' => array('TestModel.field_name' => null),
'fields' => null, 'order' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);
$result = $this->testDb->query('findByFieldName', array('= a'), $this->Model);
$expected = array('first', array(
'conditions' => array('TestModel.field_name' => '= a'),
'fields' => null, 'order' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);
$result = $this->testDb->query('findByFieldName', array(), $this->Model);
$expected = false;
$this->assertEqual($result, $expected);
$result = $this->testDb->query('directCall', array(), $this->Model);
$this->assertFalse($result);
$result = $this->testDb->query('directCall', true, $this->Model);
$this->assertFalse($result);
$result = $this->testDb->query('directCall', false, $this->Model);
$this->assertFalse($result);
} | testMagicMethodQuerying method
@access public
@return void | testMagicMethodQuerying | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testOrderParsing() {
$result = $this->testDb->order("ADDTIME(Event.time_begin, '-06:00:00') ASC");
$expected = " ORDER BY ADDTIME(`Event`.`time_begin`, '-06:00:00') ASC";
$this->assertEqual($result, $expected);
$result = $this->testDb->order("title, id");
$this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result);
$result = $this->testDb->order("title desc, id desc");
$this->assertPattern('/^\s*ORDER BY\s+`title`\s+desc,\s+`id`\s+desc\s*$/', $result);
$result = $this->testDb->order(array("title desc, id desc"));
$this->assertPattern('/^\s*ORDER BY\s+`title`\s+desc,\s+`id`\s+desc\s*$/', $result);
$result = $this->testDb->order(array("title", "id"));
$this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result);
$result = $this->testDb->order(array(array('title'), array('id')));
$this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result);
$result = $this->testDb->order(array("Post.title" => 'asc', "Post.id" => 'desc'));
$this->assertPattern('/^\s*ORDER BY\s+`Post`.`title`\s+asc,\s+`Post`.`id`\s+desc\s*$/', $result);
$result = $this->testDb->order(array(array("Post.title" => 'asc', "Post.id" => 'desc')));
$this->assertPattern('/^\s*ORDER BY\s+`Post`.`title`\s+asc,\s+`Post`.`id`\s+desc\s*$/', $result);
$result = $this->testDb->order(array("title"));
$this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC\s*$/', $result);
$result = $this->testDb->order(array(array("title")));
$this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC\s*$/', $result);
$result = $this->testDb->order("Dealer.id = 7 desc, Dealer.id = 3 desc, Dealer.title asc");
$expected = " ORDER BY `Dealer`.`id` = 7 desc, `Dealer`.`id` = 3 desc, `Dealer`.`title` asc";
$this->assertEqual($result, $expected);
$result = $this->testDb->order(array("Page.name" => "='test' DESC"));
$this->assertPattern("/^\s*ORDER BY\s+`Page`\.`name`\s*='test'\s+DESC\s*$/", $result);
$result = $this->testDb->order("Page.name = 'view' DESC");
$this->assertPattern("/^\s*ORDER BY\s+`Page`\.`name`\s*=\s*'view'\s+DESC\s*$/", $result);
$result = $this->testDb->order("(Post.views)");
$this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\)\s+ASC\s*$/", $result);
$result = $this->testDb->order("(Post.views)*Post.views");
$this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\)\*`Post`\.`views`\s+ASC\s*$/", $result);
$result = $this->testDb->order("(Post.views) * Post.views");
$this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\) \* `Post`\.`views`\s+ASC\s*$/", $result);
$result = $this->testDb->order("(Model.field1 + Model.field2) * Model.field3");
$this->assertPattern("/^\s*ORDER BY\s+\(`Model`\.`field1` \+ `Model`\.`field2`\) \* `Model`\.`field3`\s+ASC\s*$/", $result);
$result = $this->testDb->order("Model.name+0 ASC");
$this->assertPattern("/^\s*ORDER BY\s+`Model`\.`name`\+0\s+ASC\s*$/", $result);
$result = $this->testDb->order("Anuncio.destaque & 2 DESC");
$expected = ' ORDER BY `Anuncio`.`destaque` & 2 DESC';
$this->assertEqual($result, $expected);
$result = $this->testDb->order("3963.191 * id");
$expected = ' ORDER BY 3963.191 * id ASC';
$this->assertEqual($result, $expected);
$result = $this->testDb->order(array('Property.sale_price IS NULL'));
$expected = ' ORDER BY `Property`.`sale_price` IS NULL ASC';
$this->assertEqual($result, $expected);
$result = $this->testDb->order(array('Export.column-name' => 'ASC'));
$expected = ' ORDER BY `Export`.`column-name` ASC';
$this->assertEqual($result, $expected, 'Columns with -s are not working with order()');
} | testOrderParsing method
@access public
@return void | testOrderParsing | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testComplexSortExpression() {
$result = $this->testDb->order(array('(Model.field > 100) DESC', 'Model.field ASC'));
$this->assertPattern("/^\s*ORDER BY\s+\(`Model`\.`field`\s+>\s+100\)\s+DESC,\s+`Model`\.`field`\s+ASC\s*$/", $result);
} | testComplexSortExpression method
@return void
@access public | testComplexSortExpression | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testCalculations() {
$result = $this->testDb->calculate($this->Model, 'count');
$this->assertEqual($result, 'COUNT(*) AS `count`');
$result = $this->testDb->calculate($this->Model, 'count', array('id'));
$this->assertEqual($result, 'COUNT(`id`) AS `count`');
$result = $this->testDb->calculate(
$this->Model,
'count',
array($this->testDb->expression('DISTINCT id'))
);
$this->assertEqual($result, 'COUNT(DISTINCT id) AS `count`');
$result = $this->testDb->calculate($this->Model, 'count', array('id', 'id_count'));
$this->assertEqual($result, 'COUNT(`id`) AS `id_count`');
$result = $this->testDb->calculate($this->Model, 'count', array('Model.id', 'id_count'));
$this->assertEqual($result, 'COUNT(`Model`.`id`) AS `id_count`');
$result = $this->testDb->calculate($this->Model, 'max', array('id'));
$this->assertEqual($result, 'MAX(`id`) AS `id`');
$result = $this->testDb->calculate($this->Model, 'max', array('Model.id', 'id'));
$this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`');
$result = $this->testDb->calculate($this->Model, 'max', array('`Model`.`id`', 'id'));
$this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`');
$result = $this->testDb->calculate($this->Model, 'min', array('`Model`.`id`', 'id'));
$this->assertEqual($result, 'MIN(`Model`.`id`) AS `id`');
$result = $this->testDb->calculate($this->Model, 'min', 'left');
$this->assertEqual($result, 'MIN(`left`) AS `left`');
} | testCalculations method
@access public
@return void | testCalculations | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testLength() {
$result = $this->testDb->length('varchar(255)');
$expected = 255;
$this->assertIdentical($result, $expected);
$result = $this->testDb->length('int(11)');
$expected = 11;
$this->assertIdentical($result, $expected);
$result = $this->testDb->length('float(5,3)');
$expected = '5,3';
$this->assertIdentical($result, $expected);
$result = $this->testDb->length('decimal(5,2)');
$expected = '5,2';
$this->assertIdentical($result, $expected);
$result = $this->testDb->length("enum('test','me','now')");
$expected = 4;
$this->assertIdentical($result, $expected);
$result = $this->testDb->length("set('a','b','cd')");
$expected = 2;
$this->assertIdentical($result, $expected);
$this->expectError();
$result = $this->testDb->length(false);
$this->assertTrue($result === null);
$result = $this->testDb->length('datetime');
$expected = null;
$this->assertIdentical($result, $expected);
$result = $this->testDb->length('text');
$expected = null;
$this->assertIdentical($result, $expected);
} | testLength method
@access public
@return void | testLength | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testBuildIndex() {
$data = array(
'PRIMARY' => array('column' => 'id')
);
$result = $this->testDb->buildIndex($data);
$expected = array('PRIMARY KEY (`id`)');
$this->assertIdentical($result, $expected);
$data = array(
'MyIndex' => array('column' => 'id', 'unique' => true)
);
$result = $this->testDb->buildIndex($data);
$expected = array('UNIQUE KEY `MyIndex` (`id`)');
$this->assertEqual($result, $expected);
$data = array(
'MyIndex' => array('column' => array('id', 'name'), 'unique' => true)
);
$result = $this->testDb->buildIndex($data);
$expected = array('UNIQUE KEY `MyIndex` (`id`, `name`)');
$this->assertEqual($result, $expected);
} | testBuildIndex method
@access public
@return void | testBuildIndex | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testBuildColumn() {
$this->expectError();
$data = array(
'name' => 'testName',
'type' => 'varchar(255)',
'default',
'null' => true,
'key'
);
$this->testDb->buildColumn($data);
$data = array(
'name' => 'testName',
'type' => 'string',
'length' => 255,
'default',
'null' => true,
'key'
);
$result = $this->testDb->buildColumn($data);
$expected = '`testName` varchar(255) DEFAULT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'int_field',
'type' => 'integer',
'default' => '',
'null' => false,
);
$restore = $this->testDb->columns;
$this->testDb->columns = array('integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), );
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertEqual($result, $expected);
$this->testDb->fieldParameters['param'] = array(
'value' => 'COLLATE',
'quote' => false,
'join' => ' ',
'column' => 'Collate',
'position' => 'beforeDefault',
'options' => array('GOOD', 'OK')
);
$data = array(
'name' => 'int_field',
'type' => 'integer',
'default' => '',
'null' => false,
'param' => 'BAD'
);
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'int_field',
'type' => 'integer',
'default' => '',
'null' => false,
'param' => 'GOOD'
);
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) COLLATE GOOD NOT NULL';
$this->assertEqual($result, $expected);
$this->testDb->columns = $restore;
$data = array(
'name' => 'created',
'type' => 'timestamp',
'default' => 'current_timestamp',
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '`created` timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'created',
'type' => 'timestamp',
'default' => 'CURRENT_TIMESTAMP',
'null' => true,
);
$result = $this->db->buildColumn($data);
$expected = '`created` timestamp DEFAULT CURRENT_TIMESTAMP';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'modified',
'type' => 'timestamp',
'null' => true,
);
$result = $this->db->buildColumn($data);
$expected = '`modified` timestamp NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'modified',
'type' => 'timestamp',
'default' => null,
'null' => true,
);
$result = $this->db->buildColumn($data);
$expected = '`modified` timestamp NULL';
$this->assertEqual($result, $expected);
} | testBuildColumn method
@access public
@return void | testBuildColumn | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testIntrospectType() {
$this->assertEqual($this->testDb->introspectType(0), 'integer');
$this->assertEqual($this->testDb->introspectType(2), 'integer');
$this->assertEqual($this->testDb->introspectType('2'), 'string');
$this->assertEqual($this->testDb->introspectType('2.2'), 'string');
$this->assertEqual($this->testDb->introspectType(2.2), 'float');
$this->assertEqual($this->testDb->introspectType('stringme'), 'string');
$this->assertEqual($this->testDb->introspectType('0stringme'), 'string');
$data = array(2.2);
$this->assertEqual($this->testDb->introspectType($data), 'float');
$data = array('2.2');
$this->assertEqual($this->testDb->introspectType($data), 'float');
$data = array(2);
$this->assertEqual($this->testDb->introspectType($data), 'integer');
$data = array('2');
$this->assertEqual($this->testDb->introspectType($data), 'integer');
$data = array('string');
$this->assertEqual($this->testDb->introspectType($data), 'string');
$data = array(2.2, '2.2');
$this->assertEqual($this->testDb->introspectType($data), 'float');
$data = array(2, '2');
$this->assertEqual($this->testDb->introspectType($data), 'integer');
$data = array('string one', 'string two');
$this->assertEqual($this->testDb->introspectType($data), 'string');
$data = array('2.2', 3);
$this->assertEqual($this->testDb->introspectType($data), 'integer');
$data = array('2.2', '0stringme');
$this->assertEqual($this->testDb->introspectType($data), 'string');
$data = array(2.2, 3);
$this->assertEqual($this->testDb->introspectType($data), 'integer');
$data = array(2.2, '0stringme');
$this->assertEqual($this->testDb->introspectType($data), 'string');
$data = array(2, 'stringme');
$this->assertEqual($this->testDb->introspectType($data), 'string');
$data = array(2, '2.2', 'stringgme');
$this->assertEqual($this->testDb->introspectType($data), 'string');
$data = array(2, '2.2');
$this->assertEqual($this->testDb->introspectType($data), 'integer');
$data = array(2, 2.2);
$this->assertEqual($this->testDb->introspectType($data), 'integer');
// NULL
$result = $this->testDb->value(null, 'boolean');
$this->assertEqual($result, 'NULL');
// EMPTY STRING
$result = $this->testDb->value('', 'boolean');
$this->assertEqual($result, "NULL");
// BOOLEAN
$result = $this->testDb->value('true', 'boolean');
$this->assertEqual($result, 1);
$result = $this->testDb->value('false', 'boolean');
$this->assertEqual($result, 1);
$result = $this->testDb->value(true, 'boolean');
$this->assertEqual($result, 1);
$result = $this->testDb->value(false, 'boolean');
$this->assertEqual($result, 0);
$result = $this->testDb->value(1, 'boolean');
$this->assertEqual($result, 1);
$result = $this->testDb->value(0, 'boolean');
$this->assertEqual($result, 0);
$result = $this->testDb->value('abc', 'boolean');
$this->assertEqual($result, 1);
$result = $this->testDb->value(1.234, 'boolean');
$this->assertEqual($result, 1);
$result = $this->testDb->value('1.234e05', 'boolean');
$this->assertEqual($result, 1);
// NUMBERS
$result = $this->testDb->value(123, 'integer');
$this->assertEqual($result, 123);
$result = $this->testDb->value('123', 'integer');
$this->assertEqual($result, '123');
$result = $this->testDb->value('0123', 'integer');
$this->assertEqual($result, "'0123'");
$result = $this->testDb->value('0x123ABC', 'integer');
$this->assertEqual($result, "'0x123ABC'");
$result = $this->testDb->value('0x123', 'integer');
$this->assertEqual($result, "'0x123'");
$result = $this->testDb->value(1.234, 'float');
$this->assertEqual($result, 1.234);
$result = $this->testDb->value('1.234', 'float');
$this->assertEqual($result, '1.234');
$result = $this->testDb->value(' 1.234 ', 'float');
$this->assertEqual($result, "' 1.234 '");
$result = $this->testDb->value('1.234e05', 'float');
$this->assertEqual($result, "'1.234e05'");
$result = $this->testDb->value('1.234e+5', 'float');
$this->assertEqual($result, "'1.234e+5'");
$result = $this->testDb->value('1,234', 'float');
$this->assertEqual($result, "'1,234'");
$result = $this->testDb->value('FFF', 'integer');
$this->assertEqual($result, "'FFF'");
$result = $this->testDb->value('abc', 'integer');
$this->assertEqual($result, "'abc'");
// STRINGS
$result = $this->testDb->value('123', 'string');
$this->assertEqual($result, "'123'");
$result = $this->testDb->value(123, 'string');
$this->assertEqual($result, "'123'");
$result = $this->testDb->value(1.234, 'string');
$this->assertEqual($result, "'1.234'");
$result = $this->testDb->value('abc', 'string');
$this->assertEqual($result, "'abc'");
$result = $this->testDb->value(' abc ', 'string');
$this->assertEqual($result, "' abc '");
$result = $this->testDb->value('a bc', 'string');
$this->assertEqual($result, "'a bc'");
} | testIntrospectType method
@access public
@return void | testIntrospectType | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testValue() {
$result = $this->testDb->value('{$__cakeForeignKey__$}');
$this->assertEqual($result, '{$__cakeForeignKey__$}');
$result = $this->testDb->value(array('first', 2, 'third'));
$expected = array('\'first\'', 2, '\'third\'');
$this->assertEqual($result, $expected);
} | testValue method
@access public
@return void | testValue | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testReconnect() {
$this->testDb->reconnect(array('prefix' => 'foo'));
$this->assertTrue($this->testDb->connected);
$this->assertEqual($this->testDb->config['prefix'], 'foo');
} | testReconnect method
@access public
@return void | testReconnect | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testRealQueries() {
$this->loadFixtures('Apple', 'Article', 'User', 'Comment', 'Tag');
$Apple =& ClassRegistry::init('Apple');
$Article =& ClassRegistry::init('Article');
$result = $this->db->rawQuery('SELECT color, name FROM ' . $this->db->fullTableName('apples'));
$this->assertTrue(!empty($result));
$result = $this->db->fetchRow($result);
$expected = array($this->db->fullTableName('apples', false) => array(
'color' => 'Red 1',
'name' => 'Red Apple 1'
));
$this->assertEqual($result, $expected);
$result = $this->db->fetchAll('SELECT name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id');
$expected = array(
array($this->db->fullTableName('apples', false) => array('name' => 'Red Apple 1')),
array($this->db->fullTableName('apples', false) => array('name' => 'Bright Red Apple')),
array($this->db->fullTableName('apples', false) => array('name' => 'green blue')),
array($this->db->fullTableName('apples', false) => array('name' => 'Test Name')),
array($this->db->fullTableName('apples', false) => array('name' => 'Blue Green')),
array($this->db->fullTableName('apples', false) => array('name' => 'My new apple')),
array($this->db->fullTableName('apples', false) => array('name' => 'Some odd color'))
);
$this->assertEqual($result, $expected);
$result = $this->db->field($this->testDb->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id');
$expected = array(
'color' => 'Red 1',
'name' => 'Red Apple 1'
);
$this->assertEqual($result, $expected);
$Apple->unbindModel(array(), false);
$result = $this->db->read($Apple, array(
'fields' => array($Apple->escapeField('name')),
'conditions' => null,
'recursive' => -1
));
$expected = array(
array('Apple' => array('name' => 'Red Apple 1')),
array('Apple' => array('name' => 'Bright Red Apple')),
array('Apple' => array('name' => 'green blue')),
array('Apple' => array('name' => 'Test Name')),
array('Apple' => array('name' => 'Blue Green')),
array('Apple' => array('name' => 'My new apple')),
array('Apple' => array('name' => 'Some odd color'))
);
$this->assertEqual($result, $expected);
$result = $this->db->read($Article, array(
'fields' => array('id', 'user_id', 'title'),
'conditions' => null,
'recursive' => 1
));
$this->assertTrue(Set::matches('/Article[id=1]', $result));
$this->assertTrue(Set::matches('/Comment[id=1]', $result));
$this->assertTrue(Set::matches('/Comment[id=2]', $result));
$this->assertFalse(Set::matches('/Comment[id=10]', $result));
} | testRealQueries method
@access public
@return void | testRealQueries | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testName() {
$result = $this->testDb->name('name');
$expected = '`name`';
$this->assertEqual($result, $expected);
$result = $this->testDb->name(array('name', 'Model.*'));
$expected = array('`name`', '`Model`.*');
$this->assertEqual($result, $expected);
$result = $this->testDb->name('MTD()');
$expected = 'MTD()';
$this->assertEqual($result, $expected);
$result = $this->testDb->name('(sm)');
$expected = '(sm)';
$this->assertEqual($result, $expected);
$result = $this->testDb->name('name AS x');
$expected = '`name` AS `x`';
$this->assertEqual($result, $expected);
$result = $this->testDb->name('Model.name AS x');
$expected = '`Model`.`name` AS `x`';
$this->assertEqual($result, $expected);
$result = $this->testDb->name('Function(Something.foo)');
$expected = 'Function(`Something`.`foo`)';
$this->assertEqual($result, $expected);
$result = $this->testDb->name('Function(SubFunction(Something.foo))');
$expected = 'Function(SubFunction(`Something`.`foo`))';
$this->assertEqual($result, $expected);
$result = $this->testDb->name('Function(Something.foo) AS x');
$expected = 'Function(`Something`.`foo`) AS `x`';
$this->assertEqual($result, $expected);
$result = $this->testDb->name('name-with-minus');
$expected = '`name-with-minus`';
$this->assertEqual($result, $expected);
$result = $this->testDb->name(array('my-name', 'Foo-Model.*'));
$expected = array('`my-name`', '`Foo-Model`.*');
$this->assertEqual($result, $expected);
$result = $this->testDb->name(array('Team.P%', 'Team.G/G'));
$expected = array('`Team`.`P%`', '`Team`.`G/G`');
$this->assertEqual($result, $expected);
$result = $this->testDb->name('Model.name as y');
$expected = '`Model`.`name` AS `y`';
$this->assertEqual($result, $expected);
} | testName method
@access public
@return void | testName | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testCacheMethod() {
$this->testDb->cacheMethods = true;
$result = $this->testDb->cacheMethod('name', 'some-key', 'stuff');
$this->assertEqual($result, 'stuff');
$result = $this->testDb->cacheMethod('name', 'some-key');
$this->assertEqual($result, 'stuff');
$result = $this->testDb->cacheMethod('conditions', 'some-key');
$this->assertNull($result);
$result = $this->testDb->cacheMethod('name', 'other-key');
$this->assertNull($result);
$this->testDb->cacheMethods = false;
$result = $this->testDb->cacheMethod('name', 'some-key', 'stuff');
$this->assertEqual($result, 'stuff');
$result = $this->testDb->cacheMethod('name', 'some-key');
$this->assertNull($result);
} | test that cacheMethod works as exepected
@return void | testCacheMethod | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testLog() {
$this->testDb->logQuery('Query 1');
$this->testDb->logQuery('Query 2');
$log = $this->testDb->getLog(false, false);
$result = Set::extract($log['log'], '/query');
$expected = array('Query 1', 'Query 2');
$this->assertEqual($result, $expected);
$oldError = $this->testDb->error;
$this->testDb->error = true;
$result = $this->testDb->logQuery('Error 1');
$this->assertFalse($result);
$this->testDb->error = $oldError;
$log = $this->testDb->getLog(false, false);
$result = Set::combine($log['log'], '/query', '/error');
$expected = array('Query 1' => false, 'Query 2' => false, 'Error 1' => true);
$this->assertEqual($result, $expected);
Configure::write('debug', 2);
ob_start();
$this->testDb->showLog();
$contents = ob_get_clean();
$this->assertPattern('/Query 1/s', $contents);
$this->assertPattern('/Query 2/s', $contents);
$this->assertPattern('/Error 1/s', $contents);
ob_start();
$this->testDb->showLog(true);
$contents = ob_get_clean();
$this->assertPattern('/Query 1/s', $contents);
$this->assertPattern('/Query 2/s', $contents);
$this->assertPattern('/Error 1/s', $contents);
$oldError = $this->testDb->error;
$oldDebug = Configure::read('debug');
Configure::write('debug', 2);
$this->testDb->error = true;
ob_start();
$this->testDb->showQuery('Error 2');
$contents = ob_get_clean();
$this->assertPattern('/Error 2/s', $contents);
$this->testDb->error = $oldError;
Configure::write('debug', $oldDebug);
} | testLog method
@access public
@return void | testLog | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testGetLog() {
$this->testDb->logQuery('Query 1');
$this->testDb->logQuery('Query 2');
$oldError = $this->testDb->error;
$this->testDb->error = true;
$result = $this->testDb->logQuery('Error 1');
$this->assertFalse($result);
$this->testDb->error = $oldError;
$log = $this->testDb->getLog();
$expected = array('query' => 'Query 1', 'error' => '', 'affected' => '', 'numRows' => '', 'took' => '');
$this->assertEqual($log['log'][0], $expected);
$expected = array('query' => 'Query 2', 'error' => '', 'affected' => '', 'numRows' => '', 'took' => '');
$this->assertEqual($log['log'][1], $expected);
$expected = array('query' => 'Error 1', 'error' => true, 'affected' => '', 'numRows' => '', 'took' => '');
$this->assertEqual($log['log'][2], $expected);
} | test getting the query log as an array.
@return void | testGetLog | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testExecute() {
$query = 'SELECT * FROM ' . $this->testDb->fullTableName('articles') . ' WHERE 1 = 1';
$this->db->_result = null;
$this->db->took = null;
$this->db->affected = null;
$result = $this->db->execute($query, array('stats' => false));
$this->assertNotNull($result, 'No query performed! %s');
$this->assertNull($this->db->took, 'Stats were set %s');
$this->assertNull($this->db->affected, 'Stats were set %s');
$result = $this->db->execute($query);
$this->assertNotNull($result, 'No query performed! %s');
$this->assertNotNull($this->db->took, 'Stats were not set %s');
$this->assertNotNull($this->db->affected, 'Stats were not set %s');
} | test that execute runs queries.
@return void | testExecute | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testFetchAllBooleanReturns() {
$name = $this->db->fullTableName('test_query');
$query = "CREATE TABLE {$name} (name varchar(10));";
$result = $this->db->query($query);
$this->assertTrue($result, 'Query did not return a boolean. %s');
$query = "DROP TABLE {$name};";
$result = $this->db->fetchAll($query);
$this->assertTrue($result, 'Query did not return a boolean. %s');
} | test that query() returns boolean values from operations like CREATE TABLE
@return void | testFetchAllBooleanReturns | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testFetchAllCaching() {
$query = "SELECT NOW() as TIME";
$result = $this->db->fetchAll($query);
$this->assertTrue(is_array($this->db->_queryCache[$query]));
$this->assertEqual($this->db->_queryCache[$query][0][0]['TIME'], $result[0][0]['TIME']);
$query = "DROP TABLE IF EXISTS select_test";
$result = $this->db->fetchAll($query);
$this->assertTrue(!isset($this->db->_queryCache[$query]));
} | test that query propery caches/doesn't cache selects
@return void
@author David Kullmann | testFetchAllCaching | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testShowQuery() {
$this->testDb->error = false;
ob_start();
$this->testDb->showQuery('Some Query');
$contents = ob_get_clean();
$this->assertPattern('/Some Query/s', $contents);
$this->assertPattern('/Aff:/s', $contents);
$this->assertPattern('/Num:/s', $contents);
$this->assertPattern('/Took:/s', $contents);
$this->expectError();
$this->testDb->error = true;
ob_start();
$this->testDb->showQuery('Another Query');
$contents = ob_get_clean();
$this->assertPattern('/Another Query/s', $contents);
$this->assertNoPattern('/Aff:/s', $contents);
$this->assertNoPattern('/Num:/s', $contents);
$this->assertNoPattern('/Took:/s', $contents);
} | test ShowQuery generation of regular and error messages
@return void | testShowQuery | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testVirtualFields() {
$this->loadFixtures('Article');
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_moment' => 'NOW()',
'two' => '1 + 1',
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') .
' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id'
);
$result = $this->db->fields($Article);
$expected = array(
'`Article`.`id`',
'`Article`.`user_id`',
'`Article`.`title`',
'`Article`.`body`',
'`Article`.`published`',
'`Article`.`created`',
'`Article`.`updated`',
'(NOW()) AS `Article__this_moment`',
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('this_moment', 'title'));
$expected = array(
'`Article`.`title`',
'(NOW()) AS `Article__this_moment`',
);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('Article.title', 'Article.this_moment'));
$expected = array(
'`Article`.`title`',
'(NOW()) AS `Article__this_moment`',
);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('Article.this_moment', 'Article.title'));
$expected = array(
'`Article`.`title`',
'(NOW()) AS `Article__this_moment`',
);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('Article.*'));
$expected = array(
'`Article`.*',
'(NOW()) AS `Article__this_moment`',
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('*'));
$expected = array(
'*',
'(NOW()) AS `Article__this_moment`',
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
);
$this->assertEqual($expected, $result);
} | test fields generating usable virtual fields to use in query
@return void | testVirtualFields | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testVirtualFieldsInConditions() {
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_moment' => 'NOW()',
'two' => '1 + 1',
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') .
' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id'
);
$conditions = array('two' => 2);
$result = $this->db->conditions($conditions, true, false, $Article);
$expected = '(1 + 1) = 2';
$this->assertEqual($expected, $result);
$conditions = array('this_moment BETWEEN ? AND ?' => array(1,2));
$expected = 'NOW() BETWEEN 1 AND 2';
$result = $this->db->conditions($conditions, true, false, $Article);
$this->assertEqual($expected, $result);
$conditions = array('comment_count >' => 5);
$expected = '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) > 5';
$result = $this->db->conditions($conditions, true, false, $Article);
$this->assertEqual($expected, $result);
$conditions = array('NOT' => array('two' => 2));
$result = $this->db->conditions($conditions, true, false, $Article);
$expected = 'NOT ((1 + 1) = 2)';
$this->assertEqual($expected, $result);
} | test conditions to generate query conditions for virtual fields
@return void | testVirtualFieldsInConditions | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testConditionsWithComplexVirtualFields() {
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'distance' => 'ACOS(SIN(20 * PI() / 180)
* SIN(Article.latitude * PI() / 180)
+ COS(20 * PI() / 180)
* COS(Article.latitude * PI() / 180)
* COS((50 - Article.longitude) * PI() / 180)
) * 180 / PI() * 60 * 1.1515 * 1.609344'
);
$conditions = array('distance >=' => 20);
$result = $this->db->conditions($conditions, true, true, $Article);
$this->assertPattern('/\) >= 20/', $result);
$this->assertPattern('/[`\'"]Article[`\'"].[`\'"]latitude[`\'"]/', $result);
$this->assertPattern('/[`\'"]Article[`\'"].[`\'"]longitude[`\'"]/', $result);
} | test that virtualFields with complex functions and aliases work.
@return void | testConditionsWithComplexVirtualFields | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testVirtualFieldsInOrder() {
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_moment' => 'NOW()',
'two' => '1 + 1',
);
$order = array('two', 'this_moment');
$result = $this->db->order($order, 'ASC', $Article);
$expected = ' ORDER BY (1 + 1) ASC, (NOW()) ASC';
$this->assertEqual($expected, $result);
$order = array('Article.two', 'Article.this_moment');
$result = $this->db->order($order, 'ASC', $Article);
$expected = ' ORDER BY (1 + 1) ASC, (NOW()) ASC';
$this->assertEqual($expected, $result);
} | test order to generate query order clause for virtual fields
@return void | testVirtualFieldsInOrder | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testVirtualFieldsInCalculate() {
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_moment' => 'NOW()',
'two' => '1 + 1',
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') .
' WHERE Article.id = ' . $this->db->fullTableName('comments'). '.article_id'
);
$result = $this->db->calculate($Article, 'count', array('this_moment'));
$expected = 'COUNT(NOW()) AS `count`';
$this->assertEqual($expected, $result);
$result = $this->db->calculate($Article, 'max', array('comment_count'));
$expected = 'MAX(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `comment_count`';
$this->assertEqual($expected, $result);
} | test calculate to generate claculate statements on virtual fields
@return void | testVirtualFieldsInCalculate | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testVirtualFieldsFetch() {
$this->loadFixtures('Article', 'Comment');
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') .
' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id'
);
$conditions = array('comment_count >' => 2);
$query = 'SELECT ' . join(',',$this->db->fields($Article, null, array('id', 'comment_count'))) .
' FROM ' . $this->db->fullTableName($Article) . ' Article ' . $this->db->conditions($conditions, true, true, $Article);
$result = $this->db->fetchAll($query);
$expected = array(array(
'Article' => array('id' => 1, 'comment_count' => 4)
));
$this->assertEqual($expected, $result);
} | test a full example of using virtual fields
@return void | testVirtualFieldsFetch | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testVirtualFieldsComplexRead() {
$this->loadFixtures('DataTest', 'Article', 'Comment');
$Article =& ClassRegistry::init('Article');
$commentTable = $this->db->fullTableName('comments');
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'comment_count' => 'SELECT COUNT(*) FROM ' . $commentTable .
' AS Comment WHERE Article.id = Comment.article_id'
);
$result = $Article->find('all');
$this->assertTrue(count($result) > 0);
$this->assertTrue($result[0]['Article']['comment_count'] > 0);
$DataTest =& ClassRegistry::init('DataTest');
$DataTest->virtualFields = array(
'complicated' => 'ACOS(SIN(20 * PI() / 180)
* SIN(DataTest.float * PI() / 180)
+ COS(20 * PI() / 180)
* COS(DataTest.count * PI() / 180)
* COS((50 - DataTest.float) * PI() / 180)
) * 180 / PI() * 60 * 1.1515 * 1.609344'
);
$result = $DataTest->find('all');
$this->assertTrue(count($result) > 0);
$this->assertTrue($result[0]['DataTest']['complicated'] > 0);
} | test reading complex virtualFields with subqueries.
@return void | testVirtualFieldsComplexRead | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testFieldsWithComplexVirtualFields() {
$Article =& new Article();
$Article->virtualFields = array(
'distance' => 'ACOS(SIN(20 * PI() / 180)
* SIN(Article.latitude * PI() / 180)
+ COS(20 * PI() / 180)
* COS(Article.latitude * PI() / 180)
* COS((50 - Article.longitude) * PI() / 180)
) * 180 / PI() * 60 * 1.1515 * 1.609344'
);
$fields = array('id', 'distance');
$result = $this->db->fields($Article, null, $fields);
$qs = $this->db->startQuote;
$qe = $this->db->endQuote;
$this->assertEqual($result[0], "{$qs}Article{$qe}.{$qs}id{$qe}");
$this->assertPattern('/Article__distance/', $result[1]);
$this->assertPattern('/[`\'"]Article[`\'"].[`\'"]latitude[`\'"]/', $result[1]);
$this->assertPattern('/[`\'"]Article[`\'"].[`\'"]longitude[`\'"]/', $result[1]);
} | test that virtualFields with complex functions and aliases work.
@return void | testFieldsWithComplexVirtualFields | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testReadVirtualFieldsWithNewLines() {
$Article =& new Article();
$Article->recursive = 1;
$Article->virtualFields = array(
'test' => '
User.id + User.id
'
);
$result = $this->db->fields($Article, null, array());
$result = $this->db->fields($Article, $Article->alias, $result);
$this->assertPattern('/[`\"]User[`\"]\.[`\"]id[`\"] \+ [`\"]User[`\"]\.[`\"]id[`\"]/', $result[7]);
} | test reading virtual fields containing newlines when recursive > 0
@return void | testReadVirtualFieldsWithNewLines | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testVirtualFieldsInGroup() {
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_year' => 'YEAR(Article.created)'
);
$result = $this->db->group('this_year',$Article);
$expected = " GROUP BY (YEAR(`Article`.`created`))";
$this->assertEqual($expected, $result);
} | test group to generate GROUP BY statements on virtual fields
@return void | testVirtualFieldsInGroup | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testGroupNoModel() {
$result = $this->db->group('created');
$this->assertEqual(' GROUP BY created', $result);
} | Test that group works without a model
@return void | testGroupNoModel | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testFullTablePermutations() {
$Article =& ClassRegistry::init('Article');
$result = $this->testDb->fullTableName($Article, false);
$this->assertEqual($result, 'articles');
$Article->tablePrefix = 'tbl_';
$result = $this->testDb->fullTableName($Article, false);
$this->assertEqual($result, 'tbl_articles');
$Article->useTable = $Article->table = 'with spaces';
$Article->tablePrefix = '';
$result = $this->testDb->fullTableName($Article);
$this->assertEqual($result, '`with spaces`');
} | test the permutations of fullTableName()
@return void | testFullTablePermutations | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testReadOnlyCallingQueryAssociationWhenDefined() {
ConnectionManager::create('test_no_queryAssociation', array(
'datasource' => 'data'
));
$Article =& ClassRegistry::init('Article');
$Article->Comment->useDbConfig = 'test_no_queryAssociation';
$result = $Article->find('all');
$this->assertTrue(is_array($result));
} | test that read() only calls queryAssociation on db objects when the method is defined.
@return void | testReadOnlyCallingQueryAssociationWhenDefined | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function testFieldsUsingMethodCache() {
$this->testDb->cacheMethods = false;
$this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty');
$Article =& ClassRegistry::init('Article');
$this->testDb->fields($Article, null, array('title', 'body', 'published'));
$this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty');
} | test that fields() is using methodCache()
@return void | testFieldsUsingMethodCache | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo_source.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo_source.test.php | MIT |
function _execute($sql) {
if ($this->simulate) {
$this->simulated[] = $sql;
return null;
} else {
return parent::_execute($sql);
}
} | execute method
@param mixed $sql
@access protected
@return void | _execute | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function _matchRecords(&$model, $conditions = null) {
return $this->conditions(array('id' => array(1, 2)));
} | fetchAll method
@param mixed $sql
@access protected
@return void | _matchRecords | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function fetchAll($sql, $cache = true, $modelName = null) {
$result = parent::fetchAll($sql, $cache, $modelName);
if (!empty($this->fetchAllResultsStack)) {
return array_pop($this->fetchAllResultsStack);
}
return $result;
} | fetchAll method
@param mixed $sql
@access protected
@return void | fetchAll | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function getLastQuery() {
return $this->simulated[count($this->simulated) - 1];
} | getLastQuery method
@access public
@return void | getLastQuery | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function getPrimaryKey($model) {
return parent::_getPrimaryKey($model);
} | getPrimaryKey method
@param mixed $model
@access public
@return void | getPrimaryKey | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function clearFieldMappings() {
$this->__fieldMappings = array();
} | clearFieldMappings method
@access public
@return void | clearFieldMappings | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function find($conditions = null, $fields = null, $order = null, $recursive = null) {
return $conditions;
} | find method
@param mixed $conditions
@param mixed $fields
@param mixed $order
@param mixed $recursive
@access public
@return void | find | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function findAll($conditions = null, $fields = null, $order = null, $recursive = null) {
return $conditions;
} | findAll method
@param mixed $conditions
@param mixed $fields
@param mixed $order
@param mixed $recursive
@access public
@return void | findAll | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function setSchema($schema) {
$this->_schema = $schema;
} | setSchema method
@param array $schema
@access public
@return void | setSchema | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function skip() {
$this->_initDb();
$this->skipUnless($this->db->config['driver'] == 'mssql', '%s SQL Server connection not available');
} | Skip if cannot connect to mssql
@access public | skip | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function start() {
$this->db->simulate = false;
parent::start();
$this->db->simulate = true;
} | Make sure all fixtures tables are being created
@access public | start | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function end() {
$this->db->simulate = false;
parent::end();
$this->db->simulate = true;
} | Make sure all fixtures tables are being dropped
@access public | end | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function setUp() {
$db = ConnectionManager::getDataSource('test_suite');
$this->db = new DboMssqlTestDb($db->config);
$this->model = new MssqlTestModel();
} | Sets up a Dbo class instance for testing
@access public | setUp | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function testQuoting() {
$expected = "1.2";
$result = $this->db->value(1.2, 'float');
$this->assertIdentical($expected, $result);
$expected = "'1,2'";
$result = $this->db->value('1,2', 'float');
$this->assertIdentical($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'integer');
$this->assertIdentical($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'float');
$this->assertIdentical($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'binary');
$this->assertIdentical($expected, $result);
} | testQuoting method
@access public
@return void | testQuoting | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function testFields() {
$fields = array(
'[MssqlTestModel].[id] AS [MssqlTestModel__0]',
'[MssqlTestModel].[client_id] AS [MssqlTestModel__1]',
'[MssqlTestModel].[name] AS [MssqlTestModel__2]',
'[MssqlTestModel].[login] AS [MssqlTestModel__3]',
'[MssqlTestModel].[passwd] AS [MssqlTestModel__4]',
'[MssqlTestModel].[addr_1] AS [MssqlTestModel__5]',
'[MssqlTestModel].[addr_2] AS [MssqlTestModel__6]',
'[MssqlTestModel].[zip_code] AS [MssqlTestModel__7]',
'[MssqlTestModel].[city] AS [MssqlTestModel__8]',
'[MssqlTestModel].[country] AS [MssqlTestModel__9]',
'[MssqlTestModel].[phone] AS [MssqlTestModel__10]',
'[MssqlTestModel].[fax] AS [MssqlTestModel__11]',
'[MssqlTestModel].[url] AS [MssqlTestModel__12]',
'[MssqlTestModel].[email] AS [MssqlTestModel__13]',
'[MssqlTestModel].[comments] AS [MssqlTestModel__14]',
'CONVERT(VARCHAR(20), [MssqlTestModel].[last_login], 20) AS [MssqlTestModel__15]',
'[MssqlTestModel].[created] AS [MssqlTestModel__16]',
'CONVERT(VARCHAR(20), [MssqlTestModel].[updated], 20) AS [MssqlTestModel__17]'
);
$result = $this->db->fields($this->model);
$expected = $fields;
$this->assertEqual($result, $expected);
$this->db->clearFieldMappings();
$result = $this->db->fields($this->model, null, 'MssqlTestModel.*');
$expected = $fields;
$this->assertEqual($result, $expected);
$this->db->clearFieldMappings();
$result = $this->db->fields($this->model, null, array('*', 'AnotherModel.id', 'AnotherModel.name'));
$expected = array_merge($fields, array(
'[AnotherModel].[id] AS [AnotherModel__18]',
'[AnotherModel].[name] AS [AnotherModel__19]'));
$this->assertEqual($result, $expected);
$this->db->clearFieldMappings();
$result = $this->db->fields($this->model, null, array('*', 'MssqlClientTestModel.*'));
$expected = array_merge($fields, array(
'[MssqlClientTestModel].[id] AS [MssqlClientTestModel__18]',
'[MssqlClientTestModel].[name] AS [MssqlClientTestModel__19]',
'[MssqlClientTestModel].[email] AS [MssqlClientTestModel__20]',
'CONVERT(VARCHAR(20), [MssqlClientTestModel].[created], 20) AS [MssqlClientTestModel__21]',
'CONVERT(VARCHAR(20), [MssqlClientTestModel].[updated], 20) AS [MssqlClientTestModel__22]'));
$this->assertEqual($result, $expected);
} | testFields method
@access public
@return void | testFields | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function testDistinctFields() {
$result = $this->db->fields($this->model, null, array('DISTINCT Car.country_code'));
$expected = array('DISTINCT [Car].[country_code] AS [Car__0]');
$this->assertEqual($result, $expected);
$result = $this->db->fields($this->model, null, 'DISTINCT Car.country_code');
$expected = array('DISTINCT [Car].[country_code] AS [Car__1]');
$this->assertEqual($result, $expected);
} | testDistinctFields method
@access public
@return void | testDistinctFields | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function testDescribe() {
$MssqlTableDescription = array(
0 => array(
0 => array(
'Default' => '((0))',
'Field' => 'count',
'Key' => 0,
'Length' => '4',
'Null' => 'NO',
'Type' => 'integer',
)
)
);
$this->db->fetchAllResultsStack = array($MssqlTableDescription);
$dummyModel = $this->model;
$result = $this->db->describe($dummyModel);
$expected = array(
'count' => array(
'type' => 'integer',
'null' => false,
'default' => '0',
'length' => 4
)
);
$this->assertEqual($result, $expected);
} | testDescribe method
@access public
@return void | testDescribe | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function testBuildIndex() {
$indexes = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'client_id' => array('column' => 'client_id', 'unique' => 1)
);
$result = $this->db->buildIndex($indexes, 'items');
$expected = array(
'PRIMARY KEY ([id])',
'ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id]);'
);
$this->assertEqual($result, $expected);
$indexes = array('client_id' => array('column' => 'client_id'));
$result = $this->db->buildIndex($indexes, 'items');
$this->assertEqual($result, array());
$indexes = array('client_id' => array('column' => array('client_id', 'period_id'), 'unique' => 1));
$result = $this->db->buildIndex($indexes, 'items');
$expected = array('ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id], [period_id]);');
$this->assertEqual($result, $expected);
} | testBuildIndex method
@return void
@access public | testBuildIndex | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function testUpdateAllSyntax() {
$fields = array('MssqlTestModel.client_id' => '[MssqlTestModel].[client_id] + 1');
$conditions = array('MssqlTestModel.updated <' => date('2009-01-01 00:00:00'));
$this->db->update($this->model, $fields, null, $conditions);
$result = $this->db->getLastQuery();
$this->assertNoPattern('/MssqlTestModel/', $result);
$this->assertPattern('/^UPDATE \[mssql_test_models\]/', $result);
$this->assertPattern('/SET \[client_id\] = \[client_id\] \+ 1/', $result);
} | testUpdateAllSyntax method
@return void
@access public | testUpdateAllSyntax | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function testGetPrimaryKey() {
// When param is a model
$result = $this->db->getPrimaryKey($this->model);
$this->assertEqual($result, 'id');
$schema = $this->model->schema();
unset($schema['id']['key']);
$this->model->setSchema($schema);
$result = $this->db->getPrimaryKey($this->model);
$this->assertNull($result);
// When param is a table name
$this->db->simulate = false;
$this->loadFixtures('Category');
$result = $this->db->getPrimaryKey('categories');
$this->assertEqual($result, 'id');
} | testGetPrimaryKey method
@return void
@access public | testGetPrimaryKey | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php | MIT |
function find($conditions = null, $fields = null, $order = null, $recursive = null) {
return $conditions;
} | find method
@param mixed $conditions
@param mixed $fields
@param mixed $order
@param mixed $recursive
@access public
@return void | find | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function findAll($conditions = null, $fields = null, $order = null, $recursive = null) {
return $conditions;
} | findAll method
@param mixed $conditions
@param mixed $fields
@param mixed $order
@param mixed $recursive
@access public
@return void | findAll | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function schema() {
return array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
} | schema method
@access public
@return void | schema | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function skip() {
$this->_initDb();
$this->skipUnless($this->db->config['driver'] == 'mysql', '%s MySQL connection not available');
} | Skip if cannot connect to mysql
@access public | skip | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function startTest() {
$db = ConnectionManager::getDataSource('test_suite');
$this->model = new MysqlTestModel();
} | Sets up a Dbo class instance for testing
@access public | startTest | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function tearDown() {
unset($this->model);
ClassRegistry::flush();
} | Sets up a Dbo class instance for testing
@access public | tearDown | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testQuoting() {
$result = $this->db->fields($this->model);
$expected = array(
'`MysqlTestModel`.`id`',
'`MysqlTestModel`.`client_id`',
'`MysqlTestModel`.`name`',
'`MysqlTestModel`.`login`',
'`MysqlTestModel`.`passwd`',
'`MysqlTestModel`.`addr_1`',
'`MysqlTestModel`.`addr_2`',
'`MysqlTestModel`.`zip_code`',
'`MysqlTestModel`.`city`',
'`MysqlTestModel`.`country`',
'`MysqlTestModel`.`phone`',
'`MysqlTestModel`.`fax`',
'`MysqlTestModel`.`url`',
'`MysqlTestModel`.`email`',
'`MysqlTestModel`.`comments`',
'`MysqlTestModel`.`last_login`',
'`MysqlTestModel`.`created`',
'`MysqlTestModel`.`updated`'
);
$this->assertEqual($result, $expected);
$expected = 1.2;
$result = $this->db->value(1.2, 'float');
$this->assertEqual($expected, $result);
$expected = "'1,2'";
$result = $this->db->value('1,2', 'float');
$this->assertEqual($expected, $result);
$expected = "'4713e29446'";
$result = $this->db->value('4713e29446');
$this->assertEqual($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'integer');
$this->assertEqual($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'boolean');
$this->assertEqual($expected, $result);
$expected = 10010001;
$result = $this->db->value(10010001);
$this->assertEqual($expected, $result);
$expected = "'00010010001'";
$result = $this->db->value('00010010001');
$this->assertEqual($expected, $result);
} | Test Dbo value method
@access public | testQuoting | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testLocalizedFloats() {
$restore = setlocale(LC_ALL, null);
setlocale(LC_ALL, 'de_DE');
$result = $this->db->value(3.141593, 'float');
$this->assertEqual('3.141593', $result);
$result = $this->db->value(3.141593);
$this->assertEqual('3.141593', $result);
$result = $this->db->value(3.141593);
$this->assertEqual('3.141593', $result);
$result = $this->db->value(1234567.11, 'float');
$this->assertEqual('1234567.11', $result);
$result = $this->db->value(123456.45464748, 'float');
$this->assertEqual('123456.454647', $result);
$result = $this->db->value(0.987654321, 'float');
$this->assertEqual('0.987654321', (string)$result);
$result = $this->db->value(2.2E-54, 'float');
$this->assertEqual('2.2E-54', (string)$result);
$result = $this->db->value(2.2E-54);
$this->assertEqual('2.2E-54', (string)$result);
setlocale(LC_ALL, $restore);
} | test that localized floats don't cause trouble.
@return void | testLocalizedFloats | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testScientificNotation() {
$result = $this->db->value(2.2E-54, 'float');
$this->assertEqual('2.2E-54', (string)$result);
$result = $this->db->value(2.2E-54, 'float');
$this->assertEqual('2.2E-54', (string)$result);
$result = $this->db->value(2.2E-54);
$this->assertEqual('2.2E-54', (string)$result);
} | test that scientific notations are working correctly
@return void | testScientificNotation | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testTinyintCasting() {
$this->db->cacheSources = false;
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
$this->model = new CakeTestModel(array(
'name' => 'Tinyint', 'table' => 'tinyint', 'ds' => 'test_suite'
));
$result = $this->model->schema();
$this->assertEqual($result['bool']['type'], 'boolean');
$this->assertEqual($result['small_int']['type'], 'integer');
$this->assertTrue($this->model->save(array('bool' => 5, 'small_int' => 5)));
$result = $this->model->find('first');
$this->assertIdentical($result['Tinyint']['bool'], '1');
$this->assertIdentical($result['Tinyint']['small_int'], '5');
$this->model->deleteAll(true);
$this->assertTrue($this->model->save(array('bool' => 0, 'small_int' => 100)));
$result = $this->model->find('first');
$this->assertIdentical($result['Tinyint']['bool'], '0');
$this->assertIdentical($result['Tinyint']['small_int'], '100');
$this->model->deleteAll(true);
$this->assertTrue($this->model->save(array('bool' => true, 'small_int' => 0)));
$result = $this->model->find('first');
$this->assertIdentical($result['Tinyint']['bool'], '1');
$this->assertIdentical($result['Tinyint']['small_int'], '0');
$this->model->deleteAll(true);
$this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint'));
} | testTinyintCasting method
@access public
@return void | testTinyintCasting | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testIndexDetection() {
$this->db->cacheSources = false;
$name = $this->db->fullTableName('simple');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
$expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1));
$result = $this->db->index('simple', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
$name = $this->db->fullTableName('with_a_key');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ));');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
);
$result = $this->db->index('with_a_key', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
$name = $this->db->fullTableName('with_two_keys');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ));');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
);
$result = $this->db->index('with_two_keys', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
$name = $this->db->fullTableName('with_compound_keys');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ));');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
);
$result = $this->db->index('with_compound_keys', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
$name = $this->db->fullTableName('with_multiple_compound_keys');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ), KEY `other_way` ( `small_int`, `bool` ));');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0),
);
$result = $this->db->index('with_multiple_compound_keys', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
} | testIndexDetection method
@return void
@access public | testIndexDetection | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testBuildColumn() {
$restore = $this->db->columns;
$this->db->columns = array('varchar(255)' => 1);
$data = array(
'name' => 'testName',
'type' => 'varchar(255)',
'default',
'null' => true,
'key',
'comment' => 'test'
);
$result = $this->db->buildColumn($data);
$expected = '`testName` DEFAULT NULL COMMENT \'test\'';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'testName',
'type' => 'varchar(255)',
'default',
'null' => true,
'key',
'charset' => 'utf8',
'collate' => 'utf8_unicode_ci'
);
$result = $this->db->buildColumn($data);
$expected = '`testName` CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL';
$this->assertEqual($result, $expected);
$this->db->columns = $restore;
} | testBuildColumn method
@access public
@return void | testBuildColumn | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testIndexOnMySQL4Output() {
$name = $this->db->fullTableName('simple');
$mockDbo =& new QueryMockDboMysql($this);
$columnData = array(
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '0',
'Key_name' => 'PRIMARY',
'Seq_in_index' => '1',
'Column_name' => 'id',
'Collation' => 'A',
'Cardinality' => '0',
'Sub_part' => NULL,
'Packed' => NULL,
'Null' => '',
'Index_type' => 'BTREE',
'Comment' => ''
)),
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '1',
'Key_name' => 'pointless_bool',
'Seq_in_index' => '1',
'Column_name' => 'bool',
'Collation' => 'A',
'Cardinality' => NULL,
'Sub_part' => NULL,
'Packed' => NULL,
'Null' => 'YES',
'Index_type' => 'BTREE',
'Comment' => ''
)),
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '1',
'Key_name' => 'pointless_small_int',
'Seq_in_index' => '1',
'Column_name' => 'small_int',
'Collation' => 'A',
'Cardinality' => NULL,
'Sub_part' => NULL,
'Packed' => NULL,
'Null' => 'YES',
'Index_type' => 'BTREE',
'Comment' => ''
)),
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '1',
'Key_name' => 'one_way',
'Seq_in_index' => '1',
'Column_name' => 'bool',
'Collation' => 'A',
'Cardinality' => NULL,
'Sub_part' => NULL,
'Packed' => NULL,
'Null' => 'YES',
'Index_type' => 'BTREE',
'Comment' => ''
)),
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '1',
'Key_name' => 'one_way',
'Seq_in_index' => '2',
'Column_name' => 'small_int',
'Collation' => 'A',
'Cardinality' => NULL,
'Sub_part' => NULL,
'Packed' => NULL,
'Null' => 'YES',
'Index_type' => 'BTREE',
'Comment' => ''
))
);
$mockDbo->setReturnValue('query', $columnData, array('SHOW INDEX FROM ' . $name));
$result = $mockDbo->index($name, false);
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
);
$this->assertEqual($result, $expected);
} | MySQL 4.x returns index data in a different format,
Using a mock ensure that MySQL 4.x output is properly parsed.
@return void | testIndexOnMySQL4Output | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testColumn() {
$result = $this->db->column('varchar(50)');
$expected = 'string';
$this->assertEqual($result, $expected);
$result = $this->db->column('text');
$expected = 'text';
$this->assertEqual($result, $expected);
$result = $this->db->column('int(11)');
$expected = 'integer';
$this->assertEqual($result, $expected);
$result = $this->db->column('int(11) unsigned');
$expected = 'integer';
$this->assertEqual($result, $expected);
$result = $this->db->column('tinyint(1)');
$expected = 'boolean';
$this->assertEqual($result, $expected);
$result = $this->db->column('boolean');
$expected = 'boolean';
$this->assertEqual($result, $expected);
$result = $this->db->column('float');
$expected = 'float';
$this->assertEqual($result, $expected);
$result = $this->db->column('float unsigned');
$expected = 'float';
$this->assertEqual($result, $expected);
$result = $this->db->column('double unsigned');
$expected = 'float';
$this->assertEqual($result, $expected);
$result = $this->db->column('decimal(14,7) unsigned');
$expected = 'float';
$this->assertEqual($result, $expected);
} | testColumn method
@return void
@access public | testColumn | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testAlterSchemaIndexes() {
App::import('Model', 'CakeSchema');
$this->db->cacheSources = false;
$schema1 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
'group1' => array('type' => 'integer', 'null' => true),
'group2' => array('type' => 'integer', 'null' => true)
)));
$this->db->query($this->db->createSchema($schema1));
$schema2 =& new CakeSchema(array(
'name' => 'AlterTest2',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
'group1' => array('type' => 'integer', 'null' => true),
'group2' => array('type' => 'integer', 'null' => true),
'indexes' => array(
'name_idx' => array('column' => 'name', 'unique' => 0),
'group_idx' => array('column' => 'group1', 'unique' => 0),
'compound_idx' => array('column' => array('group1', 'group2'), 'unique' => 0),
'PRIMARY' => array('column' => 'id', 'unique' => 1))
)));
$this->db->query($this->db->alterSchema($schema2->compare($schema1)));
$indexes = $this->db->index('altertest');
$this->assertEqual($schema2->tables['altertest']['indexes'], $indexes);
// Change three indexes, delete one and add another one
$schema3 =& new CakeSchema(array(
'name' => 'AlterTest3',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
'group1' => array('type' => 'integer', 'null' => true),
'group2' => array('type' => 'integer', 'null' => true),
'indexes' => array(
'name_idx' => array('column' => 'name', 'unique' => 1),
'group_idx' => array('column' => 'group2', 'unique' => 0),
'compound_idx' => array('column' => array('group2', 'group1'), 'unique' => 0),
'id_name_idx' => array('column' => array('id', 'name'), 'unique' => 0))
)));
$this->db->query($this->db->alterSchema($schema3->compare($schema2)));
$indexes = $this->db->index('altertest');
$this->assertEqual($schema3->tables['altertest']['indexes'], $indexes);
// Compare us to ourself.
$this->assertEqual($schema3->compare($schema3), array());
// Drop the indexes
$this->db->query($this->db->alterSchema($schema1->compare($schema3)));
$indexes = $this->db->index('altertest');
$this->assertEqual(array(), $indexes);
$this->db->query($this->db->dropSchema($schema1));
} | testAlterSchemaIndexes method
@access public
@return void | testAlterSchemaIndexes | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testAlteringTableParameters() {
App::import('Model', 'CakeSchema');
$this->db->cacheSources = false;
$schema1 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
'tableParameters' => array(
'charset' => 'latin1',
'collate' => 'latin1_general_ci',
'engine' => 'MyISAM'
)
)
));
$this->db->query($this->db->createSchema($schema1));
$schema2 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
'tableParameters' => array(
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
'engine' => 'InnoDB'
)
)
));
$result = $this->db->alterSchema($schema2->compare($schema1));
$this->assertPattern('/DEFAULT CHARSET=utf8/', $result);
$this->assertPattern('/ENGINE=InnoDB/', $result);
$this->assertPattern('/COLLATE=utf8_general_ci/', $result);
$this->db->query($result);
$result = $this->db->listDetailedSources('altertest');
$this->assertEqual($result['Collation'], 'utf8_general_ci');
$this->assertEqual($result['Engine'], 'InnoDB');
$this->assertEqual($result['charset'], 'utf8');
$this->db->query($this->db->dropSchema($schema1));
} | test altering the table settings with schema.
@return void | testAlteringTableParameters | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testAlteringTwoTables() {
$schema1 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
),
'other_table' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
)
));
$schema2 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'field_two' => array('type' => 'string', 'null' => false, 'length' => 50),
),
'other_table' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'field_two' => array('type' => 'string', 'null' => false, 'length' => 50),
)
));
$result = $this->db->alterSchema($schema2->compare($schema1));
$this->assertEqual(2, substr_count($result, 'field_two'), 'Too many fields');
} | test alterSchema on two tables.
@return void | testAlteringTwoTables | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testReadTableParameters() {
$this->db->cacheSources = false;
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;');
$result = $this->db->readTableParameters('tinyint');
$expected = array(
'charset' => 'utf8',
'collate' => 'utf8_unicode_ci',
'engine' => 'InnoDB');
$this->assertEqual($result, $expected);
$this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint'));
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;');
$result = $this->db->readTableParameters('tinyint');
$expected = array(
'charset' => 'cp1250',
'collate' => 'cp1250_general_ci',
'engine' => 'MyISAM');
$this->assertEqual($result, $expected);
$this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint'));
} | testReadTableParameters method
@access public
@return void | testReadTableParameters | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testBuildTableParameters() {
$this->db->cacheSources = false;
$data = array(
'charset' => 'utf8',
'collate' => 'utf8_unicode_ci',
'engine' => 'InnoDB');
$result = $this->db->buildTableParameters($data);
$expected = array(
'DEFAULT CHARSET=utf8',
'COLLATE=utf8_unicode_ci',
'ENGINE=InnoDB');
$this->assertEqual($result, $expected);
} | testBuildTableParameters method
@access public
@return void | testBuildTableParameters | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testGetCharsetName() {
$this->db->cacheSources = false;
$result = $this->db->getCharsetName('utf8_unicode_ci');
$this->assertEqual($result, 'utf8');
$result = $this->db->getCharsetName('cp1250_general_ci');
$this->assertEqual($result, 'cp1250');
} | testBuildTableParameters method
@access public
@return void | testGetCharsetName | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testVirtualFieldSeparators() {
$model =& new CakeTestModel(array('table' => 'binary_tests', 'ds' => 'test_suite', 'name' => 'BinaryTest'));
$model->virtualFields = array(
'other__field' => 'SUM(id)'
);
$this->db->virtualFieldSeparator = '_$_';
$result = $this->db->fields($model, null, array('data', 'other__field'));
$expected = array('`BinaryTest`.`data`', '(SUM(id)) AS `BinaryTest_$_other__field`');
$this->assertEqual($result, $expected);
} | test that changing the virtualFieldSeparator allows for __ fields.
@return void | testVirtualFieldSeparators | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testDescribeGettingFieldParameters() {
$schema =& new CakeSchema(array(
'connection' => 'test_suite',
'testdescribes' => array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'stringy' => array(
'type' => 'string',
'null' => true,
'charset' => 'cp1250',
'collate' => 'cp1250_general_ci',
),
'other_col' => array(
'type' => 'string',
'null' => false,
'charset' => 'latin1',
'comment' => 'Test Comment'
)
)
));
$this->db->execute($this->db->createSchema($schema));
$model =& new CakeTestModel(array('table' => 'testdescribes', 'name' => 'Testdescribes'));
$result = $this->db->describe($model);
$this->assertEqual($result['stringy']['collate'], 'cp1250_general_ci');
$this->assertEqual($result['stringy']['charset'], 'cp1250');
$this->assertEqual($result['other_col']['comment'], 'Test Comment');
$this->db->execute($this->db->dropSchema($schema));
} | test that a describe() gets additional fieldParameters
@return void | testDescribeGettingFieldParameters | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testSimpleDeleteConditionsNoJoins() {
$model =& new Post();
$mockDbo =& new QueryMockDboMysql($this);
$mockDbo->expectAt(0, 'execute', array(new PatternExpectation('/AS\s+`Post`\s+WHERE\s+`Post/')));
$mockDbo->setReturnValue('execute', true);
$mockDbo->delete($model, array('Post.id' => 1));
} | test that simple delete conditions don't create joins using a mock.
@return void | testSimpleDeleteConditionsNoJoins | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testDeleteWithJoins() {
$model =& new Post();
$mockDbo =& new QueryMockDboMysql($this);
$mockDbo->expectAt(0, 'execute', array(new PatternExpectation('/LEFT JOIN `authors`/')));
$mockDbo->setReturnValue('execute', true);
$mockDbo->delete($model, array('Author.id' => 1));
} | test deleting with joins, a MySQL specific feature.
@return void | testDeleteWithJoins | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function testDeleteWithJoinsAndMultipleConditions() {
$model =& new Post();
$mockDbo =& new QueryMockDboMysql($this);
$mockDbo->expectAt(0, 'execute', array(new PatternExpectation('/LEFT JOIN `authors`/')));
$mockDbo->expectAt(1, 'execute', array(new PatternExpectation('/LEFT JOIN `authors`/')));
$mockDbo->setReturnValue('execute', true);
$mockDbo->delete($model, array('Author.id' => 1, 'Post.id' => 2));
$mockDbo->delete($model, array('Post.id' => 2, 'Author.id' => 1));
} | test joins on delete with multiple conditions.
@return void | testDeleteWithJoinsAndMultipleConditions | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php | MIT |
function _execute($sql) {
if ($this->testing) {
$this->simulated[] = $sql;
return null;
}
return parent::_execute($sql);
} | execute method
@param mixed $sql
@access protected
@return void | _execute | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function getLastQuery() {
return $this->simulated[count($this->simulated) - 1];
} | getLastQuery method
@access public
@return void | getLastQuery | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function schema() {
return array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
} | schema method
@access public
@return void | schema | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function skip() {
$this->_initDb();
$this->skipUnless($this->db->config['driver'] == 'mysqli', '%s MySQLi connection not available');
} | Skip if cannot connect to mysqli
@access public | skip | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function setUp() {
$this->model = new MysqliTestModel();
} | Sets up a Dbo class instance for testing
@access public | setUp | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function tearDown() {
unset($this->model);
ClassRegistry::flush();
} | Sets up a Dbo class instance for testing
@access public | tearDown | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function testIndexDetection() {
$this->db->cacheSources = false;
$name = $this->db->fullTableName('simple');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
$expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1));
$result = $this->db->index($name, false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
$name = $this->db->fullTableName('with_a_key');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ));');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
);
$result = $this->db->index($name, false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
$name = $this->db->fullTableName('with_two_keys');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ));');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
);
$result = $this->db->index($name, false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
$name = $this->db->fullTableName('with_compound_keys');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ));');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
);
$result = $this->db->index($name, false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
$name = $this->db->fullTableName('with_multiple_compound_keys');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ), KEY `other_way` ( `small_int`, `bool` ));');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0),
);
$result = $this->db->index($name, false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
} | testIndexDetection method
@return void
@access public | testIndexDetection | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function testColumn() {
$result = $this->db->column('varchar(50)');
$expected = 'string';
$this->assertEqual($result, $expected);
$result = $this->db->column('text');
$expected = 'text';
$this->assertEqual($result, $expected);
$result = $this->db->column('int(11)');
$expected = 'integer';
$this->assertEqual($result, $expected);
$result = $this->db->column('int(11) unsigned');
$expected = 'integer';
$this->assertEqual($result, $expected);
$result = $this->db->column('tinyint(1)');
$expected = 'boolean';
$this->assertEqual($result, $expected);
$result = $this->db->column('boolean');
$expected = 'boolean';
$this->assertEqual($result, $expected);
$result = $this->db->column('float');
$expected = 'float';
$this->assertEqual($result, $expected);
$result = $this->db->column('float unsigned');
$expected = 'float';
$this->assertEqual($result, $expected);
$result = $this->db->column('double unsigned');
$expected = 'float';
$this->assertEqual($result, $expected);
$result = $this->db->column('decimal(14,7) unsigned');
$expected = 'float';
$this->assertEqual($result, $expected);
} | testColumn method
@return void
@access public | testColumn | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function testTransactions() {
$this->db->testing = false;
$result = $this->db->begin($this->model);
$this->assertTrue($result);
$beginSqlCalls = Set::extract('/.[query=START TRANSACTION]', $this->db->_queriesLog);
$this->assertEqual(1, count($beginSqlCalls));
$result = $this->db->commit($this->model);
$this->assertTrue($result);
} | test transaction commands.
@return void
@access public | testTransactions | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function testFloatParsing() {
$model =& new Model(array('ds' => 'test_suite', 'table' => 'datatypes', 'name' => 'Datatype'));
$result = $this->db->describe($model);
$this->assertEqual((string)$result['float_field']['length'], '5,2');
} | test that float values are correctly identified
@return void | testFloatParsing | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function testReadTableParameters() {
$this->db->cacheSources = $this->db->testing = false;
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;');
$result = $this->db->readTableParameters('tinyint');
$expected = array(
'charset' => 'utf8',
'collate' => 'utf8_unicode_ci',
'engine' => 'InnoDB');
$this->assertEqual($result, $expected);
$this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint'));
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;');
$result = $this->db->readTableParameters('tinyint');
$expected = array(
'charset' => 'cp1250',
'collate' => 'cp1250_general_ci',
'engine' => 'MyISAM');
$this->assertEqual($result, $expected);
$this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint'));
} | test that tableParameters like collation, charset and engine are functioning.
@access public
@return void | testReadTableParameters | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php | MIT |
function skip() {
$this->_initDb();
$this->skipUnless($this->db->config['driver'] == 'oracle', '%s Oracle connection not available');
} | skip method
@access public
@return void | skip | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php | MIT |
function testLastErrorStatement() {
if ($this->skip('testLastErrorStatement')) {
return;
}
$this->expectError();
$this->db->execute("SELECT ' FROM dual");
$e = $this->db->lastError();
$r = 'ORA-01756: quoted string not properly terminated';
$this->assertEqual($e, $r);
} | testLastErrorStatement method
@access public
@return void | testLastErrorStatement | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php | MIT |
function testLastErrorConnect() {
if ($this->skip('testLastErrorConnect')) {
return;
}
$config = $this->db->config;
$old_pw = $this->db->config['password'];
$this->db->config['password'] = 'keepmeout';
$this->db->connect();
$e = $this->db->lastError();
$r = 'ORA-01017: invalid username/password; logon denied';
$this->assertEqual($e, $r);
$this->db->config['password'] = $old_pw;
$this->db->connect();
} | testLastErrorConnect method
@access public
@return void | testLastErrorConnect | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php | MIT |
function testName() {
$Db = $this->db;
#$Db =& new DboOracle($config = null, $autoConnect = false);
$r = $Db->name($Db->name($Db->name('foo.last_update_date')));
$e = 'foo.last_update_date';
$this->assertEqual($e, $r);
$r = $Db->name($Db->name($Db->name('foo._update')));
$e = 'foo."_update"';
$this->assertEqual($e, $r);
$r = $Db->name($Db->name($Db->name('foo.last_update_date')));
$e = 'foo.last_update_date';
$this->assertEqual($e, $r);
$r = $Db->name($Db->name($Db->name('last_update_date')));
$e = 'last_update_date';
$this->assertEqual($e, $r);
$r = $Db->name($Db->name($Db->name('_update')));
$e = '"_update"';
$this->assertEqual($e, $r);
} | testName method
@access public
@return void | testName | php | Datawalke/Coordino | cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.