function testNormalizeUrl() { $strs = array('http://xataface.com/index.php?foo=1&bar=2&foo=3' => 'http://xataface.com/index.php?bar=2&foo=1&foo=3', 'index.php?foo=1&bar=2&foo=3' => 'index.php?bar=2&foo=1&foo=3', 'http://xataface.com/index.php?foo=1&bar=2&foo=3#hello_world' => 'http://xataface.com/index.php?bar=2&foo=1&foo=3', 'index.php?foo=1&bar=2&foo=3#hello_world' => 'index.php?bar=2&foo=1&foo=3', '/index.php?foo=1&bar=2&foo=3#hello_world' => '/index.php?bar=2&foo=1&foo=3', '../index.php?foo=1&bar=2&foo=3#hello_world' => '../index.php?bar=2&foo=1&foo=3', 'index.php?foo=1&bar=2&foo=3#hello_world?foo=15' => 'index.php?bar=2&foo=1&foo=3', 'https://xataface.com/index.php?foo=1&bar=2&foo=3' => 'https://xataface.com/index.php?bar=2&foo=1&foo=3'); foreach ($strs as $k => $v) { $this->assertEquals($v, SweteTools::normalizeUrl($k)); } }
/** * @brief Creates a new webpage with the given source path. * * @see newWebpageWithProxifiedUrl() for details on other arguments. */ public function newWebpageWithSrcPath($vals, $checkExists = true, $secure = false) { if (!@$vals['webpage_url']) { throw new Exception("No path provided"); } if ($checkExists) { $page = $this->loadWebpageBySrcPath($vals['webpage_url']); if ($page) { throw new Exception("Webpage already exists"); } } $vals['webpage_url'] = SweteTools::normalizeUrl($vals['webpage_url']); if (!isset($vals['webpage_content'])) { $vals['webpage_content'] = ''; } $rec = new Dataface_Record('webpages', array()); $rec->setValues($vals); $res = $rec->save($this->getSourceLanguage(), $secure); if (PEAR::isError($res)) { throw new Exception($res->getMessage(), $res->getCode()); } $page = $this->loadWebpageBySrcPath($vals['webpage_url']); if (!$page) { throw new Exception("We have inserted a page, but cannot seem to load it."); } return $page; }