Newer
Older
// change the language back to en
if ($this->lastLanguage != 'en') {
$this->changeLanguage('en');
if (!empty($this->missingExpectedFiles)) {
$expectedDir = dirname(reset($this->missingExpectedFiles));
$this->markTestIncomplete(" ERROR: Could not find expected API output '"
. implode("', '", $this->missingExpectedFiles)
. "'. For new tests, to pass the test, you can copy files from the processed/ directory into"
. " $expectedDir after checking that the output is valid. %s ");
}
// Display as one error all sub-failures
if (!empty($this->comparisonFailures)) {
$messages = '';
$i = 1;
foreach ($this->comparisonFailures as $failure) {
$msg = $failure->getMessage();
$msg = strtok($msg, "\n");
$messages .= "\n#" . $i++ . ": " . $msg;
}
$messages .= " \n ";
print($messages);
$first = reset($this->comparisonFailures);
throw $first;
}
}
/**
* changing the language within one request is a bit fancy
* in order to keep the core clean, we need a little hack here
*
* @param string $langId
*/
protected function changeLanguage($langId)
{
if ($this->lastLanguage != $langId) {
$_GET['language'] = $langId;
Piwik_Translate::reset();
Piwik_Translate::getInstance()->reloadLanguage($langId);
}
$this->lastLanguage = $langId;
}
/**
* Path where expected/processed output files are stored. Can be overridden.
*/
public function getPathToTestDirectory()
{
return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Integration';
}
/**
* Returns an array associating table names w/ lists of row data.
* @return array
*/
protected static function getDbTablesWithData()
{
$result = array();
foreach (Piwik::getTablesInstalled() as $tableName) {
$result[$tableName] = Piwik_FetchAll("SELECT * FROM $tableName");
}
return $result;
/**
* Truncates all tables then inserts the data in $tables into each
* mapped table.
* @param array $tables Array mapping table names with arrays of row data.
*/
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
protected static function restoreDbTables($tables)
{
// truncate existing tables
Piwik::truncateAllTables();
// insert data
$existingTables = Piwik::getTablesInstalled();
foreach ($tables as $table => $rows) {
// create table if it's an archive table
if (strpos($table, 'archive_') !== false && !in_array($table, $existingTables)) {
$tableType = strpos($table, 'archive_numeric') !== false ? 'archive_numeric' : 'archive_blob';
$createSql = Piwik::getTableCreateSql($tableType);
$createSql = str_replace(Piwik_Common::prefixTable($tableType), $table, $createSql);
Piwik_Query($createSql);
}
if (empty($rows)) {
continue;
}
$rowsSql = array();
foreach ($rows as $row) {
$values = array();
foreach ($row as $name => $value) {
if (is_null($value)) {
$values[] = 'NULL';
} else if (is_numeric($value)) {
$values[] = $value;
} else if (!ctype_print($value)) {
$values[] = "x'" . bin2hex(substr($value, 1)) . "'";
} else {
$values[] = "'$value'";
}
}
$rowsSql[] = "(" . implode(',', $values) . ")";
}
$sql = "INSERT INTO $table VALUES " . implode(',', $rowsSql);
Piwik_Query($sql);
}
}
/**
* Drops all archive tables.
*/
public static function deleteArchiveTables()
foreach (Piwik_DataAccess_ArchiveTableCreator::getTablesArchivesInstalled() as $table) {
Piwik_Query("DROP TABLE IF EXISTS $table");
}
mattab
a validé
Piwik_DataAccess_ArchiveTableCreator::refreshTableList($forceReload = true);