public function testLoad() { $this->assertEquals(2, Group::getCount()); $this->assertEquals(0, Role::getCount()); $this->assertEquals(0, Account::getCount()); $this->assertEquals(0, Contact::getCount()); $this->assertEquals(0, Opportunity::getCount()); $this->assertEquals(0, Meeting::getCount()); $this->assertEquals(0, Note::getCount()); $this->assertEquals(0, Task::getCount()); $this->assertEquals(1, User::getCount()); $this->assertEquals(0, ProductCatalog::getCount()); $this->assertEquals(0, ProductCategory::getCount()); $this->assertEquals(0, ProductTemplate::getCount()); $this->assertEquals(0, Product::getCount()); $messageLogger = new MessageLogger(); DemoDataUtil::unsetLoadedModules(); DemoDataUtil::load($messageLogger, 3); $this->assertEquals(8, Group::getCount()); $this->assertEquals(3, Role::getCount()); $this->assertEquals(3, Account::getCount()); $this->assertEquals(16, Contact::getCount()); $this->assertEquals(6, Opportunity::getCount()); $this->assertEquals(18, Meeting::getCount()); $this->assertEquals(12, Note::getCount()); $this->assertEquals(9, Task::getCount()); $this->assertEquals(10, User::getCount()); $this->assertEquals(1, ProductCatalog::getCount()); $this->assertEquals(6, ProductCategory::getCount()); $this->assertEquals(32, ProductTemplate::getCount()); $this->assertEquals(59, Product::getCount()); }
/** * Method to run installation from command line. Use @InstallCommand. * @param array $args */ public static function runFromInstallCommand($args, $validateForm = false) { assert('is_array($args)'); $form = new InstallSettingsForm(); $template = "{message}\n"; $messageStreamer = new MessageStreamer($template); $messageStreamer->setExtraRenderBytes(0); $messageStreamer->add(Zurmo::t('InstallModule', 'Connecting to Database.')); $form->databaseHostname = $args[0]; $form->databaseName = $args[1]; $form->databaseUsername = $args[2]; $form->databasePassword = $args[3]; $form->databasePort = $args[4]; $form->superUserPassword = $args[5]; $form->removeExistingData = 1; if (!empty($args[6])) { $form->hostInfo = $args[6]; Yii::app()->getRequest()->setHostInfo($form->hostInfo); } if (!empty($args[7])) { $form->scriptUrl = $args[7]; } $formHasErrors = false; if ($validateForm) { $form->validate(); if ($form->hasErrors()) { $errors = $form->getErrors(); foreach ($errors as $fieldErrors) { foreach ($fieldErrors as $fieldError) { $messageStreamer->add($fieldError); } } $formHasErrors = true; } } if (!$formHasErrors) { static::runInstallation($form, $messageStreamer); if (isset($args[8])) { $messageStreamer->add(Zurmo::t('InstallModule', 'Starting to load demo data.')); $messageLogger = new MessageLogger($messageStreamer); $messageLogger->logDateTimeStamp = false; $startTime = microtime(true); if (isset($args[9])) { DemoDataUtil::load($messageLogger, intval($args[9])); } else { DemoDataUtil::load($messageLogger, 6); } $endTime = microtime(true); $messageStreamer->add(Zurmo::t('InstallModule', 'Total demodata build time: {formattedTime} seconds.', array('{formattedTime}' => number_format($endTime - $startTime, 3)))); if (SHOW_QUERY_DATA) { $messageStreamer->add(FooterView::getTotalAndDuplicateQueryCountContent()); $messageStreamer->add(PageView::makeNonHtmlDuplicateCountAndQueryContent()); } $messageStreamer->add(Zurmo::t('InstallModule', 'Finished loading demo data.')); } if (empty($args[6]) || empty($args[7])) { // Send notification to super admin that need to setup hostInfo and scriptUrl params in perInstance.php $message = new NotificationMessage(); $message->textContent = Zurmo::t('InstallModule', 'The system has detected that the hostInfo and/or scriptUrl are ' . 'not set up. Please open the perInstance.php config file and ' . 'set up these parameters.'); $rules = new HostInfoAndScriptUrlNotSetupNotificationRules(); NotificationsUtil::submit($message, $rules); } $messageStreamer->add(Zurmo::t('InstallModule', 'Locking Installation.')); static::writeInstallComplete(INSTANCE_ROOT); $messageStreamer->add(Zurmo::t('InstallModule', 'Installation Complete.')); } }
/** * Added forgetAllCaches in case you are debugging and want to run this action again with a saved db. */ public function actionInstallDemoData() { RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); InstallUtil::freezeDatabase(); ForgetAllCacheUtil::forgetAllCaches(); Yii::app()->user->userModel = User::getByUsername('super'); $nextView = new InstallCompleteView($this->getId(), $this->getModule()->getId()); $view = new InstallPageView($nextView); echo $view->render(); $template = ZurmoHtml::script("\$('#logging-table').prepend('{message}<br/>');"); $messageStreamer = new MessageStreamer($template); $messageStreamer->add(Zurmo::t('InstallModule', 'Starting to load demo data.')); $messageLogger = new MessageLogger($messageStreamer); DemoDataUtil::load($messageLogger, 6); $messageStreamer->add(Zurmo::t('InstallModule', 'Finished loading demo data.')); $messageStreamer->add(Zurmo::t('InstallModule', 'Locking Installation.')); InstallUtil::writeInstallComplete(INSTANCE_ROOT); ForgetAllCacheUtil::forgetAllCaches(); echo ZurmoHtml::script('$("#progress-table").hide(); $("#complete-table").show();'); }
public function testAllActions() { //Ensure that installed = false Yii::app()->setApplicationInstalled(false); //Check index action. $this->runControllerWithNoExceptionsAndGetContent('install/default'); $this->runControllerWithNoExceptionsAndGetContent('install/default/index'); //Check welcome action. $this->runControllerWithNoExceptionsAndGetContent('install/default/welcome'); //Check checkSystem action. if (isset($_SERVER['SERVER_SOFTWARE'])) { $serverSoftware = $_SERVER['SERVER_SOFTWARE']; } $_SERVER['SERVER_SOFTWARE'] = 'Apache'; $this->runControllerWithNoExceptionsAndGetContent('install/default/checkSystem'); //Check settings action. $this->runControllerWithNoExceptionsAndGetContent('install/default/settings'); //Check validateSettings action. //First validation will fail, and there should be at least validation errors. $this->setPostArray(array('ajax' => 'install-form', 'InstallSettingsForm' => array('databaseHostname' => '', 'databaseAdminUsername' => '', 'databaseAdminPassword' => '', 'databaseName' => '', 'databaseUsername' => '', 'databasePassword' => '', 'databasePort' => '', 'superUserPassword' => '', 'memcacheHostname' => '', 'memcachePortNumber' => '', 'memcacheAvailable' => '', 'databaseType' => 'mysql', 'removeExistingData' => '', 'installDemoData' => ''))); $content = $this->runControllerWithExitExceptionAndGetContent('install/default/settings'); $errors = CJSON::decode($content); $this->assertGreaterThanOrEqual(5, count($errors)); $postData = array('ajax' => 'install-form', 'InstallSettingsForm' => array('databaseHostname' => $this->databaseHostname, 'databaseAdminUsername' => '', 'databaseAdminPassword' => '', 'databaseName' => $this->databaseName, 'databaseUsername' => $this->databaseUsername, 'databasePassword' => $this->databasePassword, 'databasePort' => $this->databasePort, 'superUserPassword' => $this->superUserPassword, 'databaseType' => 'mysql', 'removeExistingData' => '1', 'installDemoData' => '')); if (MEMCACHE_ON) { $memcacheSettings = array('memcacheHostname' => 'localhost', 'memcachePortNumber' => '11211', 'memcacheAvailable' => '1'); } else { $memcacheSettings = array('memcacheHostname' => '', 'memcachePortNumber' => '', 'memcacheAvailable' => '0'); } $postData['InstallSettingsForm'] = array_merge($postData['InstallSettingsForm'], $memcacheSettings); $this->setPostArray($postData); $content = $this->runControllerWithExitExceptionAndGetContent('install/default/settings'); $errors = CJSON::decode($content); $this->assertEquals(1, count($errors)); $postData['InstallSettingsForm']['hostInfo'] = 'http://www.example.com'; $this->setPostArray($postData); $content = $this->runControllerWithExitExceptionAndGetContent('install/default/settings'); $errors = CJSON::decode($content); $this->assertEquals(0, count($errors)); //Run installation. $this->setPostArray(array('InstallSettingsForm' => array('databaseHostname' => $this->databaseHostname, 'databaseAdminUsername' => '', 'databaseAdminPassword' => '', 'databaseName' => $this->databaseName, 'databaseUsername' => $this->databaseUsername, 'databasePassword' => $this->databasePassword, 'databasePort' => $this->databasePort, 'superUserPassword' => $this->superUserPassword, 'memcacheHostname' => 'localhost', 'memcachePortNumber' => '11211', 'memcacheAvailable' => '1', 'databaseType' => 'mysql', 'removeExistingData' => '1', 'installDemoData' => '', 'hostInfo' => 'http://www.example.com'))); //Close db connection(new will be created during installation process). RedBeanDatabase::close(); $this->runControllerWithExitExceptionAndGetContent('install/default/settings'); $industryFieldData = CustomFieldData::getByName('Industries'); $this->assertGreaterThan('0', count(unserialize($industryFieldData->serializedData))); //Check installDemoData action. RedBeanDatabase::close(); DemoDataUtil::unsetLoadedModules(); $this->runControllerWithNoExceptionsAndGetContent('install/default/installDemoData'); $this->assertGreaterThan('0', Account::getAll()); $this->assertGreaterThan('0', Contact::getAll()); //Restore $_SERVER['SERVER_SOFTWARE'] if (isset($serverSoftware)) { $_SERVER['SERVER_SOFTWARE'] = $serverSoftware; } else { unset($_SERVER['SERVER_SOFTWARE']); } }