Skip to content

Commit 636188e

Browse files
committed
Adding tests for array named params from router test to cakeroute test.
1 parent cf26a8e commit 636188e

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

cake/tests/cases/libs/route/cake_route.test.php

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,73 @@ function testPassedArgumentParsing() {
490490
'named' => array()
491491
);
492492
$this->assertEquals($expected, $result);
493-
494-
$result = $route->parse('/posts/edit/a-string/page:1');
493+
494+
$result = $route->parse('/posts/edit/a-string/page:1/sort:value');
495495
$expected = array(
496496
'controller' => 'posts',
497497
'action' => 'edit',
498498
'pass' => array('a-string'),
499499
'named' => array(
500-
'page' => 1
500+
'page' => 1,
501+
'sort' => 'value'
501502
)
502503
);
503504
$this->assertEquals($expected, $result);
504505
}
506+
507+
/**
508+
* test that parsing array format named parameters works
509+
*
510+
* @return void
511+
*/
512+
function testArrayNamedParameters() {
513+
$route = new CakeRoute('/:controller/:action/*');
514+
$result = $route->parse('/tests/action/var[]:val1/var[]:val2');
515+
$expected = array(
516+
'controller' => 'tests',
517+
'action' => 'action',
518+
'named' => array(
519+
'var' => array(
520+
'val1',
521+
'val2'
522+
)
523+
),
524+
'pass' => array(),
525+
);
526+
$this->assertEqual($result, $expected);
527+
528+
$result = $route->parse('/tests/action/theanswer[is]:42/var[]:val2/var[]:val3');
529+
$expected = array(
530+
'controller' => 'tests',
531+
'action' => 'action',
532+
'named' => array(
533+
'theanswer' => array(
534+
'is' => 42
535+
),
536+
'var' => array(
537+
'val2',
538+
'val3'
539+
)
540+
),
541+
'pass' => array(),
542+
);
543+
$this->assertEqual($result, $expected);
544+
545+
$result = $route->parse('/tests/action/theanswer[is][not]:42/theanswer[]:5/theanswer[is]:6');
546+
$expected = array(
547+
'controller' => 'tests',
548+
'action' => 'action',
549+
'named' => array(
550+
'theanswer' => array(
551+
5,
552+
'is' => array(
553+
6,
554+
'not' => 42
555+
)
556+
),
557+
),
558+
'pass' => array(),
559+
);
560+
$this->assertEqual($result, $expected);
561+
}
505562
}

0 commit comments

Comments
 (0)