Example #1
0
 public function testCustomAdditionalDetailsMetadataFileIsUsedBeforeNonCustomOne()
 {
     sugar_touch("modules/{$this->moduleName}/metadata/additionalDetails.php");
     sugar_touch("custom/modules/{$this->moduleName}/metadata/additionalDetails.php");
     $viewObject = new Bug40216Mock();
     $this->assertEquals("custom/modules/{$this->moduleName}/metadata/additionalDetails.php", $viewObject->getAdditionalDetailsMetadataFile($this->moduleName));
 }
Example #2
0
 public function setUp()
 {
     sugar_mkdir('tests/include/utils/ziptest/testarchive', null, true);
     sugar_touch('tests/include/utils/ziptest/testarchive/testfile1.txt');
     sugar_touch('tests/include/utils/ziptest/testarchive/testfile2.txt');
     sugar_touch('tests/include/utils/ziptest/testarchive/testfile3.txt');
     sugar_mkdir('tests/include/utils/ziptest/testarchiveoutput', null, true);
 }
Example #3
0
 public function setUp()
 {
     $this->testdir = sugar_cached("tests/include/utils/ziptest");
     sugar_mkdir($this->testdir . '/testarchive', null, true);
     sugar_touch($this->testdir . '/testarchive/testfile1.txt');
     sugar_touch($this->testdir . '/testarchive/testfile2.txt');
     sugar_touch($this->testdir . '/testarchive/testfile3.txt');
     sugar_mkdir($this->testdir . '/testarchiveoutput', null, true);
 }
Example #4
0
 public function testDisplayWithClassicCustomView()
 {
     $view = $this->getMock('ViewClassic', array('includeClassicFile'));
     $view->module = 'testmodule' . mt_rand();
     $view->action = 'testaction' . mt_rand();
     sugar_mkdir("custom/modules/{$view->module}", null, true);
     sugar_touch("custom/modules/{$view->module}/{$view->action}.php");
     $return = $view->display();
     rmdir_recursive("custom/modules/{$view->module}");
     $this->assertTrue($return);
 }
 public function run()
 {
     if (version_compare($this->from_version, '7.6', '>=')) {
         return;
     }
     foreach (glob('custom/include/language/*.lang.php') as $file) {
         if (is_dir($file)) {
             continue;
         }
         sugar_touch($file);
     }
 }
Example #6
0
 public function setUp()
 {
     $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
     $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
     $GLOBALS['module'] = 'Imports';
     $_REQUEST['module'] = 'Imports';
     $_REQUEST['import_module'] = 'Accounts';
     $_REQUEST['action'] = 'last';
     $_REQUEST['type'] = '';
     $_REQUEST['has_header'] = 'off';
     sugar_touch('upload/import/status_' . $GLOBALS['current_user']->id . '.csv');
 }
Example #7
0
 public function setUp()
 {
     if (!class_exists('ZipArchive')) {
         $this->markTestSkipped('ZipArchive class not loaded');
     }
     $this->testdir = sugar_cached("tests/include/utils/ziptest");
     sugar_mkdir($this->testdir . '/testarchive', null, true);
     sugar_touch($this->testdir . '/testarchive/testfile1.txt');
     sugar_touch($this->testdir . '/testarchive/testfile2.txt');
     sugar_touch($this->testdir . '/testarchive/testfile3.txt');
     sugar_mkdir($this->testdir . '/testarchiveoutput', null, true);
 }
 public function testCallLegacyCodeIfLegacyDetailViewAndNewDetailViewFoundAndCustomLegacyDetailViewFoundAndCustomNewDetailViewFound()
 {
     $module_name = 'TestModule' . mt_rand();
     sugar_mkdir("custom/modules/{$module_name}/views", null, true);
     sugar_touch("custom/modules/{$module_name}/views/view.detail.php");
     sugar_touch("custom/modules/{$module_name}/DetailView.php");
     sugar_mkdir("modules/{$module_name}/views", null, true);
     sugar_touch("modules/{$module_name}/views/view.detail.php");
     sugar_touch("modules/{$module_name}/DetailView.php");
     $controller = new SugarControllerMock();
     $controller->setup($module_name);
     $controller->do_action = 'DetailView';
     $controller->view = 'list';
     $controller->callLegacyCode();
     $this->assertEquals('list', $controller->view);
     rmdir_recursive("modules/{$module_name}");
 }
Example #9
0
 function copy_recursive_with_backup($source, $dest, $backup_path, $uninstall = false)
 {
     if (is_file($source)) {
         if ($uninstall) {
             $GLOBALS['log']->debug("Restoring ... " . $source . " to " . $dest);
             if (copy($source, $dest)) {
                 if (is_writable($dest)) {
                     sugar_touch($dest, filemtime($source));
                 }
                 return unlink($source);
             } else {
                 $GLOBALS['log']->debug("Can't restore file: " . $source);
                 return true;
             }
         } else {
             if (file_exists($dest)) {
                 $rest = clean_path($backup_path . "/{$dest}");
                 if (!is_dir(dirname($rest))) {
                     mkdir_recursive(dirname($rest), true);
                 }
                 $GLOBALS['log']->debug("Backup ... " . $dest . " to " . $rest);
                 if (copy($dest, $rest)) {
                     if (is_writable($rest)) {
                         sugar_touch($rest, filemtime($dest));
                     }
                 } else {
                     $GLOBALS['log']->debug("Can't backup file: " . $dest);
                 }
             }
             return copy($source, $dest);
         }
     } elseif (!is_dir($source)) {
         if ($uninstall) {
             if (is_file($dest)) {
                 return unlink($dest);
             } else {
                 //don't do anything we already cleaned up the files using uninstall_new_files
                 return true;
             }
         } else {
             return false;
         }
     }
     if (!is_dir($dest) && !$uninstall) {
         sugar_mkdir($dest);
     }
     $status = true;
     $d = dir($source);
     while ($f = $d->read()) {
         if ($f == "." || $f == "..") {
             continue;
         }
         $status &= $this->copy_recursive_with_backup("{$source}/{$f}", "{$dest}/{$f}", $backup_path, $uninstall);
     }
     $d->close();
     return $status;
 }
Example #10
0
/**
 * sugar_file_get_contents
 *
 * @param $filename - String value of the file to create
 * @param $use_include_path - boolean value indicating whether or not to search the the included_path
 * @param $context
 * @return string|boolean - Returns a file data on success, false otherwise
 */
