Created
July 4, 2012 16:44
-
-
Save Maks3w/3048257 to your computer and use it in GitHub Desktop.
Uri test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Zend Framework | |
* | |
* LICENSE | |
* | |
* This source file is subject to the new BSD license that is bundled | |
* with this package in the file LICENSE.txt. | |
* It is also available through the world-wide-web at this URL: | |
* http://framework.zend.com/license/new-bsd | |
* If you did not receive a copy of the license and are unable to | |
* obtain it through the world-wide-web, please send an email | |
* to license@zend.com so we can send you a copy immediately. | |
* | |
* @category Zend | |
* @package Zend_Uri | |
* @subpackage UnitTests | |
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | |
* @license http://framework.zend.com/license/new-bsd New BSD License | |
* @version $Id $ | |
*/ | |
namespace ZendTest\Uri; | |
use Zend\Uri\UriFactory; | |
use Zend\Uri\Exception\InvalidUriPartException; | |
/** | |
* @category Zend | |
* @package Zend_Uri | |
* @subpackage UnitTests | |
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | |
* @license http://framework.zend.com/license/new-bsd New BSD License | |
* @group Zend_Uri | |
*/ | |
class UriFactoryTest extends \PHPUnit_Framework_TestCase | |
{ | |
/** | |
* General composing / parsing tests | |
*/ | |
/** | |
* Test that the URIs are valid | |
* | |
* @param string $uriString | |
* @dataProvider validUriStringProvider | |
*/ | |
public function testValidUris($uriString) | |
{ | |
$this->assertTrue(UriFactory::factory($uriString)->isValid(), | |
"Uri '$uriString' is not valid"); | |
} | |
/** | |
* Test that the global URI is invalid | |
* | |
* @param string $uriString | |
* @dataProvider invalidUriStringProvider | |
*/ | |
public function testInvalidUris($uriString) | |
{ | |
$uri = UriFactory::factory($uriString); | |
$this->assertFalse($uri->isValid(), | |
"Uri '$uriString' is valid"); | |
} | |
/** | |
* Test that the URIs are invalid | |
* | |
* @param string $uriString | |
* @param int $errorCode | |
* @dataProvider invalidUriPartsProvider | |
*/ | |
public function testInvalidUriParts($uriString, $errorCode) | |
{ | |
$this->setExpectedException( | |
'Zend\Uri\Exception\InvalidUriPartException', | |
null, | |
$errorCode | |
); | |
UriFactory::factory($uriString); | |
} | |
/** | |
* Data provider for valid URIs, not necessarily complete | |
* | |
* @return array | |
*/ | |
public function validUriStringProvider() | |
{ | |
return array( | |
array('a:b'), | |
array('http://www.zend.com'), | |
array('https://example.com:10082/foo/bar?query'), | |
array('../relative/path'), | |
array('?queryOnly'), | |
array('#fragmentOnly'), | |
array('mailto:bob@example.com'), | |
array('bob@example.com'), | |
array('http://a_.!~*\'(-)n0123Di%25%26:pass;:&=+$,word@www.zend.com'), | |
array('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html'), | |
array('http://[1080::8:800:200C:417A]/foo'), | |
array('http://[::192.9.5.5]/ipng'), | |
array('http://[::FFFF:129.144.52.38]:80/index.html'), | |
array('http://[2620:0:1cfe:face:b00c::3]/'), | |
array('http://[2010:836B:4179::836B:4179]'), | |
array('http'), | |
array('www.example.org:80'), | |
array('www.example.org:'), | |
array('www.example.org'), | |
array('http://foo'), | |
array('foo'), | |
array('ftp://user:pass@example.org/'), | |
array('www.fi/'), | |
array('http://1.1.1.1/'), | |
array('1.1.1.1'), | |
array('1.256.1.1'), // Hostnames can be only numbers | |
array('http://[::1]/'), | |
array('[::1]'), | |
array('[2620:0:1cfe:face:b00c::3]:80'), | |
array('[2620:0:1cfe:face:b00c::3]'), | |
array('file:/'), // schema without host | |
array('http:///'), // host empty | |
array('http:::/foo'), // relative path | |
array('http:'), // relative path | |
array('2620:0:1cfe:face:b00c::3'), // Not IPv6, is Path | |
); | |
} | |
/** | |
* Data provider for invalid URIs, not necessarily complete | |
* | |
* @return array | |
*/ | |
public function invalidUriStringProvider() | |
{ | |
return array( | |
array(''), | |
array('http:'), // Schema omitted, host = http, port = default | |
array('http://'), | |
array('[[2620:0:1cfe:face:b00c::3]]'), | |
); | |
} | |
/** | |
* Data provider for invalid URIs, not necessarily complete | |
* | |
* @return array | |
*/ | |
public function invalidUriPartsProvider() | |
{ | |
return array( | |
array('http://1080::8:800:200C:417A/foo', InvalidUriPartException::INVALID_HOSTNAME), // IPv6 without literal format | |
array('http://::/foo', InvalidUriPartException::INVALID_HOSTNAME), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment