PageRenderTime 85ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/tine20/Tinebase/HelperTests.php

https://github.com/tine20/Tine-2.0-Open-Source-Groupware-and-CRM
PHP | 95 lines | 60 code | 16 blank | 19 comment | 1 complexity | 46b6e75a69f1780f477ddd7ba1d719fd MD5 | raw file
  1. <?php
  2. /**
  3. * Tine 2.0 - http://www.tine20.org
  4. *
  5. * @package Tinebase
  6. * @license http://www.gnu.org/licenses/agpl.html
  7. * @copyright Copyright (c) 2008-2013 Metaways Infosystems GmbH (http://www.metaways.de)
  8. * @author Cornelius Weiss <c.weiss@metaways.de>
  9. */
  10. /**
  11. * Test helper
  12. */
  13. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  14. /**
  15. * Test class for Tinebase_Helper
  16. */
  17. class Tinebase_HelperTests extends \PHPUnit\Framework\TestCase
  18. {
  19. public function testArray_value()
  20. {
  21. $array = array(
  22. 0 => 'foo',
  23. 'one' => 'bar'
  24. );
  25. $this->assertEquals('foo', Tinebase_Helper::array_value(0, $array));
  26. $this->assertEquals('bar', Tinebase_Helper::array_value('one', $array));
  27. }
  28. public function testArrayHash()
  29. {
  30. $hash = Tinebase_Helper::arrayHash(array('foo' => 'bar'));
  31. $this->assertEquals('37b51d194a7513e45b56f6524f2d51f2', $hash);
  32. $hash = Tinebase_Helper::arrayHash(array('foo' => 'bar'), true);
  33. $this->assertEquals('3858f62230ac3c915f300c664312c63f', $hash);
  34. }
  35. public function testGetDevelopmentRevision()
  36. {
  37. $rev = Tinebase_Helper::getDevelopmentRevision();
  38. $this->assertFalse(empty($rev));
  39. }
  40. public function testConvertToBytes()
  41. {
  42. $this->assertEquals(1024, Tinebase_Helper::convertToBytes('1024'));
  43. $this->assertEquals(1024, Tinebase_Helper::convertToBytes('1K'));
  44. $this->assertEquals(1024*1024, Tinebase_Helper::convertToBytes('1M'));
  45. $this->assertEquals(1024*1024*1024, Tinebase_Helper::convertToBytes('1G'));
  46. }
  47. /**
  48. * testSearchArrayByRegexpKey
  49. *
  50. * @see 0008782: Endless loop login windows when calling Active Sync Page
  51. */
  52. public function testSearchArrayByRegexpKey()
  53. {
  54. $server = array(
  55. 'REMOTE_USER' => '1',
  56. 'REDIRECT_REMOTE_USER' => '2',
  57. 'REDIRECT_REDIRECT_REMOTE_USER' => '3',
  58. 'OTHER' => '4',
  59. );
  60. $remoteUserValues = Tinebase_Helper::searchArrayByRegexpKey('/REMOTE_USER$/', $server);
  61. $this->assertTrue(! empty($remoteUserValues));
  62. $this->assertEquals(3, count($remoteUserValues));
  63. $firstServerValue = array_shift($remoteUserValues);
  64. $this->assertEquals('1', $firstServerValue);
  65. }
  66. public function testIdnaConvert()
  67. {
  68. $input = 'andre@xn--brse-5qa.xn--knrz-1ra.info';
  69. self::assertEquals('andre@börse.knürz.info', Tinebase_Helper::convertDomainToUnicode($input));
  70. $input = 'nörgler.com';
  71. self::assertEquals('xn--nrgler-wxa.com', Tinebase_Helper::convertDomainToPunycode($input));
  72. $input = 'H.-H.einer@nopel.opel';
  73. $punyCodedAddress = Tinebase_Helper::convertDomainToPunycode($input);
  74. if (! preg_match(Tinebase_Mail::EMAIL_ADDRESS_REGEXP, $punyCodedAddress)) {
  75. self::fail('address is not invalid: ' . $punyCodedAddress);
  76. }
  77. self::assertEquals('H.-H.einer@nopel.opel', $punyCodedAddress);
  78. }
  79. }