PHP Classes

File: tests/util-tests/UrlParserTest.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP Generics   tests/util-tests/UrlParserTest.php   Download  
File: tests/util-tests/UrlParserTest.php
Role: Unit test script
Content type: text/plain
Description: UrlParser class test
Class: PHP Generics
Framework for accessing streams, sockets and logs
Author: By
Last change: Update of tests/util-tests/UrlParserTest.php
Date: 7 months ago
Size: 2,586 bytes
 

Contents

Class file image Download
<?php

namespace Generics\Tests;

use
Generics\Util\UrlParser;

class
UrlParserTest extends \PHPUnit\Framework\TestCase
{
    public function
testUrlParser()
    {
       
$urlToParse = "http://www.nkey.de/index.php";

       
$url = UrlParser::parseUrl($urlToParse);

       
$this->assertEquals(80, $url->getPort());
       
$this->assertEquals('/index.php', $url->getPath());
       
$this->assertEquals('http', $url->getScheme());
       
$this->assertEquals('www.nkey.de', $url->getAddress());
    }

    public function
testUrlParserSimpleUrl()
    {
       
$urlToParse = "http://www.nkey.de";

       
$url = UrlParser::parseUrl($urlToParse);

       
$this->assertEquals(80, $url->getPort());
       
$this->assertEquals('/', $url->getPath());
       
$this->assertEquals('http', $url->getScheme());
       
$this->assertEquals('www.nkey.de', $url->getAddress());
       
$this->assertEmpty($url->getQueryString());
       
$this->assertEquals($urlToParse . "/", $url->getUrlString());
    }

    public function
testQueryString()
    {
       
$urlToParse = "http://www.nkey.de/?param=1&func=print";
       
$url = UrlParser::parseUrl($urlToParse);

       
$this->assertEquals(80, $url->getPort());
       
$this->assertEquals('/', $url->getPath());
       
$this->assertEquals('http', $url->getScheme());
       
$this->assertEquals('www.nkey.de', $url->getAddress());
       
$this->assertEquals('param=1&func=print', $url->getQueryString());
       
$this->assertEquals($urlToParse, $url->getUrlString());
    }

   
/**
     * @expectedException \Generics\Socket\InvalidUrlException
     * @expectedExceptionMessage does not contain necessary parts
     */
   
public function testInvalidHost()
    {
       
UrlParser::parseUrl("http:///abc");
    }

   
/**
     * @expectedException \Generics\Socket\InvalidUrlException
     * @expectedExceptionMessage does not contain necessary parts
     */
   
public function testInvalidScheme()
    {
       
UrlParser::parseUrl("//www.nkey.de/");
    }

   
/**
     * @expectedException \Generics\Socket\InvalidUrlException
     * @expectedExceptionMessage Scheme file is not handled!
     */
   
public function testUnhandledScheme()
    {
       
UrlParser::parseUrl("file://www.nkey.de/");
    }

    public function
testUrlWithPort()
    {
       
$url = UrlParser::parseUrl("http://www.nkey.de:80/index.php");
       
$this->assertEquals(80, $url->getPort());
    }

    public function
testFtpUrl()
    {
       
$url = UrlParser::parseUrl("ftp://www.nkey.de/");
       
$this->assertEquals(21, $url->getPort());
    }
}