‪TYPO3CMS  10.4
HttpUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪HttpUtilityTest extends UnitTestCase
25 {
32  public function ‪isUrlBuiltCorrectly(array $urlParts, $expected)
33  {
34  $url = ‪HttpUtility::buildUrl($urlParts);
35  self::assertEquals($expected, $url);
36  }
37 
42  {
43  return [
44  'rebuild url without scheme' => [
45  parse_url('typo3.org/path/index.php'),
46  'typo3.org/path/index.php'
47  ],
48  'rebuild url with scheme' => [
49  parse_url('http://typo3.org/path/index.php'),
50  'http://typo3.org/path/index.php'
51  ],
52  'rebuild url with all properties' => [
53  parse_url('http://editor:secret@typo3.org:8080/path/index.php?query=data#fragment'),
54  'http://editor:secret@typo3.org:8080/path/index.php?query=data#fragment'
55  ],
56  'url without username, but password' => [
57  [
58  'scheme' => 'http',
59  'pass' => 'secrept',
60  'host' => 'typo3.org'
61  ],
62  'http://typo3.org'
63  ]
64  ];
65  }
66 
72  public function ‪queryStringDataProvider()
73  {
74  $valueArray = ['one' => '√', 'two' => 2];
75 
76  return [
77  'Empty input' => ['foo', [], ''],
78  'String parameters' => ['foo', $valueArray, 'foo%5Bone%5D=%E2%88%9A&foo%5Btwo%5D=2'],
79  'Nested array parameters' => ['foo', [$valueArray], 'foo%5B0%5D%5Bone%5D=%E2%88%9A&foo%5B0%5D%5Btwo%5D=2'],
80  'Keep blank parameters' => ['foo', ['one' => '√', ''], 'foo%5Bone%5D=%E2%88%9A&foo%5B0%5D=']
81  ];
82  }
83 
91  public function ‪buildQueryStringBuildsValidParameterString($name, array $input, $expected)
92  {
93  if ($name === '') {
94  self::assertSame($expected, ‪HttpUtility::buildQueryString($input));
95  } else {
96  self::assertSame($expected, ‪HttpUtility::buildQueryString([$name => $input]));
97  }
98  }
99 
104  {
105  $input = ['one' => '√', ''];
106  $expected = 'foo%5Bone%5D=%E2%88%9A';
107  self::assertSame($expected, ‪HttpUtility::buildQueryString(['foo' => $input], '', true));
108  }
109 
114  {
115  $input = ['one' => '√', ''];
116  $expected = 'foo%5Bone%5D=%E2%88%9A&foo%5B0%5D=';
117  self::assertSame($expected, ‪HttpUtility::buildQueryString(['foo' => $input]));
118  }
119 
124  {
125  $input = ['one' => ['two' => ['three' => '√']], ''];
126  $expected = 'foo%5Bone%5D%5Btwo%5D%5Bthree%5D=%E2%88%9A&foo%5B0%5D=';
127  self::assertSame($expected, ‪HttpUtility::buildQueryString(['foo' => $input]));
128  }
129 
134  {
135  $input = [];
136  $expected = '';
137  self::assertSame($expected, ‪HttpUtility::buildQueryString($input, '?', true));
138  }
139 
144  {
145  $input = ['one' => ''];
146  $expected = '';
147  self::assertSame($expected, ‪HttpUtility::buildQueryString(['foo' => $input], '?', true));
148  }
149 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest
Definition: HttpUtilityTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\isUrlBuiltCorrectly
‪isUrlBuiltCorrectly(array $urlParts, $expected)
Definition: HttpUtilityTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\isUrlBuiltCorrectlyDataProvider
‪array isUrlBuiltCorrectlyDataProvider()
Definition: HttpUtilityTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\queryStringDataProvider
‪array queryStringDataProvider()
Definition: HttpUtilityTest.php:72
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\buildQueryStringCanUrlEncodeKeyNames
‪buildQueryStringCanUrlEncodeKeyNames()
Definition: HttpUtilityTest.php:113
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\buildQueryStringCanUrlEncodeKeyNamesMultidimensional
‪buildQueryStringCanUrlEncodeKeyNamesMultidimensional()
Definition: HttpUtilityTest.php:123
‪TYPO3\CMS\Core\Utility\HttpUtility\buildUrl
‪static string buildUrl(array $urlParts)
Definition: HttpUtility.php:141
‪TYPO3\CMS\Core\Utility\HttpUtility\buildQueryString
‪static string buildQueryString(array $parameters, string $prependCharacter='', bool $skipEmptyParameters=false)
Definition: HttpUtility.php:163
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\buildQueryStringCanSkipEmptyParameters
‪buildQueryStringCanSkipEmptyParameters()
Definition: HttpUtilityTest.php:103
‪TYPO3\CMS\Core\Utility\HttpUtility
Definition: HttpUtility.php:24
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\buildQueryStringSkipsLeadingCharacterOnEmptyParameters
‪buildQueryStringSkipsLeadingCharacterOnEmptyParameters()
Definition: HttpUtilityTest.php:133
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\buildQueryStringBuildsValidParameterString
‪buildQueryStringBuildsValidParameterString($name, array $input, $expected)
Definition: HttpUtilityTest.php:91
‪TYPO3\CMS\Core\Tests\Unit\Utility\HttpUtilityTest\buildQueryStringSkipsLeadingCharacterOnCleanedEmptyParameters
‪buildQueryStringSkipsLeadingCharacterOnCleanedEmptyParameters()
Definition: HttpUtilityTest.php:143