/** * A method to test the saveAllocatedImpressions method. */ function testSaveAllocatedImpressions() { $oDbh =& OA_DB::singleton(); $oDal = new OA_Dal_Maintenance_Priority(); // Create the required temporary table for the tests $oTable =& OA_DB_Table_Priority::singleton(); $oTable->createTable('tmp_ad_zone_impression'); // Prepare the test data $aData = array(array('ad_id' => 56, 'zone_id' => 11, 'required_impressions' => 9997, 'requested_impressions' => 9000), array('ad_id' => 56, 'zone_id' => 12, 'required_impressions' => 24, 'requested_impressions' => 24)); $result = $oDal->saveAllocatedImpressions($aData); $query = "SELECT * FROM " . $oDbh->quoteIdentifier('tmp_ad_zone_impression', true) . " ORDER BY ad_id, zone_id"; $rc = $oDbh->query($query); $result = $rc->fetchAll(); $this->assertTrue(is_array($result)); $this->assertTrue(count($result) == 2); $tmp = $result[0]; $this->assertTrue(array_key_exists('ad_id', $tmp)); $this->assertEqual($tmp['ad_id'], 56); $this->assertTrue(array_key_exists('zone_id', $tmp)); $this->assertEqual($tmp['zone_id'], 11); $this->assertTrue(array_key_exists('required_impressions', $tmp)); $this->assertEqual($tmp['required_impressions'], 9997); $this->assertTrue(array_key_exists('requested_impressions', $tmp)); $this->assertEqual($tmp['requested_impressions'], 9000); $tmp = $result[1]; $this->assertTrue(array_key_exists('ad_id', $tmp)); $this->assertEqual($tmp['ad_id'], 56); $this->assertTrue(array_key_exists('zone_id', $tmp)); $this->assertEqual($tmp['zone_id'], 12); $this->assertTrue(array_key_exists('required_impressions', $tmp)); $this->assertEqual($tmp['required_impressions'], 24); $this->assertTrue(array_key_exists('requested_impressions', $tmp)); $this->assertEqual($tmp['requested_impressions'], 24); TestEnv::dropTempTables(); }
function _testBatchInsert($method) { $oTable =& OA_DB_Table_Priority::singleton(); $oTable->createTable('tmp_ad_required_impression'); $this->assertEqual(array(), $this->_getbatchInsertRecords()); $aData = array(array('ad_id' => '23', 'required_impressions' => '140'), array('ad_id' => '29', 'required_impressions' => '120')); $result = OA_Dal::$method('tmp_ad_required_impression', array('ad_id', 'required_impressions'), $aData); $this->assertEqual($result, 2); $result = $this->_getbatchInsertRecords(); $this->assertTrue(count($result) == 2); $this->assertEqual($result, $aData); $oneMoreRow = array(array(100, 2)); $result = OA_Dal::$method('tmp_ad_required_impression', array('ad_id', 'required_impressions'), $oneMoreRow); $this->assertEqual($result, 1); $result = $this->_getbatchInsertRecords(); $this->assertTrue(count($result) == 3); $this->assertEqual($result, array_merge($aData, array(array('ad_id' => 100, 'required_impressions' => 2)))); TestEnv::dropTempTables(); }
/** * Method to test the getAllZonesWithAllocInv method. * * Requirements: * Test 1: Test with no data, and ensure no data returned. * Test 2: Test with sample data, and ensure the correct data is returned. */ function DEPRECATED_testGetAllZonesWithAllocInv() { $conf = $GLOBALS['_MAX']['CONF']; $oDbh =& OA_DB::singleton(); $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority(); // Create the required temporary table for the tests $oTable =& OA_DB_Table_Priority::singleton(); $oTable->createTable('tmp_ad_zone_impression'); $tableTmp = $oDbh->quoteIdentifier('tmp_ad_zone_impression', true); // Test 1 $result =& $oMaxDalMaintenance->getAllZonesWithAllocInv(); $this->assertEqual(count($result), 0); // Test 2 $query = "\n INSERT INTO\n {$tableTmp}\n (\n ad_id,\n zone_id,\n required_impressions,\n requested_impressions\n )\n VALUES\n (\n 1,\n 1,\n 2,\n 3\n )"; $rows = $oDbh->exec($query); $query = "\n INSERT INTO\n {$tableTmp}\n (\n ad_id,\n zone_id,\n required_impressions,\n requested_impressions\n )\n VALUES\n (\n 1,\n 2,\n 4,\n 5\n )"; $rows = $oDbh->exec($query); $query = "\n INSERT INTO\n {$tableTmp}\n (\n ad_id,\n zone_id,\n required_impressions,\n requested_impressions\n )\n VALUES\n (\n 2,\n 2,\n 6,\n 7\n )"; $rows = $oDbh->exec($query); $result =& $oMaxDalMaintenance->getAllZonesWithAllocInv(); $this->assertEqual(count($result), 3); $this->assertEqual($result[0]['zone_id'], 1); $this->assertEqual($result[0]['ad_id'], 1); $this->assertEqual($result[0]['required_impressions'], 2); $this->assertEqual($result[0]['requested_impressions'], 3); $this->assertEqual($result[1]['zone_id'], 2); $this->assertEqual($result[1]['ad_id'], 1); $this->assertEqual($result[1]['required_impressions'], 4); $this->assertEqual($result[1]['requested_impressions'], 5); $this->assertEqual($result[2]['zone_id'], 2); $this->assertEqual($result[2]['ad_id'], 2); $this->assertEqual($result[2]['required_impressions'], 6); $this->assertEqual($result[2]['requested_impressions'], 7); TestEnv::dropTempTables(); }
/** * A method for restoring the testing environment database setup. * This method can normaly be avoided by using transactions to * rollback database changes during testing, but sometimes a * DROP TEMPORARY TABLE (for example) is used during testing, * causing any transaction to be committed. In this case, this * method is needed to re-set the testing database. */ static function restoreEnv($dropTmpTables = 'false') { $oDbh =& OA_DB::singleton(); // Rollback any transactions that have not been closed // (Naughty, naughty test!) while ($oDbh->inTransaction(true) || $oDbh->inTransaction()) { TestEnv::rollbackTransaction(); } if ($dropTmpTables) { TestEnv::dropTempTables(); } // Truncate all known core tables $oTable =& OA_DB_Table_Core::singleton(); $oTable->truncateAllTables(); // Reset all database sequences $oTable->resetAllSequences(); // Destroy the service locator $oServiceLocator =& OA_ServiceLocator::instance(); unset($oServiceLocator->aService); // Re-set up the test environment TestRunner::setupEnv($GLOBALS['_MAX']['TEST']['layerEnv'], true); }