Example #1
0
 public function testSetSchemeOnProtocolRelativeUrl()
 {
     $url = new \webignition\Url\Url('//example.com');
     $url->setScheme('http');
     $this->assertEquals('http', $url->getScheme());
     $this->assertEquals('http://example.com', (string) $url);
 }
Example #2
0
 public function testRemove()
 {
     $url = new \webignition\Url\Url('http://example.com/?key1=value&key2=value2&key3=value3');
     $url->getQuery()->remove('key3');
     $this->assertFalse($url->getQuery()->contains('key3'));
     $this->assertEquals('key1=value&key2=value2', (string) $url->getQuery());
 }
 public function testWithoutFilename()
 {
     $url = new \webignition\Url\Url('http://www.example.com/path/is/here');
     $this->assertFalse($url->getPath()->hasFilename());
     $this->assertEquals('/path/is/here', $url->getPath()->getDirectory());
     $this->assertEquals('', $url->getPath()->getFilename());
 }
 public function testMinimalEncodingWithEncodableKeysContainingVerySpecialCharacters()
 {
     $query = 'a%23a=1&b%26b=2&c!c=3';
     $url = new \webignition\Url\Url('http://example.com/?' . $query);
     $url->getConfiguration()->disableFullyEncodeQueryStringKeys();
     $this->assertEquals($query, (string) $url->getQuery());
 }
Example #5
0
 public function testProtocolRelativeHasUsernameNoPassword()
 {
     $url = new \webignition\Url\Url('//username@example.com');
     $this->assertTrue($url->hasUser());
     $this->assertEquals('username', $url->getUser());
     $this->assertFalse($url->hasPass());
 }
Example #6
0
 public function testSetPathWhenExistingPathIsUrlEncoded()
 {
     $url = new \webignition\Url\Url('js/scriptaculous.js?load=effects,builder');
     $this->assertEquals('js/scriptaculous.js?load=effects%2Cbuilder', (string) $url);
     $url->setPath('/js/scriptaculous.js');
     $this->assertEquals('/js/scriptaculous.js?load=effects%2Cbuilder', (string) $url);
 }
Example #7
0
 public function testRootUrlIsConstantWithRespectToPath()
 {
     $url = new \webignition\Url\Url('http://example.com/');
     $this->assertEquals('http://example.com', $url->getRoot());
     $url = new \webignition\Url\Url('http://example.com/index.html');
     $this->assertEquals('http://example.com', $url->getRoot());
     $url = new \webignition\Url\Url('http://example.com/path/to/application.php');
     $this->assertEquals('http://example.com', $url->getRoot());
 }
Example #8
0
 public function testUnset()
 {
     $url = new \webignition\Url\Url('http://example.com:8080/');
     $this->assertTrue($url->hasPort());
     $this->assertEquals(8080, $url->getPort());
     $url->setPort(null);
     $this->assertFalse($url->hasPort());
     $this->assertEquals('http://example.com/', (string) $url);
 }
Example #9
0
 public function testAddPathToRootUrl()
 {
     $url = new \webignition\Url\Url('http://example.com');
     $url->setPath('/index.html');
     $this->assertEquals('http://example.com/index.html', (string) $url);
     $url = new \webignition\Url\Url('http://example.com/');
     $url->setPath('/index.html');
     $this->assertEquals('http://example.com/index.html', (string) $url);
 }
Example #10
0
 public function testIdnEquivalence()
 {
     $idnUrl1 = new \webignition\Url\Url('http://econom.ía.com');
     $idnUrl2 = new \webignition\Url\Url('http://econom.xn--a-iga.com');
     $idnUrl3 = new \webignition\Url\Url('http://ヒキワリ.ナットウ.ニホン');
     $idnUrl4 = new \webignition\Url\Url('http://xn--nckwd5cta.xn--gckxcpg.xn--idk6a7d');
     $idnUrl5 = new \webignition\Url\Url('http://транспорт.com');
     $idnUrl6 = new \webignition\Url\Url('http://xn--80a0addceeeh.com');
     $this->assertTrue($idnUrl1->getHost()->isEquivalentTo($idnUrl2->getHost()));
     $this->assertTrue($idnUrl3->getHost()->isEquivalentTo($idnUrl4->getHost()));
     $this->assertTrue($idnUrl5->getHost()->isEquivalentTo($idnUrl6->getHost()));
 }
Example #11
0
 /**
  * Checks if the given href is not part 
  * of the domain we are crawling
  *
  * @return boolean
  */
 public function isLeavingOriginDomain()
 {
     if ($this->origin_domain === null) {
         throw new \Exception('origin is null');
     }
     $domain = $this->origin_domain->getParser();
     $link = new \webignition\Url\Url($this->link_href);
     $domain_host = $domain->getHost();
     $link_host = $link->getHost();
     if ($link_host === null) {
         return false;
     }
     return !$domain_host->equals($link_host);
 }
Example #12
0
 public function testSet()
 {
     $url = new \webignition\Url\Url('http://example.com/?key1=value&key2=value2');
     $url->getQuery()->set('key3', 'value3');
     $this->assertTrue($url->getQuery()->contains('key3'));
     $this->assertEquals('key1=value&key2=value2&key3=value3', (string) $url->getQuery());
     $url->getQuery()->set('key4', 'value4');
     $this->assertEquals('key1=value&key2=value2&key3=value3&key4=value4', (string) $url->getQuery());
 }
 public function testAbsoluteUrlIsRecognisedAsAbsolute()
 {
     $url = new \webignition\Url\Url('http://example.com/absolute/url');
     $this->assertTrue($url->isAbsolute());
 }
 public function testAbsoluteUrlIsRecognisedAsNonRelative()
 {
     $url = new \webignition\Url\Url('http://example.com/absolute/url');
     $this->assertFalse($url->isProtocolRelative());
 }
