Exemple #1
0
 public function run($ctx)
 {
     /** @var $ctx \CiviEnvBuilder */
     if (\Civi\Test::execute(@file_get_contents($this->file)) === FALSE) {
         throw new \RuntimeException("Cannot load {$this->file}. Aborting.");
     }
 }
Exemple #2
0
 public function run($ctx)
 {
     /** @var $ctx \CiviEnvBuilder */
     if (\Civi\Test::execute($this->sql) === FALSE) {
         throw new \RuntimeException("Cannot execute: {$this->sql}");
     }
 }
Exemple #3
0
 /**
  * @return bool
  */
 public function populate()
 {
     \Civi\Test::schema()->truncateAll();
     \Civi\Test::schema()->setStrict(FALSE);
     $sqlDir = dirname(dirname(__DIR__)) . "/sql";
     $query2 = file_get_contents("{$sqlDir}/civicrm_data.mysql");
     $query3 = file_get_contents("{$sqlDir}/test_data.mysql");
     $query4 = file_get_contents("{$sqlDir}/test_data_second_domain.mysql");
     if (\Civi\Test::execute($query2) === FALSE) {
         throw new RuntimeException("Cannot load civicrm_data.mysql. Aborting.");
     }
     if (\Civi\Test::execute($query3) === FALSE) {
         throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
     }
     if (\Civi\Test::execute($query4) === FALSE) {
         throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
     }
     unset($query, $query2, $query3);
     \Civi\Test::schema()->setStrict(TRUE);
     // Rebuild triggers
     civicrm_api('system', 'flush', array('version' => 3, 'triggers' => 1));
     \CRM_Core_BAO_ConfigSetting::setEnabledComponents(array('CiviEvent', 'CiviContribute', 'CiviMember', 'CiviMail', 'CiviReport', 'CiviPledge'));
     return TRUE;
 }
 /**
  * Determine if there's been a change in the preferred configuration.
  * If the preferred-configuration matches the last test, keep it. Otherwise,
  * destroy and recreate.
  *
  * @param bool $force
  *   Forcibly execute the build, even if the configuration hasn't changed.
  *   This will slow-down the tests, but it may be appropriate for some very sloppy
  *   tests.
  * @return $this
  */
 public function apply($force = FALSE)
 {
     $dbName = \Civi\Test::dsn('database');
     $query = "USE {$dbName};" . "CREATE TABLE IF NOT EXISTS civitest_revs (name VARCHAR(64) PRIMARY KEY, rev VARCHAR(64));";
     if (\Civi\Test::execute($query) === FALSE) {
         throw new \RuntimeException("Failed to flag schema version: {$query}");
     }
     $this->assertValid();
     if (!$force && $this->getSavedSignature() === $this->getTargetSignature()) {
         return $this;
     }
     foreach ($this->steps as $step) {
         $step->run($this);
     }
     $this->setSavedSignature($this->getTargetSignature());
     return $this;
 }
 public function setUpHeadless()
 {
     return \Civi\Test::headless()->apply();
 }
Exemple #6
0
 public function setUpHeadless()
 {
     return \Civi\Test::headless()->installMe(__DIR__)->apply();
 }
Exemple #7
0
 /**
  * @return array
  */
 public function truncateAll()
 {
     $tables = \Civi\Test::schema()->getTables('BASE TABLE');
     $truncates = array();
     $drops = array();
     foreach ($tables as $table) {
         // skip log tables
         if (substr($table, 0, 4) == 'log_') {
             continue;
         }
         // don't change list of installed extensions
         if ($table == 'civicrm_extension') {
             continue;
         }
         if (substr($table, 0, 14) == 'civicrm_value_') {
             $drops[] = 'DROP TABLE ' . $table . ';';
         } elseif (substr($table, 0, 9) == 'civitest_') {
             // ignore
         } else {
             $truncates[] = 'TRUNCATE ' . $table . ';';
         }
     }
     \Civi\Test::schema()->setStrict(FALSE);
     $queries = array_merge($truncates, $drops);
     foreach ($queries as $query) {
         if (\Civi\Test::execute($query) === FALSE) {
             throw new RuntimeException("Query failed: {$query}");
         }
     }
     \Civi\Test::schema()->setStrict(TRUE);
     return $this;
 }
 public function setUpHeadless()
 {
     // Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
     // See: https://github.com/civicrm/org.civicrm.testapalooza/blob/master/civi-test.md
     return \Civi\Test::headless()->installMe(__DIR__)->apply();
 }
Exemple #9
0
 /**
  * Prepare and execute a batch of SQL statements.
  *
  * @param string $query
  * @return bool
  */
 public static function execute($query)
 {
     $pdo = \Civi\Test::pdo();
     $string = preg_replace("/^#[^\n]*\$/m", "\n", $query);
     $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
     $queries = preg_split('/;\\s*$/m', $string);
     foreach ($queries as $query) {
         $query = trim($query);
         if (!empty($query)) {
             $result = $pdo->query($query);
             if ($pdo->errorCode() == 0) {
                 continue;
             } else {
                 var_dump($result);
                 var_dump($pdo->errorInfo());
                 // die( "Cannot execute $query: " . $pdo->errorInfo() );
             }
         }
     }
     return TRUE;
 }