PageRenderTime 46ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/app/protected/tests/unit/TestHelpers.php

https://bitbucket.org/mstowe/zurmo
PHP | 83 lines | 54 code | 5 blank | 24 comment | 6 complexity | be77947b74e98c3c39796859f3b8a1c6 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
  24. * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
  25. ********************************************************************************/
  26. class TestHelpers
  27. {
  28. public static function isClassInArray($className, array $array)
  29. {
  30. foreach ($array as $item)
  31. {
  32. if (get_class($item) == $className)
  33. {
  34. return true;
  35. }
  36. }
  37. return false;
  38. }
  39. public static function makeRandomSentence($wordCount)
  40. {
  41. $words = array();
  42. for ($i = 0; $i < $wordCount; $i++)
  43. {
  44. $words[] = TestHelpers::makeRandomWord();
  45. }
  46. return implode(' ', $words);
  47. }
  48. public static function makeRandomWord($letterCount = 5)
  49. {
  50. $word = '';
  51. for ($i = 0; $i < $letterCount; $i++)
  52. {
  53. $word .= chr(rand(ord('a'), ord('z')));
  54. }
  55. return $word;
  56. }
  57. public static function makeUniqueRandomUsernames($count)
  58. {
  59. $usernames = array();
  60. for ($i = 0; $i < $count; $i++)
  61. {
  62. do
  63. {
  64. $username = TestHelpers::makeRandomWord(6);
  65. }
  66. while (in_array($username, $usernames));
  67. $usernames[] = $username;
  68. }
  69. return $usernames;
  70. }
  71. public static function createControllerAndModuleByRoute($route)
  72. {
  73. $data = Yii::app()->createController($route);
  74. assert('$data[0]->getModule() instanceof Module');
  75. Yii::app()->setController($data[0]);
  76. }
  77. }
  78. ?>