Example #15
0
 public function testQueryContains()
 {
     $url = new \webignition\Url\Url('http://example.com/?key1=value&key2=value2');
     $this->assertTrue($url->getQuery()->contains('key1'));
     $this->assertFalse($url->getQuery()->contains('key3'));
 }
 public function testNullifySchemeMakesUrlProtocolRelative()
 {
     $url = new \webignition\Url\Url('http://example.com/foo/bar/index.html');
     $url->setScheme(null);
     $this->assertEquals('//example.com/foo/bar/index.html', (string) $url);
 }
 /**
  * 
  * @return string
  */
 private function findSitemapUrlsFromRobotsTxt()
 {
     $robotsTxtParser = new \webignition\RobotsTxt\File\Parser();
     $robotsTxtParser->setSource($this->getRobotsTxtContent());
     $robotsTxtFile = $robotsTxtParser->getFile();
     $urls = array();
     if ($robotsTxtFile->directiveList()->containsField('sitemap')) {
         $sitemapDirectives = $robotsTxtFile->directiveList()->filter(array('field' => 'sitemap'));
         foreach ($sitemapDirectives->get() as $sitemapDirective) {
             /* @var $sitemapDirective \webignition\RobotsTxt\Directive\Directive */
             $sitemapUrl = new \webignition\Url\Url((string) $sitemapDirective->getValue());
             if ($sitemapUrl->isRelative()) {
                 $absoluteUrlDeriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver((string) $sitemapUrl, $this->getConfiguration()->getRootUrl());
                 $urls[] = (string) $absoluteUrlDeriver->getAbsoluteUrl();
             } else {
                 $urls[] = (string) $sitemapUrl;
             }
         }
     }
     return $urls;
 }
Example #18
0
 public function testChangeFragmentWithHash()
 {
     $url = new \webignition\Url\Url('http://example.com/#fragment');
     $url->setFragment('#new-fragment');
     $this->assertEquals('new-fragment', $url->getFragment());
     $this->assertEquals('http://example.com/#new-fragment', (string) $url);
 }
Example #19
0
 public function testRelativeUrl()
 {
     $url = new \webignition\Url\Url($this->urls['relative']);
     $this->assertFalse($url->hasScheme());
     $this->assertNull($url->getScheme());
     $this->assertFalse($url->hasHost());
     $this->assertNull($url->getHost());
     $this->assertFalse($url->hasPort());
     $this->assertNull($url->getPort());
     $this->assertFalse($url->hasUser());
     $this->assertNull($url->getUser());
     $this->assertFalse($url->hasPass());
     $this->assertNull($url->getPass());
     $this->assertTrue($url->hasPath());
     $this->assertEquals($this->completePath(), $url->getPath());
     $this->assertTrue($url->hasQuery());
     $this->assertEquals($this->completeUrlQueryString(), $url->getQuery());
     $this->assertTrue($url->hasFragment());
     $this->assertEquals(self::FRAGMENT, $url->getFragment());
     $this->assertEquals($this->urls['relative'], (string) $url);
 }
Example #20
0
 public function testSetPathThenHostThenSchemeThenUser()
 {
     $url = new \webignition\Url\Url('example.php');
     $this->assertEquals('example.php', (string) $url);
     $url->setPath('/pathOne/Path2/path2/example2.php');
     $this->assertEquals('/pathOne/Path2/path2/example2.php', (string) $url);
     $url->setHost('www.example.com');
     $this->assertEquals('//www.example.com/pathOne/Path2/path2/example2.php', (string) $url);
     $url->setScheme('http');
     $this->assertEquals('http://www.example.com/pathOne/Path2/path2/example2.php', (string) $url);
     $url->setUser('user');
     $this->assertEquals('http://user:@www.example.com/pathOne/Path2/path2/example2.php', (string) $url);
 }
Example #21
0
 public function testParseHashAndIdentifierOnly()
 {
     $url = new \webignition\Url\Url('#foo');
     $this->assertTrue($url->hasFragment());
 }
Example #22
0
 public function testInit()
 {
     $url = new \webignition\Url\Url();
     $url->init('http://example.com/foo/bar.html?foo=bar&foobar=boofar#identity');
     $this->assertTrue($url->hasScheme());
     $this->assertEquals('http', $url->getScheme());
     $this->assertTrue($url->hasHost());
     $this->assertEquals('example.com', $url->getHost());
     $this->assertTrue($url->hasPath());
     $this->assertEquals('/foo/bar.html', $url->getPath());
     $this->assertTrue($url->hasQuery());
     $this->assertEquals('foo=bar&foobar=boofar', (string) $url->getQuery());
     $this->assertTrue($url->hasFragment());
     $this->assertEquals('identity', $url->getFragment());
 }
Example #23
0
 /**
  * When setting a fragment to null in a url that had a fragment
  * and then setting the query to null where there was no query
  * was resulting in the fragment containing the string '?', this is incorrect
  */
 public function testReplaceFragmentWithNullSetNullQuery()
 {
     $url = new \webignition\Url\Url('http://example.com/#fragment');
     $url->setFragment(null);
     $url->setQuery(null);
     $this->assertNull($url->getFragment());
     $this->assertNull($url->getQuery());
     $this->assertEquals("http://example.com/", (string) $url);
 }
 public function testAddPathToHashAndIdentifier()
 {
     $url = new \webignition\Url\Url('#foo');
     $url->setPath('/index.html');
     $this->assertEquals('/index.html#foo', (string) $url);
 }
Example #25
0
 public function isValid(Link $link)
 {
     $link = new \webignition\Url\Url($link->getLinkHref());
     return $link->getScheme() === 'http' || $link->getScheme() === 'https' || $link->getHost() !== null;
 }