execute() 공개 메소드

public execute ( PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet )
$connection PHPUnit_Extensions_Database_DB_IDatabaseConnection
$dataSet PHPUnit_Extensions_Database_DataSet_IDataSet
 public function testTruncate()
 {
     $truncateOperation = new PHPUnit_Extensions_Database_Operation_Truncate();
     $truncateOperation->execute($this->getConnection(), new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/DeleteAllOperationTest.xml'));
     $expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array(new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4'))), new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', array('table2_id', 'column5', 'column6', 'column7', 'column8'))), new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table3', array('table3_id', 'column9', 'column10', 'column11', 'column12')))));
     $this->assertDataSetsEqual($expectedDataSet, $this->getConnection()->createDataSet());
 }
 public function testTruncateComposite()
 {
     $truncateOperation = new PHPUnit_Extensions_Database_Operation_Truncate();
     $truncateOperation->execute($this->getConnection(), $this->getCompositeDataSet());
     $expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array(new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4'))), new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', array('table2_id', 'table1_id', 'column5', 'column6', 'column7', 'column8'))), new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table3', array('table3_id', 'table2_id', 'column9', 'column10', 'column11', 'column12')))));
     $this->assertDataSetsEqual($expectedDataSet, $this->getConnection()->createDataSet());
 }
예제 #3
0
 public function execute(\PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, \PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
 {
     $connection->getConnection()->query("SET @PHAKE_PREV_foreign_key_checks = @@FOREIGN_KEY_CHECKS");
     $connection->getConnection()->query("SET FOREIGN_KEY_CHECKS = 0");
     parent::execute($connection, $dataSet);
     $connection->getConnection()->query("SET FOREIGN_KEY_CHECKS = @PHAKE_PREV_foreign_key_checks");
 }
예제 #4
0
파일: rowTest.php 프로젝트: Notacadet/RFID
 public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
 {
     $connection->getConnection()->query("SET @PHAKE_PREV_foreign_key_checks = @@foreign_key_checks");
     $connection->getConnection()->query("SET foreign_key_checks = 0");
     parent::execute($connection, $dataSet);
     $connection->getConnection()->query("SET foreign_key_checks = @PHAKE_PREV_foreign_key_checks");
 }
예제 #5
0
 /**
  *  Test setup for every test
  *
  *  Connect to the database, truncate the tables that will be used
  *  and redirect stdin to a temporary file
  */
 public function setUp()
 {
     //  Connect to the database
     parent::setUp();
     //  Truncate the tables
     $op = new PHPUnit_Extensions_Database_Operation_Truncate();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/../../CiviTest/truncate-option.xml'));
     //  Insert a row in civicrm_contact creating contact 17
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml'));
     //  Insert a row in civicrm_option_group creating option group
     //  activity_type
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/option_group_activity_type.xml'));
     //  Insert a row in civicrm_option_value creating
     //  activity_type 5
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/option_value_activity_5.xml'));
 }
예제 #6
0
 public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, 
                         PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) {
   $truncate = new PHPUnit_Extensions_Database_Operation_Truncate(true);
   $truncate->setCascade(true);
   $dataset = new OBM_Database_CsvDataSet(';');
   $dataset->addTable('Entity');
   $truncate->execute($connection, $dataset);
   
   $pdo = $connection->getConnection(); // we retrieve the PDO object
   parent::execute($connection, $dataSet);
   
   $dsIterator = $dataSet->getIterator();
   foreach ($dsIterator as $table) {
     $tableName = $table->getTableMetaData()->getTableName();
     if ($dataSet->isEntityTable($tableName)) {
       $entities = $dataSet->getEntityName($tableName);
       if(!is_array($entities)) $entities = array($entities);
       foreach($entities as $entity) {
         for ($i = 1; $i <= $table->getRowCount(); $i++) {
           $pdo->exec('INSERT INTO Entity (entity_mailing) VALUES (TRUE)');
           $entityId = $pdo->lastInsertId();
           $query = 'INSERT INTO '.ucfirst($entity).'Entity ('.$entity.'entity_entity_id, '.$entity.'entity_'.$entity.'_id )
                     SELECT MAX(entity_id), '.$i.' FROM Entity';
           $pdo->exec($query);
         }
       }
     }
   }
 }
예제 #7
0
 /**
  *  Test civicrm_constant_get( 'locationType' )
  */
 public function testLocationType()
 {
     // needed to get rid of cached values from previous tests
     CRM_Core_Pseudoconstant::flush('locationType');
     $dataset = new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/location_type_data.xml');
     //  We don't want default set, we want our own, so clean up first
     $tr = new PHPUnit_Extensions_Database_Operation_Truncate();
     $tr->execute($this->_dbconn, $dataset);
     //  Insert default location type values
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, $dataset);
     $result = civicrm_constant_get('locationType');
     $this->assertEquals(4, count($result), "In line " . __LINE__);
     $this->assertContains('Home', $result, "In line " . __LINE__);
     $this->assertContains('Work', $result, "In line " . __LINE__);
     $this->assertContains('Main', $result, "In line " . __LINE__);
     $this->assertContains('Billing', $result, "In line " . __LINE__);
     $this->assertTrue(empty($result['is_error']), "In line " . __LINE__);
 }
예제 #8
0
 /**
  *  Common setup functions for all unit tests
  */
 protected function setUp()
 {
     // "initialize" CiviCRM to avoid problems when running single tests
     // FIXME: look at it closer in second stage
     if (isset($config)) {
         unset($config);
     }
     require_once 'CRM/Core/Config.php';
     $config =& CRM_Core_Config::singleton();
     //  Use a temporary file for STDIN
     $GLOBALS['stdin'] = tmpfile();
     if ($GLOBALS['stdin'] === false) {
         echo "Couldn't open temporary file\n";
         exit(1);
     }
     //  Get and save a connection to the database
     $this->_dbconn = $this->getConnection();
     //  Truncate the tables
     $op = new PHPUnit_Extensions_Database_Operation_Truncate();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/truncate.xml'));
     // Load clean db state
     $sql_file = dirname(dirname(dirname(__FILE__))) . "/../sql/civicrm_data.mysql";
     $query = file_get_contents($sql_file);
     if (AllTests::$utils->do_query($query) === false) {
         //  failed to initialze test database
         echo "Cannot load civicrm_data.mysql";
         exit;
     }
 }
예제 #9
0
 /**
  *  Test CRM_Contact_Form_Search_Custom_Group::contactIDs()
  *  @dataProvider dataProvider
  */
 public function testContactIDs($fv, $count, $ids, $full)
 {
     //  Truncate the tables
     $op = new PHPUnit_Extensions_Database_Operation_Truncate();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/../../../../../CiviTest/truncate-option.xml'));
     // echo "testContactIDs\n";
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset.xml'));
     $obj = new CRM_Contact_Form_Search_Custom_Group($fv);
     $sql = $obj->contactIDs();
     $this->assertTrue(is_string($sql), 'In line ' . __LINE__);
     $dao =& CRM_Core_DAO::executeQuery($sql);
     $contacts = array();
     while ($dao->fetch()) {
         $contacts[] = $dao->contact_id;
     }
     sort($contacts, SORT_NUMERIC);
     $this->assertEquals($ids, $contacts, 'In line ' . __LINE__);
 }