public function data() { if ($this->method !== "POST") { return array("error" => "Sorry, this endpoint only accepts POST requests. Please see the help documentation."); } // validate the incoming JSON data to ensure its valid $error = Utils::validateJSON($this->rawRequest); if ($error) { return array("error" => ErrorCodes::API_INVALID_JSON, "error_details" => $error); } $json = @json_decode($this->rawRequest); // validate the JSON contains the appropriate settings for the Code $errors = $this->validateCoreSettings($json); if ($errors) { return $errors; } $errors = $this->validateDataTypeSettings($json); if ($errors) { return $errors; } $errors = $this->validateExportTypeSettings($json); if ($errors) { return $errors; } // okay! Now we generate whatever data was requested $gen = new DataGenerator(Constants::GEN_ENVIRONMENT_API, $json); $response = $gen->generate(); if ($response["success"]) { return $response; } }
function testGetPublishersByTracker() { $campaignId = 1; // Add a couple of campaign_trackers $doCampaignsTrackers = OA_Dal::factoryDO('campaigns_trackers'); $doCampaignsTrackers->campaignid = $campaignId; $doCampaignsTrackers->trackerid = 1; $aCampaignTrackerId = DataGenerator::generate($doCampaignsTrackers, 2); $doBanners = OA_Dal::factoryDO('banners'); $doBanners->campaignid = $campaignId; $doBanners->acls_updated = '2007-04-03 18:39:45'; $bannerId = DataGenerator::generateOne($doBanners, true); // Add a couple of affiliates $aAffiliateId = DataGenerator::generate('affiliates', 2); $doZones = OA_Dal::factoryDO('zones'); $doZones->affiliateid = $aAffiliateId[0]; $zoneId = DataGenerator::generateOne($doZones); $doAddZoneAssoc = OA_Dal::factoryDO('ad_zone_assoc'); $doAddZoneAssoc->zone_id = $zoneId; $doAddZoneAssoc->ad_id = $BannerId; $adZoneAssocId = DataGenerator::generateOne($doAddZoneAssoc); // Test the correct number of rows is returned. $expectedRows = 1; $rsAffiliates = $this->dalAffiliates->getPublishersByTracker($aCampaignTrackerId[0]); $rsAffiliates->find(); $actualRows = $rsAffiliates->getRowCount(); $this->assertEqual($actualRows, $expectedRows); }
function testUpdateVariableCode() { $this->varName = 'my_var'; $this->defaultVarCode = "var {$this->varName} = escape(\\'%%" . strtoupper($this->varName) . "_VALUE%%\\')"; // Create a tracker with default variableMethod $doTrackers = OA_Dal::factoryDO('trackers'); $trackerId = DataGenerator::generateOne($doTrackers); $doVariables = OA_Dal::factoryDO('variables'); $doVariables->trackerid = $trackerId; $doVariables->name = $this->varName; $doVariables->variablecode = $this->defaultVarCode; $aVariableIds = DataGenerator::generate($doVariables, 2); // JS $this->assertTrue($this->dalVariables->updateVariableCode($trackerId, DataObjects_Trackers::TRACKER_VARIABLE_METHOD_JS)); $this->assertVariableCode($trackerId, DataObjects_Trackers::TRACKER_VARIABLE_METHOD_JS); // DOM $this->assertTrue($this->dalVariables->updateVariableCode($trackerId, DataObjects_Trackers::TRACKER_VARIABLE_METHOD_DOM)); $this->assertVariableCode($trackerId, DataObjects_Trackers::TRACKER_VARIABLE_METHOD_DOM); // Custom $this->customCode = 'custom'; $doVariables->variablecode = $this->customCode; $doVariables->whereAdd('1=1'); $doVariables->update(DB_DATAOBJECT_WHEREADD_ONLY); $this->assertTrue($this->dalVariables->updateVariableCode($trackerId, DataObjects_Trackers::TRACKER_VARIABLE_METHOD_CUSTOM)); $this->assertVariableCode($trackerId, DataObjects_Trackers::TRACKER_VARIABLE_METHOD_CUSTOM); // Default $this->assertTrue($this->dalVariables->updateVariableCode($trackerId)); $this->assertVariableCode($trackerId); }
public function testGetLinkedCampaigns() { $trackerId = 5; $nonexistentTrackerId = 999; // Create a some campaigns $numLinkedCampaigns = 2; $doCampaigns = OA_Dal::factoryDO('campaigns'); $aCampaignIds = DataGenerator::generate($doCampaigns, $numLinkedCampaigns); // Create tracker links for them foreach ($aCampaignIds as $campaignId) { $doCampaignsTrackers = OA_Dal::factoryDO('campaigns_trackers'); $doCampaignsTrackers->trackerid = $trackerId; $doCampaignsTrackers->campaignid = $campaignId; DataGenerator::generateOne($doCampaignsTrackers); } // Ad a campaign that is not linked. $doCampaigns = OA_Dal::factoryDO('campaigns'); $campaignId = DataGenerator::generateOne($doCampaigns); $aLinkedCampaigns = $this->dalTrackers->getLinkedCampaigns($trackerId); $this->assertEqual($numLinkedCampaigns, count($aLinkedCampaigns)); foreach ($aLinkedCampaigns as $campaignId => $campaign) { $this->assertIsA($campaign, 'DataObjects_Campaigns', "Object not of type DataObjects_Campaigns"); } // Check for nonexist $aLinkedCampaigns = $this->dalTrackers->getLinkedCampaigns($nonexistentTrackerId); $this->assertEmpty($aLinkedCampaigns); }
/** * Generate one record. Wrapper for: generate($do, 1, $generateParents) * Returns id of created record * * @static * @access public * @param DB_DataObjectCommon $do Either DataObject or table name (as string) * @param bool $generateParents Generate parent records * @return int Id of created record * @see DB_DataObject::insert() */ function generateOne($do, $generateParents = false) { if (!empty($this) && is_a($this, 'DataGenerator')) { $ids = $this->generate($do, 1, $generateParents); } else { $ids = DataGenerator::generate($do, 1, $generateParents); } return array_pop($ids); }
function test_genericHtml_class() { // test the class implementation $oComponent =& OX_Component::factory('bannerTypeHtml', 'demoBannerTypeHtml', 'demoHtml'); // common extension methods $this->_assertClass($oComponent, 'bannerTypeHtml', 'demoBannerTypeHtml', 'demoHtml'); // plugin-specific methods $this->assertTrue(method_exists($oComponent, '_buildHtmlTemplate'), $sender . ' missing method _buildHtmlTemplate'); $this->assertTrue(method_exists($oComponent, 'exportData'), $sender . ' missing method exportData'); // generate test data $doBanners = OA_Dal::factoryDO('banners'); $oDG = new DataGenerator(); $oDG->setData('banners', array('ext_bannertype' => array($oComponent->getComponentIdentifier()))); $aIds = $oDG->generate($doBanners, 5, false); $aFields = $aVariables = array(); // test the processForm method // this method joins the banners and banners_demo tables // by creating a banners_demo record where // banners_demo.banners_demo_id = banners.bannerid foreach ($aIds as $i => $bannerId) { $aFields['description'] = 'description_' . $bannerId; $this->assertTrue($oComponent->processForm(true, $bannerId, $aFields, $aVariables)); $doBannersDemo = OA_Dal::factoryDO('banners_demo'); $doBannersDemo->banners_demo_id = $bannerId; $this->assertTrue($doBannersDemo->find(true)); $this->assertEqual($doBannersDemo->banners_demo_desc, $aFields['description']); } // test the exportData method $aTables = $oComponent->exportData(); $this->assertIsA($aTables, 'array'); $this->assertEqual(count($aTables), 2); $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; $pattern = '/' . $prefix . 'z_' . $oComponent->component . '[\\d]{8}_[\\d]{6}' . $prefix . 'banners/'; $this->assertPattern($pattern, $aTables[0]); $pattern = '/' . $prefix . 'z_' . $oComponent->component . '[\\d]{8}_[\\d]{6}' . $prefix . 'banners_demo/'; $this->assertPattern($pattern, $aTables[1]); $oDbh = OA_DB::singleton(); $query = "SELECT * FROM " . $oDbh->quoteIdentifier($aTables[0]); $aResult = $oDbh->queryAll($query, null, MDB2_FETCHMODE_ASSOC); foreach ($aResult as $i => $aFrom) { $this->assertEqual($aFrom['bannerid'], $aIds[$i]); } $query = "SELECT * FROM " . $oDbh->quoteIdentifier($aTables[1]); $aResult = $oDbh->queryAll($query, null, MDB2_FETCHMODE_ASSOC); foreach ($aResult as $i => $aFrom) { $this->assertEqual($aFrom['banners_demo_id'], $aIds[$i]); } }
function testDeleteWhereOne() { $this->oaTable->createTable('audit'); $this->oaTable->createTable('acls'); $dg = new DataGenerator(); $dg->setData('acls', array('bannerid' => array(1, 2, 3), 'executionorder' => array(0, 0, 0, 1, 1, 1, 2, 2, 2))); $dg->generate('acls', 5); OA_DB_Sql::deleteWhereOne('acls', 'bannerid', 1); $doAcls = OA_Dal::factoryDO('acls'); $doAcls->bannerid = 1; $doAcls->find(); $this->assertEqual(0, $doAcls->getRowCount()); $doAcls->bannerid = 2; $doAcls->find(); $this->assertEqual(2, $doAcls->getRowCount()); $aConf = $GLOBALS['_MAX']['CONF']; $this->oaTable->dropTable($aConf['table']['prefix'] . 'acls'); }
function testGetChannelsAndAffiliates() { // Insert 2 channels $aData = array('acls_updated' => array('2007-04-04 17:27:33')); $dg = new DataGenerator(); $dg->setData('channel', $aData); $aChannelId = $dg->generate('channel', 2, true); // Check the correct number of rows returned $expectedRows = 2; $rsChannel = $this->dalChannel->getChannelsAndAffiliates(); $rsChannel->find(); $actualRows = $rsChannel->getRowCount(); $this->assertEqual($actualRows, $expectedRows); // Check each row has the correct number of fields $rsChannel->fetch(); $aChannel = $rsChannel->export(); $this->assertEqual(count($aChannel), 4); }
function testInsert() { $numTrackers = 2; $clientId = 7; // Prepare test data $doChannel = OA_Dal::factoryDO('channel'); $doChannel->acls_updated = '2007-04-03 19:29:54'; $channelId = DataGenerator::generateOne($doChannel, true); // Test non empty connection wondows $GLOBALS['_MAX']['CONF']['logging']['defaultImpressionConnectionWindow'] = 1000; $GLOBALS['_MAX']['CONF']['logging']['defaultClickConnectionWindow'] = 2000; $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->clientid = $clientId; $campaignId = DataGenerator::generateOne($doCampaigns); $this->assertNotEmpty($campaignId); $this->assertEqual($doCampaigns->viewwindow, 1000); $this->assertEqual($doCampaigns->clickwindow, 2000); $GLOBALS['_MAX']['CONF']['logging']['defaultImpressionConnectionWindow'] = ''; $GLOBALS['_MAX']['CONF']['logging']['defaultClickConnectionWindow'] = ''; // Add trackers $doTrackers = OA_Dal::factoryDO('trackers'); $doTrackers->clientid = $clientId; $doTrackers->linkcampaigns = 't'; $aTrackerId = DataGenerator::generate($doTrackers, $numTrackers, false); $doTrackers = OA_Dal::factoryDO('trackers'); $doTrackers->linkcampaigns = 'f'; DataGenerator::generateOne($doTrackers); // redundant one // Test that inserting new campaigns triggers to insert new campaigns_trackers (if exists) $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->clientid = $clientId; $campaignId = DataGenerator::generateOne($doCampaigns); $this->assertNotEmpty($campaignId); // Test that two campaign_trackers were inserted as well $doCampaigns_trackers = OA_Dal::factoryDO('campaigns_trackers'); $doCampaigns_trackers->campaignid = $campaignId; $this->assertEqual($doCampaigns_trackers->count(), $numTrackers); // Delete any data which wasn't created by DataGenerator DataGenerator::cleanUp(array('campaigns', 'campaigns_trackers', 'trackers')); }
function testGetAclsByDataValueType() { $type = 'Site:Channel'; $bannerId = 1; $channelId = 1; // Test it returns empty set if no data exists $rsChannel = $this->dalAcls->getAclsByDataValueType($bannerId, $type); $rsChannel->reset(); $this->assertEqual($rsChannel->getRowCount(), 0); // Generate acls, two of them with the same $bannerId $data = array('bannerid' => array($bannerId, $bannerId, 3), 'data' => array("{$channelId},2,3", '4,5,6', "{$channelId}"), 'executionorder' => array(1, 2, 3)); $dg = new DataGenerator(); $dg->setData('acls', $data); // Add test data $doAcls = OA_Dal::factoryDO('acls'); $doAcls->type = $type; $dg->generate($doAcls, 3, true); // Test that $bannerId is in two sets $rsChannel = $this->dalAcls->getAclsByDataValueType($channelId, $type); $rsChannel->reset(); $this->assertEqual($rsChannel->getRowCount(), 2); }
function testDelete() { $doZones = OA_Dal::factoryDO('zones'); $doZones->append = ''; $doZones->chain = ''; DataGenerator::generate($doZones, $numZones1 = 2); // add few reduntant zones // Add our testing zone $zoneId = DataGenerator::generateOne('zones'); // add appending zones $doZones = OA_Dal::factoryDO('zones'); $doZones->appendtype = phpAds_ZoneAppendZone; $doZones->append = 'zone:' . $zoneId; $doZones->chain = ''; $aZoneIdAppends = DataGenerator::generate($doZones, $numZonesAppened = 3); // add chained zones $doZones = OA_Dal::factoryDO('zones'); $doZones->append = ''; $doZones->chain = 'zone:' . $zoneId; $aZoneIdChained = DataGenerator::generate($doZones, $numZonesChained = 3); $doZones = OA_Dal::staticGetDO('zones', $zoneId); $ret = $doZones->delete(); // delete $this->assertTrue($ret); $numAllZones = $numZones1 + $numZonesAppened + $numZonesChained; // check appended zones were cleaned up $doZones = OA_Dal::factoryDO('zones'); $doZones->append = ''; //$doZones->whereAdd("append = ''"); // $countWhat = true $this->assertEqual($doZones->count(), $numAllZones); // check chained zones were cleaned up $doZones = OA_Dal::factoryDO('zones'); $doZones->chain = ''; $this->assertEqual($doZones->count(), $numAllZones); }
/** * AjaxRequest objects are automatically processed when they are created, based on the unique $action * value. The result of the call is stored in $response to be handled however you need (e.g. output * as JSON, XML etc) - or an Exception is thrown if something went wrong. Exceptions are used SOLELY for * program errors: not for user-entry errors. */ public function __construct($action, $post = array()) { $this->action = $action; $this->post = Utils::sanitize($post); switch ($this->action) { // ------------------------------------------------------------------------------------ // INSTALLATION // ------------------------------------------------------------------------------------ // a fresh install assumes it's a blank slate: no database tables, no settings file case "installationTestDbSettings": Core::init("installation"); if (Core::checkIsInstalled()) { return; } list($success, $content) = Database::testDbSettings($this->post["dbHostname"], $this->post["dbName"], $this->post["dbUsername"], $this->post["dbPassword"]); $this->response["success"] = $success; $this->response["content"] = $content; break; case "installationCreateSettingsFile": Core::init("installation"); if (Core::checkIsInstalled()) { return; } if (Core::checkSettingsFileExists()) { $this->response["success"] = 0; $this->response["content"] = "Your settings.php file already exists."; return; } else { list($success, $content) = Installation::createSettingsFile($this->post["dbHostname"], $this->post["dbName"], $this->post["dbUsername"], $this->post["dbPassword"], $this->post["dbTablePrefix"]); $this->response["success"] = $success ? 1 : 0; // bah! $this->response["content"] = $content; } break; case "confirmSettingsFileExists": Core::init("installation"); $settingsFileExists = Core::checkSettingsFileExists(); $this->response["success"] = $settingsFileExists ? 1 : 0; break; case "installationCreateDatabase": Core::init("installationDatabaseReady"); if (Core::checkIsInstalled()) { $this->response["success"] = 0; $this->response["content"] = "It appears that the script is already installed. If the database already existed, you may need to delete the tables manually before being able to continue."; return; } list($success, $content) = Installation::createDatabase(); if (!$success) { $this->response["success"] = 0; $this->response["content"] = $content; return; } // always create the administrator account. If the user chose the anonymous setup, all values // will be blank and all configurations will be associated with this (anonymous) user $adminAccount = array("accountType" => "admin"); if ($this->post["userAccountSetup"] != "anonymous") { $adminAccount["firstName"] = $this->post["firstName"]; $adminAccount["lastName"] = $this->post["lastName"]; $adminAccount["email"] = $this->post["email"]; $adminAccount["password"] = $this->post["password"]; } Account::createAccount($adminAccount, true); // make note of the fact that we've passed this step of the installation process Settings::setSetting("userAccountSetup", $this->post["userAccountSetup"]); Settings::setSetting("installationStepComplete_Core", "yes"); Settings::setSetting("defaultLanguage", $this->post["defaultLanguage"]); Settings::setSetting("allowAnonymousAccess", $this->post["allowAnonymousAccess"] == "yes" ? "yes" : "no"); Settings::setSetting("anonymousUserPermissionDeniedMsg", $this->post["anonymousUserPermissionDeniedMsg"]); $this->response["success"] = 1; $this->response["content"] = ""; break; // ------------------------------------------------------------------------------------ // PLUGINS (installation + reset) // ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------ // PLUGINS (installation + reset) // ------------------------------------------------------------------------------------ case "installationDataTypes": Core::init("installationDatabaseReady"); if (!Core::checkIsInstalled()) { $this->setDataTypes(); } break; case "installationValidateSettingsFile": $response = Installation::validateSettingsFile(); $this->response["success"] = $response["success"]; $this->response["content"] = $response["errorMessage"]; break; case "resetDataTypes": Core::init("resetPlugins"); if (Core::checkIsLoggedIn() && Core::$user->isAdmin()) { $this->setDataTypes(); } break; case "installationSaveDataTypes": Core::init("installationDatabaseReady"); if (!Core::checkIsInstalled()) { $folders = $this->post["folders"]; $response = Settings::setSetting("installedDataTypes", $folders); $this->response["success"] = $response["success"]; $this->response["content"] = $response["errorMessage"]; } break; case "resetSaveDataTypes": Core::init("resetPlugins"); if (Core::checkIsLoggedIn() && Core::$user->isAdmin()) { $folders = $this->post["folders"]; $response = Settings::setSetting("installedDataTypes", $folders); $this->response["success"] = $response["success"]; $this->response["content"] = $response["errorMessage"]; } break; case "installationExportTypes": Core::init("installationDatabaseReady"); if (!Core::checkIsInstalled()) { $this->setExportTypes(); } break; case "resetExportTypes": Core::init("resetPlugins"); if (Core::checkIsLoggedIn() && Core::$user->isAdmin()) { $this->setExportTypes(); } break; case "installationSaveExportTypes": Core::init("installationDatabaseReady"); if (!Core::checkIsInstalled()) { $folders = $this->post["folders"]; $response = Settings::setSetting("installedExportTypes", $folders); $this->response["success"] = $response["success"]; $this->response["content"] = $response["errorMessage"]; } break; case "resetSaveExportTypes": Core::init("resetPlugins"); if (Core::checkIsLoggedIn() && Core::$user->isAdmin()) { $folders = $this->post["folders"]; $response = Settings::setSetting("installedExportTypes", $folders); $this->response["success"] = $response["success"]; $this->response["content"] = $response["errorMessage"]; } break; case "installationCountries": Core::init("installationDatabaseReady"); if (!Core::checkIsInstalled()) { $this->setCountries(); } break; case "resetCountries": Core::init("resetPlugins"); if (Core::checkIsLoggedIn() && Core::$user->isAdmin()) { $this->setCountries(); } break; case "installationSaveCountries": Core::init("installationDatabaseReady"); if (!Core::checkIsInstalled()) { $folders = $this->post["folders"]; Settings::setSetting("installedCountries", $folders); $response = Settings::setSetting("installationComplete", "yes"); $this->response["success"] = $response["success"]; $this->response["content"] = $response["errorMessage"]; } break; case "resetSaveCountries": Core::init("resetPlugins"); if (Core::checkIsLoggedIn() && Core::$user->isAdmin()) { $folders = $this->post["folders"]; Settings::setSetting("installedCountries", $folders); $this->response["success"] = true; // ...! } break; // called anytime the plugins were updated (either via the installation or core script). This // runs any post-processes that need to be done // called anytime the plugins were updated (either via the installation or core script). This // runs any post-processes that need to be done case "updatedPluginsPostProcess": Core::init(); $this->response["success"] = Minification::createAppStartFile() ? 1 : 0; break; // ------------------------------------------------------------------------------------ // USER ACCOUNTS // ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------ // USER ACCOUNTS // ------------------------------------------------------------------------------------ case "getAccount": Core::init(); $response = Core::$user->getAccount(); $this->response["success"] = true; $this->response["content"] = $response; break; case "getUsers": Core::init(); $response = Core::$user->getUsers(); $this->response["success"] = $response["success"]; if (isset($response["accounts"])) { $this->response["content"] = $response["accounts"]; } break; case "createAccount": Core::init(); if (!Core::checkIsLoggedIn()) { $this->response["success"] = false; $this->response["errorCode"] = ErrorCodes::NOT_LOGGED_IN; } else { if (Core::$user->getAccountType() != "admin") { $this->response["success"] = false; $this->response["errorCode"] = ErrorCodes::NON_ADMIN; } else { if (Account::checkAccountExists($this->post["email"])) { $this->response["success"] = false; $this->response["errorCode"] = ErrorCodes::ACCOUNT_ALREADY_EXISTS; } else { $accountInfo = $this->post; $accountInfo["accountType"] = "user"; Account::createAccount($accountInfo); $this->response["success"] = true; } } } break; case "deleteAccount": Core::init(); if (!Core::checkIsLoggedIn()) { $this->response["success"] = false; $this->response["errorCode"] = ErrorCodes::NOT_LOGGED_IN; } else { if (Core::$user->getAccountType() != "admin") { $this->response["success"] = false; $this->response["errorCode"] = ErrorCodes::NON_ADMIN; } else { $accountID = $this->post["accountID"]; $response = Core::$user->deleteAccount($accountID); $this->response["success"] = true; } } break; // updates the current logged in user's info // updates the current logged in user's info case "updateAccount": Core::init(); if (!Core::checkIsLoggedIn()) { $this->response["success"] = false; $this->response["errorCode"] = ErrorCodes::NOT_LOGGED_IN; } else { if (Core::$user->isAnonymousAdmin()) { $this->response["success"] = false; $this->response["errorCode"] = ErrorCodes::INVALID_REQUEST; } else { $accountID = $this->post["accountID"]; $this->response = Core::$user->updateAccount($accountID, $this->post); } } break; case "saveConfiguration": Core::init(); $response = Core::$user->saveConfiguration($this->post); $this->response["success"] = $response["success"]; $this->response["content"] = $response["message"]; if (isset($response["lastUpdated"])) { $this->response["lastUpdated"] = $response["lastUpdated"]; } break; case "copyDataSet": Core::init(); $response = Core::$user->copyConfiguration($this->post); $this->response["success"] = $response["success"]; $this->response["content"] = $response["message"]; break; case "deleteDataSets": Core::init(); $configurationIDs = $this->post["configurationIDs"]; $response = Core::$user->deleteConfigurations($configurationIDs); $this->response["success"] = $response["success"]; $this->response["content"] = $response["message"]; break; case "saveDataSetVisibilityStatus": Core::init(); $configurationID = $this->post["configurationID"]; $status = $this->post["status"]; $time = $this->post["time"]; $response = Core::$user->saveDataSetVisibilityStatus($configurationID, $status, $time); $this->response["success"] = $response["success"]; $this->response["content"] = $response["message"]; if (isset($response["newStatus"])) { $this->response["newStatus"] = $response["newStatus"]; } break; case "getPublicDataSet": Core::init(); $configurationID = $this->post["dataSetID"]; $response = Core::$user->getPublicDataSet($configurationID); $this->response["success"] = $response["success"]; $this->response["content"] = $response["message"]; break; case "getDataSetHistory": Core::init(); $configurationID = $this->post["dataSetID"]; $response = Core::$user->getDataSetHistory($configurationID); $this->response["success"] = $response["success"]; $this->response["content"] = $response["message"]; break; case "login": Core::init(); $email = $this->post["email"]; $password = $this->post["password"]; $response = Account::login($email, $password); $this->response["success"] = $response["success"]; $this->response["content"] = $response["message"]; break; case "logout": Core::init(); if (!Core::checkIsLoggedIn()) { $this->response["success"] = true; } else { if (!Core::$user->isAnonymousAdmin()) { Core::$user->logout(); $this->response["success"] = true; } } break; case "resetPassword": Core::init(); $email = $this->post["email"]; $response = Account::resetPassword($email); $this->response["success"] = $response["success"]; $this->response["content"] = $response["message"]; break; // ------------------------------------------------------------------------------------ // DATA GENERATION // ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------ // DATA GENERATION // ------------------------------------------------------------------------------------ case "generateInPage": Core::init("generation"); $gen = new DataGenerator(Constants::GEN_ENVIRONMENT_POST, $this->post); $response = $gen->generate(); $this->response["success"] = $response["success"]; $this->response["content"] = $response["content"]; $this->response["isComplete"] = $response["isComplete"]; break; } }
/** * A method to generate data for testing. * * @access private */ function _generateTestZones($numZones) { $oNow = new Date(); if (is_null($this->doZones)) { $this->doZones = OA_Dal::factoryDO('zones'); } return DataGenerator::generate($this->doZones, $numZones); }
/** * The method to test the getZonesForecasts() method. */ function testgetZonesForecasts() { $this->_createTestData(); $operationInterval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval']; $oDal = new OA_Dal_Maintenance_Priority(); $oLowerDate = new Date('2007-09-16 12:00:00'); $oUpperDate = new Date('2007-09-16 17:00:00'); $lowerDateStr = $oLowerDate->format(self::DATE_TIME_FORMAT); $upperDateStr = $oUpperDate->format(self::DATE_TIME_FORMAT); $weeks = 2; // Test with bad input $badAgencyId = -1; $result = $oDal->getZonesForecasts($lowerDateStr, $upperDateStr); $expected = array(); $this->assertEqual($result, $expected); // Test with data outside the range $oDate = new Date('2007-09-16 11:00:00'); $operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate); $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate); $previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate); $startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT); $endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT); $doDIA = OA_Dal::factoryDO('data_intermediate_ad'); $aDIAs = DataGenerator::generate($doDIA, 1); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]); $doDIA->date_time = $startDateStr; $doDIA->operation_interval = $operationInterval; $doDIA->zone_id = $this->zoneId1; $doDIA->ad_id = 1; $doDIA->impressions = 1000; $doDIA->update(); $result = $oDal->getZonesForecasts($startDateStr, $endDateStr); $expected = array(); $this->assertEqual($result, $expected); // Test with data inside the range $oDate = new Date('2007-09-16 13:00:00'); $operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate); $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate); $previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate); $startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT); $endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT); $aDIAs = DataGenerator::generate($doDIA, 1); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]); $doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT); $doDIA->operation_interval = $operationInterval; $doDIA->zone_id = $this->zoneId1; $doDIA->ad_id = 1; $doDIA->impressions = 70; $doDIA->update(); $result = $oDal->getZonesForecasts($startDateStr, $endDateStr); $expected = array($this->zoneId1 => 70); $this->assertEqual($result, $expected); // Test with more data from the same zone $oDate = new Date('2007-09-16 14:00:00'); $operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate); $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate); $previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate); $startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT); $endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT); $aDIAs = DataGenerator::generate($doDIA, 3); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]); $doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT); $doDIA->operation_interval = $operationInterval; $doDIA->zone_id = $this->zoneId1; $doDIA->ad_id = 2; $doDIA->impressions = 90; $doDIA->update(); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[1]); $doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT); $doDIA->operation_interval = $operationInterval; $doDIA->zone_id = $this->zoneId1; $doDIA->ad_id = 4; $doDIA->impressions = 110; $doDIA->update(); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[2]); $doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT); $doDIA->operation_interval = $operationInterval; $doDIA->zone_id = $this->zoneId2; $doDIA->ad_id = 4; $doDIA->impressions = 15000; $doDIA->update(); $result = $oDal->getZonesForecasts($startDateStr, $endDateStr); $expected = array($this->zoneId1 => 200, $this->zoneId2 => 15000); $this->assertEqual($result, $expected); DataGenerator::cleanUp(); }
// Should we add the year to the title (eh: PyCon11 or PyCon2011 instead of PyCon?) define("EVENT_ADD_YEAR_TO_TITLE", 10); // 50% chance if the additional year added to the name is a full year (2011) instead of short year (11) define("EVENT_ADD_FULLYEAR_TO_TITLE", 50); // Percentage of anonymous comments on events define("EVENT_COMMENT_IS_ANONYMOUS", 15); // Percentage of anonymous comments on talks define("TALK_COMMENT_IS_ANONYMOUS", 15); // 5% of the comments are marked private define("COMMENT_IS_PRIVATE", 5); // Percentage of talks that is claimed define("TALK_IS_CLAIMED", 75); // Does the talk have multiple speakers define("TALK_HAS_MULTIPLE_SPEAKERS", 20); // Percentage of the talks that have slides associated with them define("TALK_HAS_SLIDES", 35); // Amount of claims that are still pending define("TALK_SPEAKER_PENDING", 10); // Percentage of talks that is claimed by a user that has registered through joind.in define("TALK_IS_CLAIMED_BY_REGISTERED_USER", 75); // Only 1 percent of the users is an admin define("USER_IS_ADMIN", 1); // 25% has a twitter account define("USER_HAS_TWITTER", 25); // ====================== NOTHING TO EDIT BELOW THIS POINT, MOVE ALONG ====================== require_once "generator_data.interface.php"; require_once "generator_data.class.php"; require_once "generator.class.php"; $gen = new DataGenerator(new Generator_Data()); echo $gen->generate(); exit;
/** * Prune all entries where the ad_id is for a banner in a High Priority Campaign where: * The campaign has a booked number of lifetime target impressions and/or clicks and/or conversions AND the campaign is not active AND at least one of the booked lifetime target values has been reached. * */ function testpruneDataSummaryAdZoneAssocTargetReached() { $oToday = new Date(); $oExpire = new Date(); $oExpire->subtractSeconds(999999); $today = $oToday->getDate(); $expire = $oExpire->getDate(); $oDal = new OA_Maintenance_Pruning(); $doDSAZA = OA_Dal::factoryDO('data_summary_ad_zone_assoc'); $doDIA = OA_Dal::factoryDO('data_intermediate_ad'); $aDIAs = DataGenerator::generate($doDIA, 4); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]); $doDIA->ad_id = $this->idBanner1; $doDIA->impressions = 1000; $doDIA->clicks = 0; $doDIA->conversions = 0; $doDIA->update(); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[1]); $doDIA->ad_id = $this->idBanner1; $doDIA->impressions = 100; $doDIA->clicks = 0; $doDIA->conversions = 0; $doDIA->update(); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[2]); $doDIA->ad_id = $this->idBanner1; $doDIA->impressions = 10; $doDIA->clicks = 0; $doDIA->conversions = 0; $doDIA->update(); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[3]); $doDIA->ad_id = $this->idBanner1; $doDIA->impressions = 1; $doDIA->clicks = 0; $doDIA->conversions = 0; $doDIA->update(); // generate 2 summary ad_zone records for an active campaign ad_id $doDSAZA->ad_id = $this->idBanner1; $aIds = DataGenerator::generate($doDSAZA, 2); // generate 7 summary ad_zone records for an inactive campaign ad_id $doDSAZA->ad_id = $this->idBanner2; $aIds = DataGenerator::generate($doDSAZA, 7); // make sure 9 rows in table $this->assertEqual($this->_countRowsInDSAZA(), 9); // ad_id 1 => campaignid 1 => active, high priority, not expired, target impressions not reached $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign1); $doCampaigns->priority = 5; $doCampaigns->status = OA_ENTITY_STATUS_RUNNING; $doCampaigns->target_impression = 0; $doCampaigns->target_click = 0; $doCampaigns->target_conversion = 0; $doCampaigns->views = 100000; $doCampaigns->clicks = 1000; $doCampaigns->conversions = 100; $doCampaigns->update(); $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveTargetReached(1); // 0 records were deleted $this->assertEqual($result, 0); // 0 records remain $this->assertEqual($this->_countRowsInDSAZA(), 9); // ad_id 1 => campaignid 1 => not active, high priority, not expired, target impressions reached $doCampaigns = OA_Dal::staticGetDO('campaigns', $this->idCampaign1); $doCampaigns->priority = 5; $doCampaigns->status = OA_ENTITY_STATUS_EXPIRED; $doCampaigns->target_impression = 0; $doCampaigns->target_click = 0; $doCampaigns->target_conversion = 0; $doCampaigns->views = 1111; $doCampaigns->clicks = 111; $doCampaigns->conversions = 11; $doCampaigns->update(); $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveTargetReached(1); // 1 record deleted $this->assertEqual($result, 1); // 8 records remain $this->assertEqual($this->_countRowsInDSAZA(), 8); $result = $oDal->_pruneDataSummaryAdZoneAssocInactiveTargetReached(5); // 1 record was deleted $this->assertEqual($result, 1); // 7 records remain $this->assertEqual($this->_countRowsInDSAZA(), 7); }
<?php require_once __DIR__ . "/library.php"; Core::init("generation"); $gen = new DataGenerator(Constants::GEN_ENVIRONMENT_POST, $_POST); $response = $gen->generate(); if ($gen->getExportTarget() == "promptDownload") { header("Cache-Control: private, no-cache, must-revalidate"); // check if user opted to zip the generated data if ($gen->isPromptDownloadZipped()) { $randNum = mt_rand(0, 100000000); $fileName = $randNum . "_" . $response["promptDownloadFilename"]; $zipPath = $filePath . ".zip"; if (file_put_contents($fileName, $response["content"])) { // now that we've written the file, zip it up $zip = new ZipArchive(); $zipFile = $zip->open($zipPath, ZipArchive::CREATE); if ($zipFile && $zip->addFile($fileName, $response["promptDownloadFilename"])) { // we've got our zip file now we may set the response header $zip->close(); header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=" . $response["promptDownloadFilename"] . ".zip"); readfile($zipPath); unlink($zipPath); unlink($fileName); exit; } } // no compression, send the original data back } else { header("Content-Type: {$response["contentTypeHeader"]}");
/** * Method to test the getAllDeliveryLimitationChangedCreatives method. * * Requirements: * Test 0: Test with bad input data, and ensure the method survives. * Test 1: Test with no data, and ensure no data are returned. * Test 2: Test with an active ad that has not had any delivery limitation changes, * and ensure that no data are returned: DEPRECATED TEST, PostgreSQL DOES * NOT PERMIT THE acls_update FIELD TO HAVE A NULL ENTRY. * Test 3: Test with an active ad that has had a delivery limitation change in the * last OI, before the last Priority Compensation run, and ensure that no * data are returned. * Test 4: Test with an active ad that has had a delivery limitation change in the * last OI, after the last Priority Compensation run, and ensure that the * correct data are returned. * Test 5: Test with an active ad that has had a delivery limitation change in the * current OI, and ensure that the correct data are returned. * Test 6: Repeat test 3, but with an inactive ad. * Test 7: Repeat test 4, but with an inactive ad. * Test 8: Repeat test 5, but with an inactive ad. * Test 9: Test with a mixture of ads, and ensure the correct data are returned. */ function testGetAllDeliveryLimitationChangedCreatives() { TestEnv::restoreEnv('dropTmpTables'); $conf = $GLOBALS['_MAX']['CONF']; $oDbh =& OA_DB::singleton(); $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority(); $oDateNow = new Date('2006-10-04 12:07:01'); $oDateLastPC = new Date('2006-10-04 11:14:53'); $aLastRun = array('start_run' => $oDateLastPC, 'now' => $oDateNow); // Test 0 $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives(array()); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 0); // Test 1 $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 0); // Test 3 $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doCampaigns->priority = 1; $doCampaigns->status = OA_ENTITY_STATUS_RUNNING; $idCampaign = DataGenerator::generateOne($doCampaigns, true); $doBanners = OA_Dal::factoryDO('banners'); $doBanners->campaignid = $idCampaign; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 11:10:00'; $idBanner = DataGenerator::generateOne($doBanners); $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 0); DataGenerator::cleanUp(); // Test 4 $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doCampaigns->priority = 1; $doCampaigns->status = OA_ENTITY_STATUS_RUNNING; $idCampaign = DataGenerator::generateOne($doCampaigns, true); $doBanners = OA_Dal::factoryDO('banners'); $doBanners->campaignid = $idCampaign; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 11:15:00'; $idBanner = DataGenerator::generateOne($doBanners); $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 1); $this->assertEqual($aResult[$idBanner], '2006-10-04 11:15:00'); DataGenerator::cleanUp(); // Test 5 $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doCampaigns->priority = 1; $doCampaigns->status = OA_ENTITY_STATUS_RUNNING; $idCampaign = DataGenerator::generateOne($doCampaigns, true); $doBanners = OA_Dal::factoryDO('banners'); $doBanners->campaignid = $idCampaign; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 12:15:00'; $idBanner = DataGenerator::generateOne($doBanners); $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 1); $this->assertEqual($aResult[$idBanner], '2006-10-04 12:15:00'); DataGenerator::cleanUp(); // Test 6 $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doCampaigns->priority = 1; $doCampaigns->status = OA_ENTITY_STATUS_RUNNING; $idCampaign = DataGenerator::generateOne($doCampaigns, true); $doBanners = OA_Dal::factoryDO('banners'); $doBanners->campaignid = $idCampaign; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 11:10:00'; $idBanner = DataGenerator::generateOne($doBanners); $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 0); DataGenerator::cleanUp(); // Test 7 $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doCampaigns->priority = 1; $doCampaigns->activate_time = '2020-01-01 00:00:00'; $doCampaigns->status = OA_ENTITY_STATUS_AWAITING; $idCampaign = DataGenerator::generateOne($doCampaigns, true); $doBanners = OA_Dal::factoryDO('banners'); $doBanners->campaignid = $idCampaign; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 11:15:00'; $idBanner = DataGenerator::generateOne($doBanners); $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 0); DataGenerator::cleanUp(); // Test 8 $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doCampaigns->priority = 1; $doCampaigns->activate_time = '2020-01-01 00:00:00'; $doCampaigns->status = OA_ENTITY_STATUS_AWAITING; $idCampaign = DataGenerator::generateOne($doCampaigns, true); $doBanners = OA_Dal::factoryDO('banners'); $doBanners->campaignid = $idCampaign; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_AWAITING; $doBanners->acls_updated = '2006-10-04 12:15:00'; $idBanner = DataGenerator::generateOne($doBanners); $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 0); DataGenerator::cleanUp(); // Test 9 $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doCampaigns->priority = 1; $doCampaigns->status = OA_ENTITY_STATUS_RUNNING; $aIdCampaignsActive = DataGenerator::generate($doCampaigns, 2, true); $doCampaigns->activate_time = '2020-01-01 00:00:00'; $doCampaigns->status = OA_ENTITY_STATUS_AWAITING; $idCampaignInactive = DataGenerator::generateOne($doCampaigns, true); $doBanners = OA_Dal::factoryDO('banners'); $doBanners->campaignid = $aIdCampaignsActive[0]; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 11:30:00'; $idBanner1 = DataGenerator::generateOne($doBanners); $doBanners->campaignid = $aIdCampaignsActive[0]; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 10:15:00'; $idBanner2 = DataGenerator::generateOne($doBanners); $doBanners->campaignid = $aIdCampaignsActive[1]; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_AWAITING; $doBanners->acls_updated = '2006-10-04 12:06:00'; $idBanner3 = DataGenerator::generateOne($doBanners); $doBanners->campaignid = $aIdCampaignsActive[1]; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 12:15:00'; $idBanner4 = DataGenerator::generateOne($doBanners); $doBanners->campaignid = $idCampaignInactive; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 12:05:00'; $idBanner5 = DataGenerator::generateOne($doBanners); $doBanners->campaignid = $idCampaignInactive; $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S'); $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->acls_updated = '2006-10-04 12:01:00'; $idBanner5 = DataGenerator::generateOne($doBanners); $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 2); $this->assertEqual($aResult[$idBanner1], '2006-10-04 11:30:00'); $this->assertEqual($aResult[$idBanner4], '2006-10-04 12:15:00'); DataGenerator::cleanUp(); }
function testHidden() { // Add websites $aWebsiteIds = DataGenerator::generate('affiliates', 2); // Add zones $aZoneIds = array(); foreach ($aWebsiteIds as $websiteId) { $doZones = OA_Dal::factoryDO('zones'); $doZones->affiliateid = $websiteId; $aZoneIds[] = DataGenerator::generateOne($doZones); } // Create a campaign $campaignId = DataGenerator::generateOne('campaigns'); $doBanner = OA_Dal::factoryDO('banners'); $doBanner->campaignid = $campaignId; $bannerId = DataGenerator::generateOne($doBanner); // Link the campaign's banner to the zones $doAza = OA_Dal::factoryDO('ad_zone_assoc'); foreach ($aZoneIds as $zoneId) { $doAza->zone_id = $aZoneIds[$zoneId]; $doAza->ad_id = $bannerId; DataGenerator::generateOne($doAza); } // Create tracker $trackerId = DataGenerator::generateOne('trackers'); // Link the tracker to the campaign $doCampaignsTrackers = OA_Dal::factoryDO('campaigns_trackers'); $doCampaignsTrackers->campaignid = $campaignId; $doCampaignsTrackers->trackerid = $trackerId; DataGenerator::generateOne($doCampaignsTrackers); // Add the variable hidden to website 0 $dllVariablePartialMock = new PartialMockOA_Dll_Variable($this); $dllVariablePartialMock->setReturnValue('checkPermissions', true); $oVariableInfo = new OA_Dll_VariableInfo(); $oVariableInfo->trackerId = $trackerId; $oVariableInfo->variableName = 'Test hidden variable name'; $oVariableInfo->hidden = true; $oVariableInfo->hiddenWebsites = array($aWebsiteIds[1]); // Add with hidden website $this->assertTrue($dllVariablePartialMock->modify($oVariableInfo), $dllVariablePartialMock->getLastError()); // Check the value of variable_publisher $doVariablePublisher = OA_Dal::factoryDO('variable_publisher'); $doVariablePublisher->variable_id = $oVariableInfo->variableId; $doVariablePublisher->find(true); $this->assertEqual(1, $doVariablePublisher->count()); $this->assertEqual($aWebsiteIds[0], $doVariablePublisher->publisher_id); }
/** * A method to test the getPreviousWeekZoneForcastImpressions() method. * * Test 1: Test with bad input, and ensure false is returned. * Test 2: Test with no date in the service locator, and ensure that * false is returned. * Test 3: Test with no data, and ensure that an array with the default * forecast for each zone is returned. * Test 4: Test with data, and ensure that an array with the correct * forecasts is returned. */ function testGetPreviousWeekZoneForcastImpressions() { $aConf = $GLOBALS['_MAX']['CONF']; $oDbh =& OA_DB::singleton(); $oDal = new OA_Dal_Maintenance_Priority(); // Test 1 $aResult = $oDal->getPreviousWeekZoneForcastImpressions('foo'); $this->assertFalse($aResult); // Test 2 $oServiceLocator =& OA_ServiceLocator::instance(); $oServiceLocator->remove('now'); $aResult = $oDal->getPreviousWeekZoneForcastImpressions(1); $this->assertFalse($aResult); // Test 3 $oDate = new Date(); $oServiceLocator->register('now', $oDate); $aResult = $oDal->getPreviousWeekZoneForcastImpressions(1); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), OX_OperationInterval::operationIntervalsPerWeek()); for ($operationIntervalID = 0; $operationIntervalID < OX_OperationInterval::operationIntervalsPerWeek(); $operationIntervalID++) { $expected = array('zone_id' => 1, 'forecast_impressions' => $oDal->getZoneForecastDefaultZoneImpressions(), 'operation_interval_id' => $operationIntervalID); $this->assertEqual($aResult[$operationIntervalID], $expected); } // Test 4 // Insert impressions for the previous operation interval $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate); $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']); $firstIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']); $startDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $endDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $doDIA = OA_Dal::factoryDO('data_intermediate_ad'); $aDIAs = DataGenerator::generate($doDIA, 4); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]); $startDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $endDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $doDIA->date_time = $startDate; $doDIA->interval_start = $startDate; $doDIA->interval_end = $endDate; $doDIA->operation_interval = $aConf['maintenance']['operationInterval']; $doDIA->operation_interval_id = $firstIntervalID; $doDIA->zone_id = 1; $doDIA->ad_id = 1; $doDIA->impressions = 4000; $doDIA->update(); // Insert forcast for the (N - 2) OI // for two different ads in this OI $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']); $secondIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']); $startDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $endDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[1]); $doDIA->date_time = $startDate; $doDIA->interval_start = $startDate; $doDIA->interval_end = $endDate; $doDIA->operation_interval = $aConf['maintenance']['operationInterval']; $doDIA->operation_interval_id = $secondIntervalID; $doDIA->zone_id = 1; $doDIA->ad_id = 1; $doDIA->impressions = 4990; $doDIA->update(); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[2]); $doDIA->date_time = $startDate; $doDIA->interval_start = $startDate; $doDIA->interval_end = $endDate; $doDIA->operation_interval = $aConf['maintenance']['operationInterval']; $doDIA->operation_interval_id = $secondIntervalID; $doDIA->zone_id = 1; $doDIA->ad_id = 2; $doDIA->impressions = 10; $doDIA->update(); // Insert forcast for the second previous operation interval, but // one week ago (so it should not be in the result set) $oNewDate = new Date(); $oNewDate->copy($aDates['start']); $oNewDate->subtractSeconds(SECONDS_PER_WEEK); $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oNewDate); $intervalID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']); $startDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $endDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S'); $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[3]); $doDIA->date_time = $startDate; $doDIA->interval_start = $startDate; $doDIA->interval_end = $endDate; $doDIA->operation_interval = $aConf['maintenance']['operationInterval']; $doDIA->operation_interval_id = $intervalID; $doDIA->zone_id = 1; $doDIA->ad_id = 1; $doDIA->impressions = 1000; $doDIA->update(); // What's the current OI? $currentIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oServiceLocator->get('now')); $aResult = $oDal->getPreviousWeekZoneForcastImpressions(1); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), OX_OperationInterval::operationIntervalsPerWeek()); for ($operationIntervalID = 0; $operationIntervalID < OX_OperationInterval::operationIntervalsPerWeek(); $operationIntervalID++) { $this->assertTrue(is_array($aResult[$operationIntervalID])); $this->assertEqual(count($aResult[$operationIntervalID]), 3); $this->assertEqual($aResult[$operationIntervalID]['zone_id'], 1); if ($operationIntervalID == $firstIntervalID || $operationIntervalID == $currentIntervalID) { // Current and previous OI forecasts should be the same $this->assertEqual($aResult[$operationIntervalID]['forecast_impressions'], 4000); } elseif ($operationIntervalID == $secondIntervalID) { $this->assertEqual($aResult[$operationIntervalID]['forecast_impressions'], 5000); } else { $this->assertEqual($aResult[$operationIntervalID]['forecast_impressions'], 4500); // average between both known forecast } $this->assertEqual($aResult[$operationIntervalID]['operation_interval_id'], $operationIntervalID); } DataGenerator::cleanUp(); }
function testGetBannersCampaignsClients() { // Insert 2 banners $doBanners = OA_Dal::factoryDO('banners'); $doBanners->acls_updated = '2007-04-03 18:39:45'; $aData = array('reportlastdate' => array('2007-04-03 18:39:45')); $dg = new DataGenerator(); $dg->setData('clients', $aData); $aBannerIds = $dg->generate($doBanners, 2, true); // Check the correct number of rows returned $expectedRows = 2; $rsBanners = $this->dalBanners->getBannersCampaignsClients(); $rsBanners->find(); $actualRows = $rsBanners->getRowCount(); $this->assertEqual($actualRows, $expectedRows); // Check each row has the correct number of fields $rsBanners->fetch(); $aBanner = $rsBanners->export(); $this->assertEqual(count($aBanner), 6); }
function insertBanners($index, $c = 1) { $doBanners = OA_Dal::factoryDO('banners'); $doBanners->acls_updated = OA::getNow(); $doBanners->updated = OA::getNow(); $doBanners->campaignid = $this->campaignId; $doBanners->status = OA_ENTITY_STATUS_RUNNING; $doBanners->contenttype = ''; $doBanners->pluginversion = '0'; $doBanners->storagetype = 'html'; $doBanners->filename = ''; $doBanners->imageurl = ''; $doBanners->width = '468'; $doBanners->height = '60'; $doBanners->weight = '1'; $doBanners->seq = '0'; $doBanners->target = '_blank'; $doBanners->url = ''; $doBanners->alt = ''; $doBanners->statustext = ''; $doBanners->bannertext = ''; $doBanners->description = 'Default banner 468*60 (' . $index . ')'; $doBanners->adserver = 'max'; $doBanners->block = '0'; $doBanners->capping = '0'; $doBanners->session_capping = '0'; $doBanners->compiledlimitation = ''; $doBanners->acl_plugins = ''; $doBanners->append = ''; $doBanners->appendtype = '0'; $doBanners->bannertype = '0'; $doBanners->alt_filename = ''; $doBanners->alt_imageurl = ''; $doBanners->alt_contenttype = 'gif'; $doBanners->comments = ''; $doBanners->keyword = ''; $doBanners->transparent = ''; $doBanners->parameters = ''; $doBanners->htmltemplate = "<script type='text/javascript'><!--//<![CDATA[\n var m3_u = (location.protocol=='https:'?'https://ads.openx.org/delivery/ajs.php':'http://ads.openx.org/delivery/ajs.php');\n var m3_r = Math.floor(Math.random()*99999999999);\n if (!document.MAX_used) document.MAX_used = ',';\n document.write (\"<scr\"+\"ipt type='text/javascript' src='\"+m3_u);\n document.write (\"?zoneid=9\");\n document.write ('&cb=' + m3_r);\n if (document.MAX_used != ',') document.write (\"&exclude=\" + document.MAX_used);\n document.write (\"&loc=\" + escape(window.location));\n if (document.referrer) document.write (\"&referer=\" + escape(document.referrer));\n if (document.context) document.write (\"&context=\" + escape(document.context));\n if (document.context) document.write (\"&context=\" + escape(document.context));\n if (document.mmm_fo) document.write (\"&mmm_fo=1\");\n document.write (\"'><\\/scr\"+\"ipt>\");\n//]]>--></script><noscript><a href='http://ads.openx.org/delivery/ck.php?n=abc986b1&cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://ads.openx.org/delivery/avw.php?zoneid=9&cb=INSERT_RANDOM_NUMBER_HERE&n=abc986b1' border='0' alt='' /></a></noscript>"; $doBanners->htmlcache = "<script type='text/javascript'><!--//<![CDATA[\n var m3_u = (location.protocol=='https:'?'https://ads.openx.org/delivery/ajs.php':'http://ads.openx.org/delivery/ajs.php');\n var m3_r = Math.floor(Math.random()*99999999999);\n if (!document.MAX_used) document.MAX_used = ',';\n document.write (\"<scr\"+\"ipt type='text/javascript' src='\"+m3_u);\n document.write (\"?zoneid=9\");\n document.write ('&cb=' + m3_r);\n if (document.MAX_used != ',') document.write (\"&exclude=\" + document.MAX_used);\n document.write (\"&loc=\" + escape(window.location));\n if (document.referrer) document.write (\"&referer=\" + escape(document.referrer));\n if (document.context) document.write (\"&context=\" + escape(document.context));\n if (document.context) document.write (\"&context=\" + escape(document.context));\n if (document.mmm_fo) document.write (\"&mmm_fo=1\");\n document.write (\"'><\\/scr\"+\"ipt>\");\n//]]>--></script>"; $this->bannerId1 = DataGenerator::generate($doBanners, $c); }
function testGetAllCampaignsUnderAgency() { // Test it doesn't return any data if no records are added $this->assertEqual(count($this->oDalCampaigns->getAllCampaignsUnderAgency(123, 'name', 'up')), 0); // Add test data (add a little bit more than required) $numCampaigns1 = 3; $aData = array('reportlastdate' => array('2007-04-03 18:39:45')); $dg = new DataGenerator(); $dg->setData('clients', $aData); $aCampaigns1 = $dg->generate('campaigns', $numCampaigns1, true); $agencyId1 = DataGenerator::getReferenceId('agency'); $numCampaigns2 = 2; $aData = array('reportlastdate' => array('2007-04-03 18:39:45')); $dg = new DataGenerator(); $dg->setData('clients', $aData); $aCampaigns2 = $dg->generate('campaigns', $numCampaigns2, true); $agencyId2 = DataGenerator::getReferenceId('agency'); $clientId = DataGenerator::getReferenceId('clients'); $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->clientid = $clientId; $doCampaigns->campaignname = 'market campaign'; $doCampaigns->type = DataObjects_Campaigns::CAMPAIGN_TYPE_MARKET_CAMPAIGN_OPTIN; $marketCampaignId = DataGenerator::generateOne($doCampaigns); // Take test data $aCampaigns = $this->oDalCampaigns->getAllCampaignsUnderAgency($agencyId2, 'name', 'up'); $this->assertEqual(count($aCampaigns), $numCampaigns2); // Make sure that both arrays have the same sorting ksort($aCampaigns); sort($aCampaigns2); $this->assertEqual(array_keys($aCampaigns), array_values($aCampaigns2)); $aIncludeSystemTypes = array(DataObjects_Campaigns::CAMPAIGN_TYPE_MARKET_CAMPAIGN_OPTIN); $aCampaigns = $this->oDalCampaigns->getAllCampaignsUnderAgency($agencyId2, 'name', 'up', $aIncludeSystemTypes); $this->assertEqual(count($aCampaigns), $numCampaigns2 + 1); }
/** * Test delete() and deleteOnCascade() * */ function testDelete() { DataGenerator::cleanUp(array('audit')); // Create few records $aAgencyId = DataGenerator::generate('agency', 3); $agencyId = array_pop($aAgencyId); $doClients = OA_Dal::factoryDO('clients'); $doClients->reportlastdate = '2007-04-03 18:39:45'; $aClientId1 = DataGenerator::generate($doClients, 2); $doClients = OA_Dal::factoryDO('clients'); $doClients->agencyid = $agencyId; $doClients->reportlastdate = '2007-04-03 18:39:45'; $aClientId2 = DataGenerator::generate($doClients, 2); $doAgency = OA_Dal::staticGetDO('agency', $agencyId); // Test that onDeleteCascade is set $this->assertTrue($doAgency->onDeleteCascade); // Delete one agency $doAgency->delete(); // Test that agency was deleted $doAgency = OA_Dal::factoryDO('agency'); $aAgencyIdTest = $doAgency->getAll('agencyid'); $this->assertEqual(array_values($aAgencyId), $aAgencyIdTest); // Test that associated clients were deleted as well $doClients = OA_Dal::factoryDO('clients'); $aClientId1Test = $doClients->getAll('clientid'); $this->assertEqual($aClientId1, $aClientId1Test); // only two should left DataGenerator::cleanUp(array('audit')); }