public function testBasicSetScheme() { $value = 'https'; $url = new Url(); $url->setScheme($value); $this->assertEquals($value, $url->getScheme()); }
/** * This exists as the php::parse_url function sometimes breaks inexplicably * @param string $sUrl * @return Url */ protected static function parse_url($sUrl = null) { if (is_null($sUrl)) { return new Url(); } if (mb_detect_encoding($sUrl) !== 'ASCII') { $sUrl = rawurlencode($sUrl); } $oUrl = new Url(); try { if (!stristr($sUrl, '://') && is_file($sUrl) && is_readable($sUrl)) { $oUrl->setScheme('file'); $oUrl->setPath($sUrl); return $oUrl; } } catch (\Exception $e) { // possible open basedir restriction $oUrl->setScheme('file'); $oUrl->setPath($sUrl); return $oUrl; } try { if (!self::urlHasScheme($sUrl)) { $sUrl = (HttpRequestA::isSecure() ? 'https:' : 'http:') . $sUrl; } $aParsed = parse_url($sUrl); if (!is_array($aParsed)) { return null; } if (isset($aParsed['scheme'])) { $oUrl->setScheme($aParsed['scheme']); } if (isset($aParsed['host'])) { $oUrl->setHost($aParsed['host']); } if (isset($aParsed['port'])) { $oUrl->setPort($aParsed['port']); } if (isset($aParsed['path'])) { $oUrl->setPath($aParsed['path']); } if (isset($aParsed['query'])) { $oUrl->setRawQuery($aParsed['query']); } if (isset($aParsed['fragment'])) { $oUrl->setFragment($aParsed['fragment']); } return $oUrl; } catch (\Exception $e) { // failed php::parse_url } }
/** * @test */ public function parse_urlIPWithoutProtocol() { $aUrlComponents = array('scheme' => 'http', 'host' => '127.0.0.1', 'user' => '', 'pass' => '', 'path' => '/', 'query' => [], 'fragment' => ''); $oUrl = new Url(); $oUrl->setScheme($aUrlComponents['scheme']); $oUrl->setHost($aUrlComponents['host']); $oUrl->setPath($aUrlComponents['path']); $oUrl->setQuery($aUrlComponents['query']); $oUrl->setFragment($aUrlComponents['fragment']); $this->assertEquals($oUrl, UrlParserA_underTest::parse_url('//127.0.0.1/')); }