merging from my sandbox

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@798 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-09-11 12:45:10 +00:00
parent f6662921c2
commit e640ab7596
3 changed files with 87 additions and 4 deletions

View file

@ -1306,7 +1306,7 @@ class Model extends Object
$merged = array_merge_recursive($data[$count],$oneToManySelect1);
$newdata[$count] = $merged;
//added fix from Ticket #188
// Added fix from Ticket #188
// I had this in code before and removed
// If this cause problems may need to look into it more -PhpNut
unset( $oneToManySelect[$table], $oneToManySelect1);
@ -1364,7 +1364,9 @@ class Model extends Object
}
$merged = array_merge_recursive($data[$count],$manyToManySelect1);
$newdata[$count] = $merged;
unset( $manyToManySelect[$table] );
// I had this in code before and removed
// If this cause problems may need to look into it more -PhpNut
unset( $manyToManySelect[$table], $manyToManySelect1 );
}
if(!empty($newdata[$count]))
{
@ -1373,10 +1375,13 @@ class Model extends Object
}
}
}
$count++;
}
$this->joinedHasAndBelongs[] = new NeatArray($this->db->fields($table));
}
if(!empty($original))
{
$data = $original;

View file

@ -101,7 +101,11 @@ class NeatArray
$out = is_array($this->value)? array(): null;
foreach ($this->value as $k=>$v)
{
if ($v)
if ($v == "0")
{
$out[$k] = $v;
}
elseif ($v)
{
$out[$k] = $v;
}

View file

@ -30,6 +30,10 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
require_once LIBS.'basics.php';
require_once LIBS.'dispatcher.php';
/**
* Short description for class.
*
@ -39,6 +43,76 @@
*/
class DispatcherTest extends UnitTestCase
{
function testParseParamsWithoutZerosAndEmptyPost()
{
$dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3");
$this->assertIdentical($test['controller'], 'testcontroller', "<br />Parsed URL shows controller is {$test['controller']} expected testcontroller" );
$this->assertIdentical($test['action'], 'testaction', "<br />Parsed URL shows action is {$test['action']} expected testaction" );
$this->assertIdentical($test['pass'][0], 'params1', "<br />Parsed URL shows action is {$test['pass'][0]} expected params1" );
$this->assertIdentical($test['pass'][1], 'params2', "<br />Parsed URL shows action is {$test['pass'][1]} expected params2" );
$this->assertIdentical($test['pass'][2], 'params3', "<br />Parsed URL shows action is {$test['pass'][2]} expected params3" );
$this->assertFalse($test['form'], "<br />Parsed URL returning post data expected not post data");
}
function testParseParamsReturnsPostedData()
{
$_POST['testdata'] = "My Posted Content";
$dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/");
$this->assertTrue($test['form'], "Parsed URL not returning post data");
$this->assertIdentical($test['form']['testdata'],
"My Posted Content",
"'Post content is {$test['form']['testdata']} expected My Posted Content");
}
function testParseParamsWithSingleZero()
{
$dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/1/0/23");
$this->assertIdentical($test['controller'], 'testcontroller', "<br />Parsed URL shows controller is {$test['controller']} expected testcontroller" );
$this->assertIdentical($test['action'], 'testaction', "<br />Parsed URL shows action is {$test['action']} expected testaction" );
$this->assertIdentical($test['pass'][0], '1', "value is {$test['pass'][0]} expected 1" );
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1], "value is {$test['pass'][1]} expected 0" );
$this->assertIdentical($test['pass'][2], '23', "value is {$test['pass'][2]} expected 23" );
}
function testParseParamsWithManySingleZeros()
{
$dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0");
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0], "value is {$test['pass'][0]} expected 0" );
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1], "value is {$test['pass'][1]} expected 0" );
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2], "value is {$test['pass'][2]} expected 0" );
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][3], "value is {$test['pass'][3]} expected 0" );
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][4], "value is {$test['pass'][4]} expected 0" );
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][5], "value is {$test['pass'][5]} expected 0" );
}
function testParseParamsWithManyZerosInEachSectionOfUrl()
{
$dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
$this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0], "value is {$test['pass'][0]} expected 000" );
$this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1], "value is {$test['pass'][1]} expected 0000" );
$this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2], "value is {$test['pass'][2]} expected 00000" );
$this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][3], "value is {$test['pass'][3]} expected 000000" );
$this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][4], "value is {$test['pass'][4]} expected 000000" );
$this->assertPattern('/\\A(?:0000000)\\z/', $test['pass'][5], "value is {$test['pass'][5]} expected 0000000" );
}
function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl()
{
$dispatcher =& new Dispatcher();
$test = $dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
$this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0], "value is {$test['pass'][0]} expected 01" );
$this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1], "value is {$test['pass'][1]} expected 0403" );
$this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2], "value is {$test['pass'][2]} expected 04010" );
$this->assertPattern('/\\A(?:000002)\\z/', $test['pass'][3], "value is {$test['pass'][3]} expected 000002" );
$this->assertPattern('/\\A(?:000030)\\z/', $test['pass'][4], "value is {$test['pass'][4]} expected 000030" );
$this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5], "value is {$test['pass'][5]} expected 0000400" );
}
}
?>