PageRenderTime 103ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 57ms app.codeStats 0ms

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

https://bitbucket.org/rkcbabu/zurmo
PHP | 83 lines | 54 code | 5 blank | 24 comment | 6 complexity | be77947b74e98c3c39796859f3b8a1c6 MD5 | raw file
 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
27    class TestHelpers
28    {
29        public static function isClassInArray($className, array $array)
30        {
31            foreach ($array as $item)
32            {
33                if (get_class($item) == $className)
34                {
35                    return true;
36                }
37            }
38            return false;
39        }
40
41        public static function makeRandomSentence($wordCount)
42        {
43            $words = array();
44            for ($i = 0; $i < $wordCount; $i++)
45            {
46                $words[] = TestHelpers::makeRandomWord();
47            }
48            return implode(' ', $words);
49        }
50
51        public static function makeRandomWord($letterCount = 5)
52        {
53            $word = '';
54            for ($i = 0; $i < $letterCount; $i++)
55            {
56                $word .= chr(rand(ord('a'), ord('z')));
57            }
58            return $word;
59        }
60
61        public static function makeUniqueRandomUsernames($count)
62        {
63            $usernames = array();
64            for ($i = 0; $i < $count; $i++)
65            {
66                do
67                {
68                    $username = TestHelpers::makeRandomWord(6);
69                }
70                while (in_array($username, $usernames));
71                $usernames[] = $username;
72            }
73            return $usernames;
74        }
75
76        public static function createControllerAndModuleByRoute($route)
77        {
78            $data = Yii::app()->createController($route);
79            assert('$data[0]->getModule() instanceof Module');
80            Yii::app()->setController($data[0]);
81        }
82    }
83?>