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