function sugar_file_get_contents($filename, $use_include_path = false, $context = null)
{
    //check to see if the file exists, if not then use touch to create it.
    if (!file_exists($filename)) {
        sugar_touch($filename);
    }
    if (!is_readable($filename)) {
        $GLOBALS['log']->error("File {$filename} cannot be read");
        return false;
    }
    if (empty($context)) {
        return file_get_contents($filename, $use_include_path);
    } else {
        return file_get_contents($filename, $use_include_path, $context);
    }
}
                if ($install_type == "patch" && is_file($dest_file)) {
                    if (!is_dir(dirname($rest_file))) {
                        mkdir_recursive(dirname($rest_file));
                    }
                    copy($dest_file, $rest_file);
                    sugar_touch($rest_file, filemtime($dest_file));
                }
                if (!copy($src_file, $dest_file)) {
                    die($mod_strings['ERR_UW_COPY_FAILED'] . $src_file . $mod_strings['LBL_TO'] . $dest_file);
                }
                $uh_status = "installed";
                break;
            case "Uninstall":
                if ($install_type == "patch" && is_file($rest_file)) {
                    copy($rest_file, $dest_file);
                    sugar_touch($dest_file, filemtime($rest_file));
                } elseif (file_exists($dest_file) && !unlink($dest_file)) {
                    die($mod_strings['ERR_UW_REMOVE_FAILED'] . $dest_file);
                }
                $uh_status = "uninstalled";
                break;
            default:
                die("{$mod_strings['LBL_UW_OP_MODE']} '{$mode}' {$mod_strings['ERR_UW_NOT_RECOGNIZED']}.");
        }
        $files_to_handle[] = clean_path("{$zip_to_dir}/{$file_to_copy}");
    }
}
switch ($install_type) {
    case "langpack":
        if (!isset($_REQUEST['new_lang_name']) || $_REQUEST['new_lang_name'] == "") {
            die($mod_strings['ERR_UW_NO_LANG']);
 public function testSugarTouchWithAccessTime()
 {
     $time = filemtime($this->_filename);
     $atime = gmmktime();
     $this->assertTrue(sugar_touch($this->_filename, $time, $atime));
     $this->assertEquals($time, filemtime($this->_filename));
     $this->assertEquals($atime, fileatime($this->_filename));
 }
Example #13
0
/**
 * searchEngineDown
 *
 * This function creates a cache file to indicate search engine is down
 *
 */
function searchEngineDown()
{
    $cacheDir = create_cache_directory('fts/');
    sugar_touch($cacheDir . '/fts_down');
}
Example #14
0
 public function testGetTemplateDefaultCustom()
 {
     create_custom_directory('themes/default/tpls/');
     sugar_touch('custom/themes/default/tpls/SomeDefaultTemplate.tpl');
     $this->assertEquals('custom/themes/default/tpls/SomeDefaultTemplate.tpl', $this->_themeObject->getTemplate('SomeDefaultTemplate.tpl'));
     unlink('custom/themes/default/tpls/SomeDefaultTemplate.tpl');
 }
    /**
     * Enable and Show the RevenueLine Item Module
     *
     * - Add the file that shows the RLI Module
     * - Adds the `studio.php` file
     * - Puts  RLI module from the menu bar
     * - Adds the ACL Actions
     */
    protected function fixRevenueLineItemModule()
    {
        // lets make sure the dir is there
        SugarAutoLoader::ensureDir($this->rliModuleExtFolder . '/Vardefs');
        $file_contents = <<<EOL
<?php
\$dictionary['RevenueLineItem']['importable'] = true;
\$dictionary['RevenueLineItem']['unified_search'] = true;
EOL;
        sugar_file_put_contents($this->rliModuleExtFolder . '/Vardefs/' . $this->rliModuleExtVardefFile, $file_contents);
        SugarAutoLoader::ensureDir($this->appExtFolder . '/Include');
        // we need to run the code we are putting in the custom file
        $GLOBALS['moduleList'][] = 'RevenueLineItems';
        if (isset($GLOBALS['modInvisList']) && is_array($GLOBALS['modInvisList'])) {
            foreach ($GLOBALS['modInvisList'] as $key => $mod) {
                if ($mod === 'RevenueLineItems') {
                    unset($GLOBALS['modInvisList'][$key]);
                }
            }
        }
        $file_contents = <<<EOL
<?php
\$moduleList[] = 'RevenueLineItems';
if (isset(\$modInvisList) && is_array(\$modInvisList)) {
    foreach (\$modInvisList as \$key => \$mod) {
        if (\$mod === 'RevenueLineItems') {
            unset(\$modInvisList[\$key]);
        }
    }
}
EOL;
        sugar_file_put_contents($this->appExtFolder . '/Include/' . $this->rliModuleExtFile, $file_contents);
        // enable the ACLs on RevenueLineItems
        ACLAction::addActions('RevenueLineItems');
        // show the rli module in WorkFlows
        $affected_modules = $this->toggleRevenueLineItemsLinkInWorkFlows(true);
        // show the rli module in the mega menu
        $this->setRevenueLineItemModuleTab(true);
        // handle the parent_type_field
        $this->setRevenueLineItemInParentRelateDropDown(true);
        // enable the item in the quick create
        $this->toggleRevenueLineItemQuickCreate(true);
        // place the studio file
        sugar_touch($this->rliStudioFile);
        $affected_modules[] = 'RevenueLineItems';
        return $affected_modules;
    }
 /**
  * @dataProvider scanCopyProvider
  * @param string $from
  * @param string $to
  * @param bool $ok is it supposed to be ok?
  */
 public function testScanCopy($file, $from, $to, $ok)
 {
     $this->markTestIncomplete('This test requires files.md5.');
     if (is_file('files.md5')) {
         copy('files.md5', 'files.md5.copy');
     }
     copy(__DIR__ . "/../upgrade/files.md5", "files.md5");
     // ensure target file exists
     $from = sugar_cached("ModuleScannerTest/{$from}");
     $file = sugar_cached("ModuleScannerTest/{$file}");
     mkdir_recursive(dirname($file));
     sugar_touch($file);
     $ms = new ModuleScanner();
     $ms->scanCopy($from, $to);
     if ($ok) {
         $this->assertEmpty($ms->getIssues(), "Issue found where it should not be");
     } else {
         $this->assertNotEmpty($ms->getIssues(), "Issue not detected");
     }
     // check with dir
     $ms->scanCopy(dirname($from), $to);
     if ($ok) {
         $this->assertEmpty($ms->getIssues(), "Issue found where it should not be");
     } else {
         $this->assertNotEmpty($ms->getIssues(), "Issue not detected");
     }
 }
Example #17
0
/**
 * sugar_file_put_contents
 * Call this function instead of file_put_contents to apply preconfigured permission
 * settings when creating the the file.  This method is basically
 * a wrapper to the PHP file_put_contents function except that it supports setting
 * the mode value by using the configuration file (if set).  The mode is
 * 0777 by default.
 *
 * @param $filename - String value of the file to create
 * @param $data - The data to be written to the file
 * @param $flags - int as specifed by file_put_contents parameters
 * @param $context
 * @return int - Returns the number of bytes written to the file, false otherwise.
 */
function sugar_file_put_contents($filename, $data, $flags = null, $context = null)
{
    //check to see if the file exists, if not then use touch to create it.
    if (!file_exists($filename)) {
        sugar_touch($filename);
    }
    if (!is_writable($filename)) {
        $GLOBALS['log']->error("File {$filename} cannot be written to");
        return false;
    }
    if (empty($flags)) {
        $return = file_put_contents($filename, $data);
    } elseif (empty($context)) {
        $return = file_put_contents($filename, $data, $flags);
    } else {
        $return = file_put_contents($filename, $data, $flags, $context);
    }
    // Add to the file loader cache if it isn't there
    if ($return) {
        if (!SugarAutoLoader::fileExists($filename)) {
            SugarAutoLoader::addToMap($filename);
        }
    }
    return $return;
}
/**
 * sugar_file_put_contents
 * Call this function instead of file_put_contents to apply preconfigured permission
 * settings when creating the the file.  This method is basically
 * a wrapper to the PHP file_put_contents function except that it supports setting
 * the mode value by using the configuration file (if set).  The mode is
 * 0777 by default.
 *
 * @param $filename - String value of the file to create
 * @param $data - The data to be written to the file
 * @param $flags - int as specifed by file_put_contents parameters
 * @param $context
 * @return int - Returns the number of bytes written to the file, false otherwise.
 */
function sugar_file_put_contents($filename, $data, $flags = null, $context = null)
{
    //check to see if the file exists, if not then use touch to create it.
    if (!file_exists($filename)) {
        sugar_touch($filename);
    }
    if (empty($flags)) {
        return file_put_contents($filename, $data);
    } elseif (empty($context)) {
        return file_put_contents($filename, $data, $flags);
    } else {
        return file_put_contents($filename, $data, $flags, $context);
    }
}
 public static function createAnonymousRTLTheme()
 {
     $themename = 'TestTheme' . mt_rand();
     sugar_mkdir("themes/{$themename}/images", null, true);
     sugar_mkdir("themes/{$themename}/css", null, true);
     sugar_mkdir("themes/{$themename}/js", null, true);
     sugar_mkdir("themes/{$themename}/tpls", null, true);
     sugar_file_put_contents("themes/{$themename}/css/style.css", "h2 { display: inline; }");
     sugar_file_put_contents("themes/{$themename}/css/yui.css", ".yui { display: inline; }");
     sugar_file_put_contents("themes/{$themename}/js/style.js", 'var dog = "cat";');
     sugar_touch("themes/{$themename}/images/Accounts.gif");
     sugar_touch("themes/{$themename}/images/fonts.big.icon.gif");
     sugar_touch("themes/{$themename}/tpls/header.tpl");
     $themedef = "<?php\n";
     $themedef .= "\$themedef = array(\n";
     $themedef .= "'name'  => '{$themename}',";
     $themedef .= "'dirName'  => '{$themename}',";
     $themedef .= "'description' => '{$themename}',";
     $themedef .= "'directionality' => 'rtl',";
     $themedef .= "'version' => array('regex_matches' => array('.*')),";
     $themedef .= ");";
     sugar_file_put_contents("themes/{$themename}/themedef.php", $themedef);
     self::$_createdThemes[] = $themename;
     SugarThemeRegistry::buildRegistry();
     return $themename;
 }
Example #20
0
}
// try to use the content cached locally if it's the same as we have here.
if (defined('TEMPLATE_URL')) {
    $last_modified_time = time();
} else {
    $last_modified_time = filemtime($filename);
}
$etag = '"' . md5_file($filename) . '"';
header("Cache-Control: private");
header("Pragma: dummy=bogus");
header("Etag: {$etag}");
header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 2592000));
$ifmod = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $last_modified_time : null;
$iftag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] == $etag : null;
if (($ifmod || $iftag) && ($ifmod !== false && $iftag !== false)) {
    header($_SERVER["SERVER_PROTOCOL"] . ' 304 Not Modified');
    die;
}
header("Last-Modified: " . gmdate('D, d M Y H:i:s \\G\\M\\T', $last_modified_time));
// now send the content
if (substr($filename, -3) == 'gif') {
    header("Content-Type: image/gif");
} elseif (substr($filename, -3) == 'png') {
    header("Content-Type: image/png");
}
if (!defined('TEMPLATE_URL')) {
    if (!file_exists($filename)) {
        sugar_touch($filename);
    }
}
readfile($filename);
Example #21
0
 /**
  * Create empty file and add to map
  * To use mainly for tests
  * @param string $filename
  * @param bool $save Save map to file?
  * @return bool Success?
  */
 public static function touch($filename, $save = false)
 {
     if (sugar_touch($filename)) {
         self::addToMap($filename, $save);
         return true;
     }
     return false;
 }