public function testNormalisedUrlCapitalisesPercentEncodedEntities()
 {
     $reservedCharacters = array('!', '*', "'", '(', ')', ';', ':', '@', '&', '=', '+', '$', ',', '/', '?', '#', '[', ']');
     $encodedKeyValuePairs = array();
     $lowercaseEncodedKeyValuePairs = array();
     $keyIndex = 0;
     foreach ($reservedCharacters as $reservedCharacter) {
         $key = 'key' . $keyIndex;
         $encodedKeyValuePairs[$key] = urlencode($reservedCharacter);
         $lowercaseEncodedKeyValuePairs[$key] = strtolower(urlencode($reservedCharacter));
         $keyIndex++;
     }
     ksort($encodedKeyValuePairs);
     ksort($lowercaseEncodedKeyValuePairs);
     $percentEncodedQueryString = '';
     $lowercasePercentEncodedQueryString = '';
     foreach ($encodedKeyValuePairs as $key => $value) {
         $percentEncodedQueryString .= '&' . urlencode($key) . '=' . $value;
     }
     foreach ($lowercaseEncodedKeyValuePairs as $key => $value) {
         $lowercasePercentEncodedQueryString .= '&' . urlencode($key) . '=' . $value;
     }
     $percentEncodedQueryString = substr($percentEncodedQueryString, 1);
     $lowercasePercentEncodedQueryString = substr($lowercasePercentEncodedQueryString, 1);
     $url = new \webignition\NormalisedUrl\NormalisedUrl(self::SCHEME_HTTP . '://' . self::HOST . '/?' . $lowercasePercentEncodedQueryString);
     $this->assertEquals($percentEncodedQueryString, (string) $url->getQuery());
 }
 public function testSetQueryWithFragmentWithQuestionMark()
 {
     $url = new \webignition\NormalisedUrl\NormalisedUrl('http://example.com/#fragment');
     $url->setQuery('?key2=value2&key1=value1');
     $this->assertEquals('key1=value1&key2=value2', (string) $url->getQuery());
     $this->assertEquals('http://example.com/?key1=value1&key2=value2#fragment', (string) $url);
 }
 public function testNormalisedUrlDecodesUnreservedCharacters()
 {
     $alpha = 'abcdefghijklmnopqrstuvwxyz';
     $uppercaseAlpha = strtoupper($alpha);
     $digit = '0123456789';
     $otherUnreservedCharacters = '-._~';
     $unreservedCharacterString = $alpha . $uppercaseAlpha . $digit . $otherUnreservedCharacters;
     $unreservedCharacters = str_split($unreservedCharacterString);
     $sortedKeyValues = array();
     $keyIndex = 0;
     foreach ($unreservedCharacters as $unreservedCharacter) {
         $sortedKeyValues['key' . $keyIndex] = $unreservedCharacter;
         $keyIndex++;
     }
     ksort($sortedKeyValues);
     $encodedKeyValuePairs = array();
     $decodedKeyValuePairs = array();
     foreach ($sortedKeyValues as $key => $value) {
         $encodedKeyValuePairs[] = $key . '=%' . dechex(ord($value));
         $decodedKeyValuePairs[] = $key . '=' . $value;
     }
     $encodedQueryString = implode('&', $encodedKeyValuePairs);
     $decodedQueryString = implode('&', $decodedKeyValuePairs);
     $url = new \webignition\NormalisedUrl\NormalisedUrl(self::SCHEME_HTTP . '://' . self::HOST . '/?' . $encodedQueryString);
     $this->assertEquals($decodedQueryString, (string) $url->getQuery());
 }
 public function testAddPathToRootUrl()
 {
     $url = new \webignition\NormalisedUrl\NormalisedUrl('http://example.com');
     $url->setPath('/index.html');
     $this->assertEquals('http://example.com/index.html', (string) $url);
     $url = new \webignition\NormalisedUrl\NormalisedUrl('http://example.com/');
     $url->setPath('/index.html');
     $this->assertEquals('http://example.com/index.html', (string) $url);
 }