/** * A method to test the getAllDeliveryLimitationsByTypeId() method. * * Requirements: * Test 1: Test for ad limitations with no data, and ensure null returned * Test 2: Test for channel limitations with no data, and ensure null returned * Test 3: Test with an ad limitation for an ad, but with a different ad id, and * ensure null returned * Test 4: Test with an ad limitation, but with a channel id, and ensure null * returned * Test 5: Test with an ad limitation, but with a bad $type, and ensure null * returned * Test 6: Test with an ad limitation, and ensure values returned * Test 7: Test with a channel limitation, but with an ad id, and ensure null * returned * Test 8: Test with a channel limitation, but with a different channel id, and * ensure null returned * Test 9: Test with a channel limitation, but with a bad $type, and ensure null * returned * Test 10: Test with a channel limitation, and ensure values returned */ function testGetAllDeliveryLimitationsByTypeId() { $aConf = $GLOBALS['_MAX']['CONF']; $oDbh =& OA_DB::singleton(); $oDalMaintenanceCommon = new OA_Dal_Maintenance_Common(); // Test 1 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'ad'); $this->assertNull($aResult); // Test 2 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'channel'); $this->assertNull($aResult); $table = $aConf['table']['prefix'] . $aConf['table']['acls']; $query = "\n INSERT INTO\n " . $oDbh->quoteIdentifier($table, true) . "\n (\n bannerid,\n logical,\n type,\n comparison,\n data,\n executionorder\n )\n VALUES\n (?, ?, ?, ?, ?, ?)"; $aTypes = array('integer', 'text', 'text', 'text', 'text', 'integer'); $st = $oDbh->prepare($query, $aTypes, MDB2_PREPARE_MANIP); $aData = array(3, 'and', 'Time:Date', '!=', '2005-05-25', 0); $rows = $st->execute($aData); $aData = array(3, 'and', 'Geo:Country', '==', 'GB', 1); $rows = $st->execute($aData); // Test 3 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'ad'); $this->assertNull($aResult); // Test 4 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'channel'); $this->assertNull($aResult); // Test 5 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(3, 'foo'); $this->assertNull($aResult); // Test 6 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(3, 'ad'); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 2); $this->assertEqual(count($aResult[0]), 6); $this->assertEqual($aResult[0]['ad_id'], 3); $this->assertEqual($aResult[0]['logical'], 'and'); $this->assertEqual($aResult[0]['type'], 'Time:Date'); $this->assertEqual($aResult[0]['comparison'], '!='); $this->assertEqual($aResult[0]['data'], '2005-05-25'); $this->assertEqual($aResult[0]['executionorder'], 0); $this->assertEqual(count($aResult[1]), 6); $this->assertEqual($aResult[1]['ad_id'], 3); $this->assertEqual($aResult[1]['logical'], 'and'); $this->assertEqual($aResult[1]['type'], 'Geo:Country'); $this->assertEqual($aResult[1]['comparison'], '=='); $this->assertEqual($aResult[1]['data'], 'GB'); $this->assertEqual($aResult[1]['executionorder'], 1); $aCleanupTables = array($aConf['table']['acls']); foreach ($aCleanupTables as $table) { $query = "DELETE FROM {$aConf['table']['prefix']}{$table}"; $oDbh->exec($query); } DataGenerator::resetSequence($aCleanupTables); TestEnv::restoreEnv(); $table = $aConf['table']['prefix'] . $aConf['table']['acls_channel']; $query = "\n INSERT INTO\n " . $oDbh->quoteIdentifier($table, true) . "\n (\n channelid,\n logical,\n type,\n comparison,\n data,\n executionorder\n )\n VALUES\n (?, ?, ?, ?, ?, ?)"; $aTypes = array('integer', 'text', 'text', 'text', 'text', 'integer'); $st = $oDbh->prepare($query, $aTypes, MDB2_PREPARE_MANIP); $aData = array(3, 'and', 'Time:Date', '!=', '2005-05-25', 0); $rows = $st->execute($aData); $aData = array(3, 'and', 'Geo:Country', '==', 'GB', 1); $rows = $st->execute($aData); // Test 7 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'ad'); $this->assertNull($aResult); // Test 8 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'channel'); $this->assertNull($aResult); // Test 9 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(3, 'foo'); $this->assertNull($aResult); // Test 10 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(3, 'channel'); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 2); $this->assertEqual(count($aResult[0]), 6); $this->assertEqual($aResult[0]['ad_id'], 3); $this->assertEqual($aResult[0]['logical'], 'and'); $this->assertEqual($aResult[0]['type'], 'Time:Date'); $this->assertEqual($aResult[0]['comparison'], '!='); $this->assertEqual($aResult[0]['data'], '2005-05-25'); $this->assertEqual($aResult[0]['executionorder'], 0); $this->assertEqual(count($aResult[1]), 6); $this->assertEqual($aResult[1]['ad_id'], 3); $this->assertEqual($aResult[1]['logical'], 'and'); $this->assertEqual($aResult[1]['type'], 'Geo:Country'); $this->assertEqual($aResult[1]['comparison'], '=='); $this->assertEqual($aResult[1]['data'], 'GB'); $this->assertEqual($aResult[1]['executionorder'], 1); $aCleanupTables = array($aConf['table']['acls_channel']); foreach ($aCleanupTables as $table) { $query = "DELETE FROM {$aConf['table']['prefix']}{$table}"; $oDbh->exec($query); } DataGenerator::resetSequence($aCleanupTables); }