FunctionTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /*
  3. * This file is part of the Humbug package.
  4. *
  5. * (c) 2015 Pádraic Brady <padraic.brady@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Humbug\Test;
  11. use PHPUnit\Framework\TestCase;
  12. use org\bovigo\vfs\vfsStream;
  13. class FunctionTest extends TestCase
  14. {
  15. private static $result;
  16. public function setup()
  17. {
  18. vfsStream::setup('home_root_path');
  19. if (null === self::$result) {
  20. $result = humbug_get_contents('https://www.howsmyssl.com/a/check');
  21. self::$result = json_decode($result, true);
  22. }
  23. }
  24. public function teardown()
  25. {
  26. self::$result = null;
  27. }
  28. public function testRating()
  29. {
  30. $this->assertEquals('Probably Okay', self::$result['rating']);
  31. }
  32. public function testTlsCompression()
  33. {
  34. $this->assertFalse(self::$result['tls_compression_supported']);
  35. }
  36. public function testSslNotUsed()
  37. {
  38. $this->assertEquals(stripos(self::$result['tls_version'], 'tls 1.'), 0);
  39. }
  40. public function testBeastVulnerability()
  41. {
  42. $this->assertFalse(self::$result['beast_vuln']);
  43. }
  44. public function testInsecureCipherSuites()
  45. {
  46. $this->assertEmpty(self::$result['insecure_cipher_suites']);
  47. }
  48. public function testUnknownCipherSuites()
  49. {
  50. $this->assertFalse(self::$result['unknown_cipher_suite_supported']);
  51. }
  52. public function testFileGetContentsWillPassThrough()
  53. {
  54. file_put_contents(vfsStream::url('home_root_path/humbug.tmp'), ($expected = uniqid()));
  55. $this->assertEquals(file_get_contents(vfsStream::url('home_root_path/humbug.tmp')), $expected);
  56. }
  57. public function testCanGetResponseHeaders()
  58. {
  59. humbug_set_headers(array('Accept-Language: da\r\n'));
  60. humbug_get_contents('http://padraic.github.io');
  61. $this->assertTrue(count(humbug_get_headers()) > 0);
  62. }
  63. public function testCanSetRequestHeaders()
  64. {
  65. humbug_set_headers(array(
  66. 'Accept-Language: da',
  67. 'User-Agent: Humbug'
  68. ));
  69. $out = humbug_get_contents('http://www.procato.com/my+headers/');
  70. $this->assertEquals(1, preg_match('%'.preg_quote('<th>Accept-Language</th><td>da</td>').'%', $out));
  71. $this->assertEquals(1, preg_match('%'.preg_quote('<th>User-Agent</th><td>Humbug</td>').'%', $out));
  72. }
  73. }