function _testImageServe($timeZone)
 {
     OA_setTimeZone($timeZone);
     $fileName = 'tz_test.gif';
     $doImages = OA_Dal::factoryDO('images');
     $doImages->filename = $fileName;
     $doImages->contents = '';
     $this->assertTrue(DataGenerator::generateOne($doImages));
     $now = time();
     $this->assertTrue($timeZone == 'UTC' || date('Z', $now), 'Time zone not correctly set');
     // Simulate delivery
     OA_setTimeZoneUTC();
     $aCreative = OA_Dal_Delivery_getCreative($fileName);
     $this->assertTrue($aCreative);
     // Serve with no If-Modified-Since header
     unset($GLOBALS['_HEADERS']);
     unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
     MAX_imageServe($aCreative, $fileName, 'gif');
     if ($this->assertEqual(count($GLOBALS['_HEADERS']), 2, 'Mismatching headers with ' . $timeZone)) {
         $this->assertPattern('/^Last-Modified: /i', $GLOBALS['_HEADERS'][0]);
         $this->assertPattern('/^Content-Type: /i', $GLOBALS['_HEADERS'][1]);
     }
     // 1-day old If-Modified-Since header
     unset($GLOBALS['_HEADERS']);
     $_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', $now - 86400) . ' GMT';
     MAX_imageServe($aCreative, $fileName, 'gif');
     if ($this->assertEqual(count($GLOBALS['_HEADERS']), 2, 'Mismatching headers with ' . $timeZone)) {
         $this->assertPattern('/^Last-Modified: /i', $GLOBALS['_HEADERS'][0]);
         $this->assertPattern('/^Content-Type: /i', $GLOBALS['_HEADERS'][1]);
     }
     // 1-day future If-Modified-Since header
     unset($GLOBALS['_HEADERS']);
     $_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', $now + 86400) . ' GMT';
     MAX_imageServe($aCreative, $fileName, 'gif');
     if ($this->assertEqual(count($GLOBALS['_HEADERS']), 1, 'Mismatching headers with ' . $timeZone)) {
         $this->assertPattern('/^HTTP\\/1.0 304/i', $GLOBALS['_HEADERS'][0]);
     }
     // 1 minute ago If-Modified-Since header
     unset($GLOBALS['_HEADERS']);
     $_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', $now - 60) . ' GMT';
     MAX_imageServe($aCreative, $fileName, 'gif');
     if ($this->assertEqual(count($GLOBALS['_HEADERS']), 2, 'Mismatching headers with ' . $timeZone)) {
         $this->assertPattern('/^Last-Modified: /i', $GLOBALS['_HEADERS'][0]);
         $this->assertPattern('/^Content-Type: /i', $GLOBALS['_HEADERS'][1]);
     }
     // 1 minute in future If-Modified-Since header
     unset($GLOBALS['_HEADERS']);
     $_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', $now + 60) . ' GMT';
     MAX_imageServe($aCreative, $fileName, 'gif');
     if ($this->assertEqual(count($GLOBALS['_HEADERS']), 1, 'Mismatching headers with ' . $timeZone)) {
         $this->assertPattern('/^HTTP\\/1.0 304/i', $GLOBALS['_HEADERS'][0]);
     }
 }
Ejemplo n.º 2
0
function MAX_cacheGetCreative($filename, $cached = true)
{
    $sName = OA_Delivery_Cache_getName(__FUNCTION__, $filename);
    if (!$cached || ($aCreative = OA_Delivery_Cache_fetch($sName)) === false) {
        MAX_Dal_Delivery_Include();
        $aCreative = OA_Dal_Delivery_getCreative($filename);
        $aCreative['contents'] = addslashes(serialize($aCreative['contents']));
        $aCreative = OA_Delivery_Cache_store_return($sName, $aCreative);
    }
    $aCreative['contents'] = unserialize(stripslashes($aCreative['contents']));
    return $aCreative;
}