public function testChangeHost() { $url = new \webignition\Url\Url('http://example.com/'); $url->setHost('new.example.com'); $this->assertEquals('new.example.com', $url->getHost()); $this->assertEquals('http://new.example.com/', (string) $url); }
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())); }
/** * 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); }
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()); }
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); }
public function testSetHostForRelativeUrlWithPathOnly() { $url = new \webignition\Url\Url('path'); $url->setHost('www.example.com'); $this->assertEquals('www.example.com', $url->getHost()); $this->assertEquals('//www.example.com/path', (string) $url); }
public function isValid(Link $link) { $link = new \webignition\Url\Url($link->getLinkHref()); return $link->getScheme() === 'http' || $link->getScheme() === 'https' || $link->getHost() !== null; }