summaryrefslogtreecommitdiff
path: root/tests/unit/Web/TUriTest.php
blob: 294898421bcb0ae679e6b62ee10e93a77a723868 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

use Prado\Exceptions\TInvalidDataValueException;
use Prado\Web\TUri;


/**
 * @package System.Web
 */
class TUriTest extends PHPUnit_Framework_TestCase {

  const URISTR='http://login:p@ssw0rd:compl3x@www.pradosoft.com:80/demos/quickstart/index.php?page=test&param1=test2#anchor';

  public function setUp () {
    $this->uri=new TUri(self::URISTR);
  }

  public function tearDown() {
    $this->uri=null;
  }

  public function testConstruct() {
    $url="http://www.pradosoft.com/";
    $uri=new TUri ($url);
    self::assertEquals($url, $uri->getUri() );
    // Bad uri test
	$url="http://www.pradosoft.com:badport/test";
	try {
	  $url=new TUri($url);
	  self::fail ('exception not raised with an invalid URL');
	} catch (TInvalidDataValueException $e) {

	}
  }

  public function testGetUri() {
    self::assertEquals(self::URISTR, $this->uri->getUri());
  }

  public function testGetScheme() {
    self::assertEquals('http', $this->uri->getScheme());
  }

  public function testGetHost() {
    self::assertEquals('www.pradosoft.com', $this->uri->getHost());
  }

  public function testGetPort() {
    self::assertEquals(80, $this->uri->getPort());
  }

  public function testGetUser() {
    self::assertEquals('login', $this->uri->getUser());
  }

  public function testGetPassword() {
    self::assertEquals('p@ssw0rd:compl3x', $this->uri->getPassword());
  }

  public function testGetPath() {
    self::assertEquals('/demos/quickstart/index.php', $this->uri->getPath());
  }

  public function testGetQuery() {
    self::assertEquals('page=test&param1=test2', $this->uri->getQuery());
  }

  public function testGetFragment() {
    self::assertEquals('anchor', $this->uri->getFragment());
  }
}