diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/HttpUtils/IsHttpsTest.php | 36 | ||||
-rw-r--r-- | tests/LinkUtilsTest.php | 10 | ||||
-rw-r--r-- | tests/api/controllers/GetLinksTest.php | 83 | ||||
-rw-r--r-- | tests/languages/de/UtilsDeTest.php | 12 | ||||
-rw-r--r-- | tests/languages/en/UtilsEnTest.php | 12 | ||||
-rw-r--r-- | tests/languages/fr/UtilsFrTest.php | 12 |
6 files changed, 147 insertions, 18 deletions
diff --git a/tests/HttpUtils/IsHttpsTest.php b/tests/HttpUtils/IsHttpsTest.php new file mode 100644 index 00000000..097f2bcf --- /dev/null +++ b/tests/HttpUtils/IsHttpsTest.php | |||
@@ -0,0 +1,36 @@ | |||
1 | <?php | ||
2 | |||
3 | |||
4 | /** | ||
5 | * Class IsHttpsTest | ||
6 | * | ||
7 | * Test class for is_https() function. | ||
8 | */ | ||
9 | class IsHttpsTest extends PHPUnit_Framework_TestCase | ||
10 | { | ||
11 | |||
12 | /** | ||
13 | * Test is_https with HTTPS values. | ||
14 | */ | ||
15 | public function testIsHttpsTrue() | ||
16 | { | ||
17 | $this->assertTrue(is_https(['HTTPS' => true])); | ||
18 | $this->assertTrue(is_https(['HTTPS' => '1'])); | ||
19 | $this->assertTrue(is_https(['HTTPS' => false, 'HTTP_X_FORWARDED_PORT' => 443])); | ||
20 | $this->assertTrue(is_https(['HTTPS' => false, 'HTTP_X_FORWARDED_PORT' => '443'])); | ||
21 | $this->assertTrue(is_https(['HTTPS' => false, 'HTTP_X_FORWARDED_PORT' => '443,123,456,'])); | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * Test is_https with HTTP values. | ||
26 | */ | ||
27 | public function testIsHttpsFalse() | ||
28 | { | ||
29 | $this->assertFalse(is_https([])); | ||
30 | $this->assertFalse(is_https(['HTTPS' => false])); | ||
31 | $this->assertFalse(is_https(['HTTPS' => '0'])); | ||
32 | $this->assertFalse(is_https(['HTTPS' => false, 'HTTP_X_FORWARDED_PORT' => 123])); | ||
33 | $this->assertFalse(is_https(['HTTPS' => false, 'HTTP_X_FORWARDED_PORT' => '123'])); | ||
34 | $this->assertFalse(is_https(['HTTPS' => false, 'HTTP_X_FORWARDED_PORT' => ',123,456,'])); | ||
35 | } | ||
36 | } | ||
diff --git a/tests/LinkUtilsTest.php b/tests/LinkUtilsTest.php index 7c0d4b0b..c77922ec 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/LinkUtilsTest.php | |||
@@ -103,6 +103,16 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
103 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff'; | 103 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff'; |
104 | $processedText = text2clickable($text, ''); | 104 | $processedText = text2clickable($text, ''); |
105 | $this->assertEquals($expectedText, $processedText); | 105 | $this->assertEquals($expectedText, $processedText); |
106 | |||
107 | $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; | ||
108 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">http://hello.there/is=someone#here(please)</a> otherstuff'; | ||
109 | $processedText = text2clickable($text, ''); | ||
110 | $this->assertEquals($expectedText, $processedText); | ||
111 | |||
112 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; | ||
113 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">http://hello.there/is=someone#here(please)&no</a> otherstuff'; | ||
114 | $processedText = text2clickable($text, ''); | ||
115 | $this->assertEquals($expectedText, $processedText); | ||
106 | } | 116 | } |
107 | 117 | ||
108 | /** | 118 | /** |
diff --git a/tests/api/controllers/GetLinksTest.php b/tests/api/controllers/GetLinksTest.php index 4cb70224..d22ed3bf 100644 --- a/tests/api/controllers/GetLinksTest.php +++ b/tests/api/controllers/GetLinksTest.php | |||
@@ -367,6 +367,89 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
367 | $this->assertEquals(1, count($data)); | 367 | $this->assertEquals(1, count($data)); |
368 | $this->assertEquals(41, $data[0]['id']); | 368 | $this->assertEquals(41, $data[0]['id']); |
369 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); | 369 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); |
370 | |||
371 | // wildcard: placeholder at the start | ||
372 | $env = Environment::mock([ | ||
373 | 'REQUEST_METHOD' => 'GET', | ||
374 | 'QUERY_STRING' => 'searchtags=*Tuff', | ||
375 | ]); | ||
376 | $request = Request::createFromEnvironment($env); | ||
377 | $response = $this->controller->getLinks($request, new Response()); | ||
378 | $this->assertEquals(200, $response->getStatusCode()); | ||
379 | $data = json_decode((string) $response->getBody(), true); | ||
380 | $this->assertEquals(2, count($data)); | ||
381 | $this->assertEquals(41, $data[0]['id']); | ||
382 | |||
383 | // wildcard: placeholder at the end | ||
384 | $env = Environment::mock([ | ||
385 | 'REQUEST_METHOD' => 'GET', | ||
386 | 'QUERY_STRING' => 'searchtags=c*', | ||
387 | ]); | ||
388 | $request = Request::createFromEnvironment($env); | ||
389 | $response = $this->controller->getLinks($request, new Response()); | ||
390 | $this->assertEquals(200, $response->getStatusCode()); | ||
391 | $data = json_decode((string) $response->getBody(), true); | ||
392 | $this->assertEquals(4, count($data)); | ||
393 | $this->assertEquals(6, $data[0]['id']); | ||
394 | |||
395 | // wildcard: placeholder at the middle | ||
396 | $env = Environment::mock([ | ||
397 | 'REQUEST_METHOD' => 'GET', | ||
398 | 'QUERY_STRING' => 'searchtags=w*b', | ||
399 | ]); | ||
400 | $request = Request::createFromEnvironment($env); | ||
401 | $response = $this->controller->getLinks($request, new Response()); | ||
402 | $this->assertEquals(200, $response->getStatusCode()); | ||
403 | $data = json_decode((string) $response->getBody(), true); | ||
404 | $this->assertEquals(4, count($data)); | ||
405 | $this->assertEquals(6, $data[0]['id']); | ||
406 | |||
407 | // wildcard: match all | ||
408 | $env = Environment::mock([ | ||
409 | 'REQUEST_METHOD' => 'GET', | ||
410 | 'QUERY_STRING' => 'searchtags=*', | ||
411 | ]); | ||
412 | $request = Request::createFromEnvironment($env); | ||
413 | $response = $this->controller->getLinks($request, new Response()); | ||
414 | $this->assertEquals(200, $response->getStatusCode()); | ||
415 | $data = json_decode((string) $response->getBody(), true); | ||
416 | $this->assertEquals(9, count($data)); | ||
417 | $this->assertEquals(41, $data[0]['id']); | ||
418 | |||
419 | // wildcard: optional ('*' does not need to expand) | ||
420 | $env = Environment::mock([ | ||
421 | 'REQUEST_METHOD' => 'GET', | ||
422 | 'QUERY_STRING' => 'searchtags=*stuff*', | ||
423 | ]); | ||
424 | $request = Request::createFromEnvironment($env); | ||
425 | $response = $this->controller->getLinks($request, new Response()); | ||
426 | $this->assertEquals(200, $response->getStatusCode()); | ||
427 | $data = json_decode((string) $response->getBody(), true); | ||
428 | $this->assertEquals(2, count($data)); | ||
429 | $this->assertEquals(41, $data[0]['id']); | ||
430 | |||
431 | // wildcard: exclusions | ||
432 | $env = Environment::mock([ | ||
433 | 'REQUEST_METHOD' => 'GET', | ||
434 | 'QUERY_STRING' => 'searchtags=*a*+-*e*', | ||
435 | ]); | ||
436 | $request = Request::createFromEnvironment($env); | ||
437 | $response = $this->controller->getLinks($request, new Response()); | ||
438 | $this->assertEquals(200, $response->getStatusCode()); | ||
439 | $data = json_decode((string) $response->getBody(), true); | ||
440 | $this->assertEquals(1, count($data)); | ||
441 | $this->assertEquals(41, $data[0]['id']); // finds '#hashtag' in descr. | ||
442 | |||
443 | // wildcard: exclude all | ||
444 | $env = Environment::mock([ | ||
445 | 'REQUEST_METHOD' => 'GET', | ||
446 | 'QUERY_STRING' => 'searchtags=-*', | ||
447 | ]); | ||
448 | $request = Request::createFromEnvironment($env); | ||
449 | $response = $this->controller->getLinks($request, new Response()); | ||
450 | $this->assertEquals(200, $response->getStatusCode()); | ||
451 | $data = json_decode((string) $response->getBody(), true); | ||
452 | $this->assertEquals(0, count($data)); | ||
370 | } | 453 | } |
371 | 454 | ||
372 | /** | 455 | /** |
diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php index 6c9c9adc..4569c923 100644 --- a/tests/languages/de/UtilsDeTest.php +++ b/tests/languages/de/UtilsDeTest.php | |||
@@ -81,12 +81,12 @@ class UtilsDeTest extends UtilsTest | |||
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Test autoLocale with multiples value, the second one is valid | 84 | * Test autoLocale with multiples value, the second one is available |
85 | */ | 85 | */ |
86 | public function testAutoLocaleMultipleSecondValid() | 86 | public function testAutoLocaleMultipleSecondAvailable() |
87 | { | 87 | { |
88 | $current = setlocale(LC_ALL, 0); | 88 | $current = setlocale(LC_ALL, 0); |
89 | $header = 'pt_BR,fr-fr'; | 89 | $header = 'mag_IN,fr-fr'; |
90 | autoLocale($header); | 90 | autoLocale($header); |
91 | $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0)); | 91 | $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0)); |
92 | 92 | ||
@@ -106,12 +106,12 @@ class UtilsDeTest extends UtilsTest | |||
106 | } | 106 | } |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * Test autoLocale with an invalid value: defaults to en_US. | 109 | * Test autoLocale with an unavailable value: defaults to en_US. |
110 | */ | 110 | */ |
111 | public function testAutoLocaleInvalid() | 111 | public function testAutoLocaleUnavailable() |
112 | { | 112 | { |
113 | $current = setlocale(LC_ALL, 0); | 113 | $current = setlocale(LC_ALL, 0); |
114 | autoLocale('pt_BR'); | 114 | autoLocale('mag_IN'); |
115 | $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); | 115 | $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); |
116 | 116 | ||
117 | setlocale(LC_ALL, $current); | 117 | setlocale(LC_ALL, $current); |
diff --git a/tests/languages/en/UtilsEnTest.php b/tests/languages/en/UtilsEnTest.php index d8680b2b..a74063ae 100644 --- a/tests/languages/en/UtilsEnTest.php +++ b/tests/languages/en/UtilsEnTest.php | |||
@@ -81,12 +81,12 @@ class UtilsEnTest extends UtilsTest | |||
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Test autoLocale with multiples value, the second one is valid | 84 | * Test autoLocale with multiples value, the second one is available |
85 | */ | 85 | */ |
86 | public function testAutoLocaleMultipleSecondValid() | 86 | public function testAutoLocaleMultipleSecondAvailable() |
87 | { | 87 | { |
88 | $current = setlocale(LC_ALL, 0); | 88 | $current = setlocale(LC_ALL, 0); |
89 | $header = 'pt_BR,fr-fr'; | 89 | $header = 'mag_IN,fr-fr'; |
90 | autoLocale($header); | 90 | autoLocale($header); |
91 | $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0)); | 91 | $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0)); |
92 | 92 | ||
@@ -106,12 +106,12 @@ class UtilsEnTest extends UtilsTest | |||
106 | } | 106 | } |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * Test autoLocale with an invalid value: defaults to en_US. | 109 | * Test autoLocale with an unavailable value: defaults to en_US. |
110 | */ | 110 | */ |
111 | public function testAutoLocaleInvalid() | 111 | public function testAutoLocaleUnavailable() |
112 | { | 112 | { |
113 | $current = setlocale(LC_ALL, 0); | 113 | $current = setlocale(LC_ALL, 0); |
114 | autoLocale('pt_BR'); | 114 | autoLocale('mag_IN'); |
115 | $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); | 115 | $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); |
116 | 116 | ||
117 | setlocale(LC_ALL, $current); | 117 | setlocale(LC_ALL, $current); |
diff --git a/tests/languages/fr/UtilsFrTest.php b/tests/languages/fr/UtilsFrTest.php index 0d50a878..3dbb126f 100644 --- a/tests/languages/fr/UtilsFrTest.php +++ b/tests/languages/fr/UtilsFrTest.php | |||
@@ -81,12 +81,12 @@ class UtilsFrTest extends UtilsTest | |||
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Test autoLocale with multiples value, the second one is valid | 84 | * Test autoLocale with multiples value, the second one is available |
85 | */ | 85 | */ |
86 | public function testAutoLocaleMultipleSecondValid() | 86 | public function testAutoLocaleMultipleSecondAvailable() |
87 | { | 87 | { |
88 | $current = setlocale(LC_ALL, 0); | 88 | $current = setlocale(LC_ALL, 0); |
89 | $header = 'pt_BR,de-de'; | 89 | $header = 'mag_IN,de-de'; |
90 | autoLocale($header); | 90 | autoLocale($header); |
91 | $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); | 91 | $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); |
92 | 92 | ||
@@ -106,12 +106,12 @@ class UtilsFrTest extends UtilsTest | |||
106 | } | 106 | } |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * Test autoLocale with an invalid value: defaults to en_US. | 109 | * Test autoLocale with an unavailable value: defaults to en_US. |
110 | */ | 110 | */ |
111 | public function testAutoLocaleInvalid() | 111 | public function testAutoLocaleUnavailable() |
112 | { | 112 | { |
113 | $current = setlocale(LC_ALL, 0); | 113 | $current = setlocale(LC_ALL, 0); |
114 | autoLocale('pt_BR'); | 114 | autoLocale('mag_IN'); |
115 | $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); | 115 | $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); |
116 | 116 | ||
117 | setlocale(LC_ALL, $current); | 117 | setlocale(LC_ALL, $current); |