Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
BaseTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero 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 Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero 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 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  class BaseTest extends PHPUnit_Framework_TestCase
38  {
39  public static $activateDefaultLanguages = false;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  RedBeanDatabase::setup(Yii::app()->db->connectionString,
45  Yii::app()->db->username,
46  Yii::app()->db->password);
47  $schemaFile = sys_get_temp_dir() . '/autobuilt.sql';
48  $success = preg_match("/;dbname=([^;]+)/", Yii::app()->db->connectionString, $matches); // Not Coding Standard
49  assert('$success == 1'); // Not Coding Standard
50  $databaseName = $matches[1];
51  if (is_readable($schemaFile) && filesize($schemaFile) > 0)
52  {
53  $systemOutput = system('mysql -u' . Yii::app()->db->username .
54  ' -p' . Yii::app()->db->password .
55  ' ' . $databaseName . " < $schemaFile");
56  if ($systemOutput != null)
57  {
58  echo 'Loading schema using system command. Output: ' . $systemOutput . "\n\n";
59  }
60  }
61  else
62  {
63  echo "The schema file is not readable: $schemaFile. \n\n";
64  exit;
65  }
66  CustomFieldData::forgetAllPhpCache();
67  GeneralCache::forgetAll();
68  BeanModelCache::forgetAll();
69  TestDatabaseUtil::deleteRowsFromAllTablesExceptLog();
70  Yii::app()->user->userModel = null;
71  Yii::app()->user->clearStates(); //reset session.
72  Yii::app()->language = Yii::app()->getConfigLanguageValue();
73  Yii::app()->timeZoneHelper->setTimeZone(Yii::app()->getConfigTimeZoneValue());
74  Yii::app()->timeZoneHelper->load(); //resets timezone
75  Yii::app()->languageHelper->flushModuleLabelTranslationParameters();
76  if (static::$activateDefaultLanguages)
77  {
78  Yii::app()->languageHelper->load();
79  Yii::app()->languageHelper->activateLanguagesForTesting();
80  Yii::app()->languageHelper->importMessagesForTesting();
81  }
82  Yii::app()->jobQueue->deleteAll();
83  }
84 
85  public static function tearDownAfterClass()
86  {
87  if (static::$activateDefaultLanguages)
88  {
89  Yii::app()->languageHelper->deactivateLanguagesForTesting();
90  }
91 
92  TestDatabaseUtil::deleteRowsFromAllTablesExceptLog();
93  PermissionsCache::forgetAll();
94  AllPermissionsOptimizationCache::forgetAll();
96  RedBeanDatabase::close();
97  assert('!RedBeanDatabase::isSetup()'); // Not Coding Standard
98  GeneralCache::forgetAll();
99  BeanModelCache::forgetAll();
100  }
101 
102  public static function resetAndPopulateFilesArrayByFilePathAndName($arrayName, $filePath, $fileName)
103  {
104  assert('is_string($arrayName) && $arrayName != ""'); // Not Coding Standard
105  assert('is_string($filePath) && $filePath != ""'); // Not Coding Standard
106  assert('is_string($fileName) && $fileName != ""'); // Not Coding Standard
107  $_FILES = null;
108  CUploadedFile::reset();
109  $_FILES = array($arrayName => array('name' => $fileName, 'type' => ZurmoFileHelper::getMimeType($filePath),
110  'tmp_name' => $filePath, 'error' => UPLOAD_ERR_OK,
111  'size' => filesize($filePath)));
112  }
113 
114  public static function getDependentTestModelClassNames()
115  {
116  return array();
117  }
118 
119  public function setup()
120  {
121  }
122 
123  public function teardown()
124  {
125  Yii::app()->user->userModel = null;
126  }
127 
128  protected function assertWithinTolerance($expected, $actual, $plusMinus)
129  {
130  if (abs($actual - $expected) > $plusMinus)
131  {
132  $this->fail("Actual $actual not within +/- $plusMinus of expected $expected.");
133  }
134  }
135 
136  protected function assertWithinPercentage($expected, $actual, $percentage)
137  {
138  $ratio = $actual/$expected;
139  if ($ratio < (1 - $percentage/100) || $ratio > (1 + $percentage/100))
140  {
141  $this->fail("Actual $actual not within +/- $percentage% of expected $expected.");
142  }
143  }
144 
145  protected function isDebug()
146  {
147  return in_array('--debug', $_SERVER['argv']);
148  }
149 
159  public static function getReflectedPropertyValue($object, $propertyName)
160  {
161  assert('is_object($object)'); // Not Coding Standard
162  $reflectedClass = new ReflectionClass($object);
163  $property = $reflectedClass->getProperty($propertyName);
164  $property->setAccessible(true);
165  return $property->getValue($object);
166  }
167 
168  protected static function getProtectedMethod($className, $methodName)
169  {
170  $class = new ReflectionClass($className);
171  $method = $class->getMethod($methodName);
172  $method->setAccessible(true);
173  return $method;
174  }
175  }
176 ?>
static setup($dsn, $username, $password)
static forgetAll()
static getMimeType($file, $magicFile=null, $checkExtension=true)
static getReflectedPropertyValue($object, $propertyName)
Definition: BaseTest.php:159
Generated on Tue Jul 7 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.