PHP Classes

File: tests/RouterAdvancedTest.php

Recommend this page to a friend!
  Classes of Mark Rolich   PHP URL Router Class   tests/RouterAdvancedTest.php   Download  
File: tests/RouterAdvancedTest.php
Role: Unit test script
Content type: text/plain
Description: new test for static and dynamic parts mix in the route
Class: PHP URL Router Class
Match URLs with routes for controllers and actions
Author: By
Last change: Update of tests/RouterAdvancedTest.php
Date: 4 months ago
Size: 2,318 bytes
 

Contents

Class file image Download
<?php
use Bike\Router;

class
RouterAdvancedTest extends PHPUnit_Framework_TestCase
{
    public function
testStatic()
    {
       
$router = new Router();

       
$router->add('static',
            array(
               
'method' => 'GET, POST',
               
'route' => '/some/static/path',
               
'defaults' => array(
                   
'controller' => 'index',
                   
'action' => 'index',
                   
'format' => 'html'
               
)
            )
        );

       
$result = $router->match('GET', '/some/static/path');

       
$expected = array(
           
'url' => array(
               
'static0' => 'some',
               
'static1' => 'static',
               
'static2' => 'path'
           
),
           
'id' => 'static',
           
'method' => array(
               
0 => 'GET',
               
1 => 'POST'
           
),
           
'data' => array(
               
'controller' => 'index',
               
'action' => 'index',
               
'format' => 'html',
               
'static0' => 'some',
               
'static1' => 'static',
               
'static2' => 'path'
           
)
        );

       
$this->assertSame($expected, $result);
    }

    public function
testStaticAndDynamic()
    {
       
$router = new Router();

       
$router->add('static-and-dynamic',
            array(
               
'method' => 'GET, POST',
               
'route' => '/r/$subreddit/comments/#thread_id/$thread_slug/'
           
)
        );

       
$result = $router->match('GET', '/r/php/comments/12/router/');

       
$expected = array(
           
'url' => array(
               
'static0' => 'r',
               
'subreddit' => 'php',
               
'static1' => 'comments',
               
'thread_id' => '12',
               
'thread_slug' => 'router'
           
),
           
'id' => 'static-and-dynamic',
           
'method' => array(
               
0 => 'GET',
               
1 => 'POST'
           
),
           
'data' => array(
               
'static0' => 'r',
               
'subreddit' => 'php',
               
'static1' => 'comments',
               
'thread_id' => '12',
               
'thread_slug' => 'router',
               
'action' => 'view'
           
)
        );

       
$this->assertSame($expected, $result);
    }
}