Adding tests for DboSource and AjaxHelper, and fixing code formatting in XmlHelper

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4482 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-02-08 22:16:35 +00:00
parent 9468feec18
commit 8a025938b5
4 changed files with 35 additions and 6 deletions

View file

@ -249,11 +249,7 @@ class XmlHelper extends AppHelper {
if (!class_exists('XML') && !class_exists('xml')) {
uses('xml');
}
$options = am(
array('attributes' => false, 'format' => 'xml'),
$options
);
$options = am(array('attributes' => false, 'format' => 'xml'), $options);
switch ($options['format']) {
case 'xml':

View file

@ -33,7 +33,7 @@
require_once LIBS.'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aclnode.php';
require_once LIBS.'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aco.php';
require_once LIBS.'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aro.php';
require_once LIBS.'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aros_aco.php';
require_once LIBS.'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'permission.php';
/**
* Short description for class.
*

View file

@ -183,6 +183,10 @@ class DboSourceTest extends UnitTestCase {
$result = $this->db->conditions('NOT Post.title_extended IS NULL AND NOT Post.title IS NULL AND Post.title_extended != Post.title');
$expected = ' WHERE NOT `Post`.`title_extended` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title_extended` != `Post`.`title`';
$this->assertEqual($result, $expected);
$result = $this->db->conditions("Comment.id = 'a'");
$expected = " WHERE `Comment`.`id` = 'a'";
$this->assertEqual($result, $expected);
}
function testArrayConditionsParsing() {
@ -205,6 +209,14 @@ class DboSourceTest extends UnitTestCase {
$result = $this->db->conditions(array('SUM(Post.comments_count)' => '> 500'));
$expected = " WHERE SUM(`Post`.`comments_count`) > 500";
$this->assertEqual($result, $expected);
$result = $this->db->conditions(array('title' => 'LIKE %hello'));
$expected = " WHERE (`title` LIKE '%hello')";
$this->assertEqual($result, $expected);
$result = $this->db->conditions(array('Post.name' => 'mad(g)ik'));
$expected = " WHERE (`Post`.`name` mad(g) 'ik')";
$this->assertEqual($result, $expected);
}
function testFieldParsing() {
@ -229,6 +241,10 @@ class DboSourceTest extends UnitTestCase {
$expected = array('TestModel.field_name' => '= value');
$this->assertEqual($result, $expected);
$result = $this->db->query('findAllById', array('a'), $this->model);
$expected = array('TestModel.id' => '= value');
$this->assertEqual($result, $expected);
$result = $this->db->query('findByFieldName', array(array('value1', 'value2', 'value3')), $this->model);
$expected = array('TestModel.field_name' => array('value1', 'value2', 'value3'));
$this->assertEqual($result, $expected);
@ -242,6 +258,12 @@ class DboSourceTest extends UnitTestCase {
$this->assertEqual($result, $expected);
}
function testOrderParsing() {
$result = $this->db->order("ADDTIME(Event.time_begin, '-06:00:00') ASC");
$expected = " ORDER BY ADDTIME(`Event`.`time_begin`, '-06:00:00') ASC";
$this->assertEqual($result, $expected);
}
function testSomething() {
$this->model->Test2 = new TestModel2();
$this->model->hasAndBelongsToMany = array('Test2' => array(

View file

@ -57,6 +57,11 @@ class AjaxTest extends UnitTestCase {
$this->assertEqual($result, $expected);
}
function testAutoComplete() {
//$result = $this->ajax->autoComplete('Post/title' , '/posts', array('minChars' => 2));
//pr($result);
}
function testAsynchronous() {
$result = $this->ajax->link('Test Link', '/', array('id' => 'link1', 'update' => 'content', 'type' => 'synchronous'));
$expected = '<a href="/" id="link1" onclick=" return false;">Test Link</a><script type="text/javascript">Event.observe(\'link1\', \'click\', function(event){ new Ajax.Updater(\'content\',\'/\', {asynchronous:false, evalScripts:true, requestHeaders:[\'X-Update\', \'content\']}) }, false);</script>';
@ -69,6 +74,12 @@ class AjaxTest extends UnitTestCase {
$this->assertEqual($result, $expected);
}
function testDroppable() {
$result = $this->ajax->drop('droppable', array('accept' => 'crap'));
$expected = '<script type="text/javascript">Droppables.add(\'droppable\', {accept:\'crap\'});</script>';
$this->assertEqual($result, $expected);
}
function tearDown() {
unset($this->ajax);
}