Login   Register  
PHP Classes
elePHPant
Icontem

File: urlTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Gergely Aradszki  >  URL handler  >  urlTest.php  >  Download  
File: urlTest.php
Role: Unit test script
Content type: text/plain
Description: test
Class: URL handler
Create and manipulate URLs
Author: By
Last change: test update
Date: 3 years ago
Size: 3,700 bytes
 

Contents

Class file image Download
<?php
require_once 'core/helpers/url.php';
class 
URLTest extends PHPUnit_Framework_TestCase {   

    function 
SetUp() {
        
$_SERVER['REQUEST_URI'] = "/test/path/?f=1#foo";
        
$_SERVER['HTTP_HOST'] = "test.example.com";
    }    
    function 
testGet() {                
        
$this->assertEquals("/test/path/?f=1"URL::get());
    }
    function 
testAdd(){
        
$this->assertEquals("/test/path/?f=1&amp;x=1"URL::add('x',1));
        
$this->assertEquals("/test/path/?f=1&amp;y=2"URL::add(Array('y'=>2)));
        
$this->assertEquals("/test/path/?f=1&amp;a=b&amp;c=d"URL::add(Array('a'=>'b','c'=>'d')));
        
        
$url URL::add(Array('y'=>2));
        
$this->assertEquals("/test/path/?f=1&amp;y=2"URL::get($url));
        
$this->assertEquals("/test/path/?f=1&amp;y=2&amp;x=3"URL::add('x'3$url));
        
$this->assertEquals("/test/path/?f=1&amp;y=2&amp;b=5&amp;v=4"URL::add(Array('b'=> 5'v'=>4),false$url));
        
$this->assertEquals("/test/path/?f=1&amp;y=2&amp;d=5&amp;z=4"$url URL::add(Array('d'=> 5'z'=>4),false$url));
        
$this->assertEquals("/test/path/?f=1&amp;y=2&amp;z=4"URL::remove('d'$url));
        
$this->assertEquals("/test/path/"URL::remove(false$url));
    }
    function 
testIgnore(){
        
$url URL::add(Array('y'=>2,'x'=>3));
        
URL::ignore('x');
        
$this->assertEquals("/test/path/?f=1&amp;y=2"URL::get($url));
    }
    function 
testPath(){
        
$this->assertEquals("/test/mod/path/"URL::path('test/mod/path'));
        
$this->assertEquals("/test/mod/path2/"URL::path('test','mod','path2'));
        
$this->assertEquals("/test/mod/path3/"URL::path(Array('test','mod','path3')));
    }
    function 
testFile(){
        
$this->assertEquals("/test/mod/file"URL::file('test/mod/file'));
        
$this->assertEquals("/test/mod/file2"URL::file('test','mod','file2'));
        
$this->assertEquals("/test/mod/file3"URL::file(Array('test','mod','file3')));
    }
    function 
testCanonical(){
        
$this->assertEquals("http://test.example.com/test/path/"URL::canonical());
        
$this->assertEquals("http://test.example.com/test/path/?f=1"URL::canonical(falsetrue));
        
        
URL::protocol('https');
        
$this->assertEquals("https://test.example.com/test/path/"URL::canonical());
    }
    function 
testHash(){
        
$this->assertEquals("/test/path/?f=1#testhash"URL::hash('testhash'));
    }
    function 
testArgs(){        
        
$this->assertEquals(Array('f'=>1), URL::args());
        
        
$url URL::add('t',3);
        
$this->assertEquals(Array('f'=>1't'=>3), URL::args(falsefalse ,$url));
        
        
$url = new URL();
        
$url->add('t',2);
        
$this->assertEquals(Array('f'=>1't'=>2), $url->args());
    }
    
/**
     * @test
     */
    
function instanceTest(){
        
$url = new URL();
        
        
ob_start();
            echo 
$url;
        
$str ob_get_clean();
        
        
$this->assertEquals("/test/path/?f=1"$str);
        
$this->assertEquals("/test/path/?f=1&amp;c=4"$url->add('c',4));
        
$this->assertEquals("/test/path/?f=1&amp;c=4&amp;z=5"$url->add('z',5));
        
$this->assertEquals("/test/path/?f=1&amp;z=5"$url->remove('c'));
    }
    
    
/*
     * @test
     */
    
function testArray(){
        
$this->assertEquals("/test/path/?f=1&amp;a[0]=1&amp;a[1]=2"urldecode(URL::add('a',Array(1,2))));
        
$this->assertEquals("/test/path/?f=1&amp;a[a]=1&amp;a[b]=2"urldecode(URL::add('a',Array('a'=>1,'b'=>2))));
        
        
$url = new URL();
        
$this->assertEquals("/test/path/?f=1&amp;x[a]=1&amp;x[b]=2"urldecode($url->add('x',Array('a'=>1,'b'=>2))));        
    }
}
?>