public function getDoctrine2Tagging() { $options = self::$doctrineOptions; $tagging = new Doctrine2Tagging($options); $cache = new \Poc\Cache\CacheImplementation\FileCache(array(\Poc\Cache\CacheImplementation\CacheParams::PARAM_TTL => $GLOBALS['TTL'])); $poc = new Poc(array(Poc::PARAM_CACHE => $cache, Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()))); $poc->addPlugin($tagging); return $tagging; }
public function fetchHeaders() { $this->headersToSend = unserialize($this->poc->getCache()->fetch($this->poc->getHasher()->getKey() . self::HEADER_POSTFIX)); if ($this->headersToSend) { foreach ($this->headersToSend as $header) { $this->poc->getEventDispatcher()->getPlugin(HttpCapture::PLUGIN_NAME)->getOutputHandler()->header($header); } } }
public function testEtagReceive() { $hasher = new Hasher(); $hasher->addDistinguishVariable("TestEtag2" . rand()); $poc = new Poc(array(Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()), PocParams::PARAM_HASHER => $hasher)); $outputHandler = $poc->getEventDispatcher()->getPlugin(HttpCapture::PLUGIN_NAME)->getOutputHandler(); $outputHandler->allheaders['If-None-Match'] = 'c075eba9c04d3faf4ac21fd29cae6fd8'; $poc->addPlugin(new Etag()); $this->pocBurner($poc, self::ETAG_TEXT); $header = $outputHandler->getHeader(); $this->assertTrue(isset($header['HTTP/1.0 304 Not Modified'])); }
public function testContentLenght() { $hasher = new Hasher(); $hasher->addDistinguishVariable("TestContentLength" . rand()); $poc = new Poc(array(Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()), PocParams::PARAM_HASHER => $hasher)); $outputHandler = $poc->getEventDispatcher()->getPlugin(HttpCapture::PLUGIN_NAME)->getOutputHandler(); $poc->addPlugin(new ContentLength()); $testString = "123"; $this->pocBurner($poc, $testString); $header = $outputHandler->getHeader(); $this->assertEquals(strlen($testString), $header['Content-Length']); }
/** * @dataProvider dataProviderForTests */ public function testminifyHtmlWithPoc($input, $expectedOutput) { $noh = new NativeOutputHandlersTestCore(); $hasher = new Hasher(); $hasher->addDistinguishVariable("TestMinify" . rand()); $cache = new FileCache(array(CacheParams::PARAM_TTL => 1000)); $outputHandler = new TestOutput(); $poc = new Poc(array(Poc::PARAM_CACHE => $cache, Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()), PocParams::PARAM_HASHER => $hasher)); $poc->addPlugin(new MinifyHtmlOutput()); $noh->pocBurner($poc, $input); $output = $noh->getOutput(); $this->assertEquals($expectedOutput, $output); }
public function testOutputFilter() { $noh = new NativeOutputHandlersTestCore(); $hasher = new Hasher(); $hasher->addDistinguishVariable("testOutputFilter" . rand()); $cache = new FileCache(array(CacheParams::PARAM_TTL => 1000)); $outputFilter = new OutputFilter(); $outputFilter->addBlacklistCondition("/Needle/"); $poc = new Poc(array(PocParams::PARAM_CACHE => $cache, Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()), PocParams::PARAM_HASHER => $hasher)); $poc->addPlugin($outputFilter); $noh->pocBurner($poc, rand() . "Needle" . rand()); //$this->assertContains('because', $noh->getOutput()); }
/** * This function has got a weird name, because it does not do anything else * only inspect the getOutputFlow function of the output handler and decides * what to do with the $testsring variable it receives. This tries to * emulate the behahviour of the server to the $poc object. * * @param $poc Poc * @param $outputHandler TestOutput * @param $testString string */ public function pocBurner(Poc $poc, $testString = "testString") { if ($poc->getEventDispatcher()->hasPlugin(PocLogs::PLUGIN_NAME)) { $poc->addPlugin(new PocLogs()); } $this->setOutput(''); $poc->start(); if ($poc->getEventDispatcher()->hasPlugin(HttpCapture::PLUGIN_NAME)) { $outputHandler = $poc->getEventDispatcher()->getPlugin(HttpCapture::PLUGIN_NAME)->getOutputHandler(); } if ($outputHandler->getOutputFlow()) { echo $testString; $poc->end(); //var_dump($outputHandler); $this->setHeader($outputHandler->getallheaders()); $this->setOutput($outputHandler->getOutput()); } else { $this->setHeader($outputHandler->getallheaders()); $this->setOutput($outputHandler->getOutput()); $poc->end(); //var_dump($outputHandler); if ($outputHandler->getOutput()) { $this->setHeader($outputHandler->getallheaders()); $this->setOutput($outputHandler->getOutput()); } } }
private function setCompressiontype(Poc $poc) { $httpCapture = $poc->getEventDispatcher()->getPlugin(HttpCapture::PLUGIN_NAME); $outputHandler = $httpCapture->getOutputHandler(); $headers = $outputHandler->getallheaders(); if (isset($headers['Accept-Encoding'])) { if (strstr($headers['Accept-Encoding'], self::COMPRESSION_GZIP)) { $this->compressionType = self::COMPRESSION_GZIP; } else { //die ("CCCCCCCCCCCCC"); } } //$this->compressionType = self::COMPRESSION_DEFLATE; }
public function pocCallbackCache($buffer) { $this->poc->setOutput($buffer); $this->poc->getPocDispatcher()->dispatch(CallbackHandlerEventNames::BEFORE_OUTPUT_SENT_TO_CLIENT_FETCHED_FROM_CACHE, new BaseEvent($this->poc)); $this->outputHandler->ObPrintCallback($this->poc->getOutput()); return $this->poc->getOutput(); }
public function testTagging() { $getPoc = function ($key, $addCacheAddTags = '', $addCacheInvalidationTags = '') { $getCache = function () { return new FileCache(array(CacheParams::PARAM_TTL => NativeOutputHandlersTestCore::BIGTTL)); }; $hasher1 = new Hasher(); $hasher1->addDistinguishVariable($key); $cache1 = $getCache($hasher1); $cache1->clearAll(); $options = $GLOBALS['DOCTRINE_OPTIONABLE']; $poc1 = new Poc(array(Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()), PocParams::PARAM_CACHE => $cache1, PocParams::PARAM_HASHER => $hasher1)); $tagger1 = new Doctrine2Tagging($options); $poc1->addPlugin($tagger1); if ($addCacheAddTags) { $tagger1->addCacheAddTags(true, $addCacheAddTags); } if ($addCacheInvalidationTags) { $tagger1->addCacheInvalidationTags(true, $addCacheInvalidationTags); } $ret['poc'] = $poc1; $ret['tagger'] = $tagger1; return $ret; }; $poc1 = $getPoc('distn1', 'user,customer,inventory,a,b,c,d,e,f,b,h,i,j,k,l,m,n,o,p'); $poc11 = $getPoc('distn2', 'user,customer,inventory'); $poc2 = $getPoc('distn1', 'inventory', 'p'); $poc3 = $getPoc('distn4', 'inventory,customer'); $poc4 = $getPoc('distn4', 'inventory,customer', 'p'); $this->pocBurner($poc1['poc'], "11"); $o1 = $this->getOutput(); $poc1['tagger']->addCacheInvalidationTags(true, 'stuff'); $this->pocBurner($poc11['poc'], "11"); $o12 = $this->getOutput(); $this->assertTrue($o1 == $o12); $poc2['tagger']->addCacheInvalidationTags(true, 'user'); $this->pocBurner($poc2['poc'], "13"); $o2 = $this->getOutput(); $this->assertEquals("13", $o2); $poc3['tagger']->addCacheInvalidationTags(true, 'p'); $this->pocBurner($poc3['poc'], "14"); $o3 = $this->getOutput(); $this->pocBurner($poc3['poc'], "15"); $o4 = $this->getOutput(); $this->assertEquals("14", $o4); }
public function init($poc) { $this->poc = $poc; $this->pocDispatcher = $poc->getPocDispatcher(); $this->logger = $this->poc->getLogger(); $this->pocDispatcher->addListener(PocEventNames::BEFORE_OUTPUT_SENT_TO_CLIENT_AFTER_OUTPUT_STORED, array($this, 'beforeOutputSentToClinetAfterOutputStoredTime')); $this->pocDispatcher->addListener(PocEventNames::BEFORE_OUTPUT_SENT_TO_CLIENT_AFTER_OUTPUT_STORED, array($this, 'beforeOutputSentToClinetAfterOutputStoredOutput')); $this->pocDispatcher->addListener(PocEventNames::BEFORE_OUTPUT_SENT_TO_CLIENT_NO_CACHING_PROCESS_INVOLVED, array($this, 'beforeOutputSentToClientNoCachingProcessInvolvedTime')); $this->pocDispatcher->addListener(PocEventNames::BEFORE_OUTPUT_SENT_TO_CLIENT_NO_CACHING_PROCESS_INVOLVED, array($this, 'beforeOutputSentToClientNoCachingProcessInvolvedOutput')); $this->pocDispatcher->addListener(PocEventNames::BEFORE_OUTPUT_SENT_TO_CLIENT_FETCHED_FROM_CACHE, array($this, 'beforeOutputSentToClientFetchedFromCacheTime')); $this->pocDispatcher->addListener(PocEventNames::BEFORE_OUTPUT_SENT_TO_CLIENT_FETCHED_FROM_CACHE, array($this, 'beforeOutputSentToClientFetchedFromCacheOutput')); $this->pocDispatcher->addListener(PocEventNames::BEFORE_STORE_OUTPUT, array($this, 'beforeStoreOutputTime')); $this->pocDispatcher->addListener(PocEventNames::BEFORE_STORE_OUTPUT, array($this, 'beforeStoreOutputOutput')); $this->pocDispatcher->addListener(PocEventNames::OUTPUT_STORED, array($this, 'outputStoredTime')); $this->pocDispatcher->addListener(EtagEvents::ETAG_FOUND, array($this, 'etagFoundTime')); $this->pocDispatcher->addListener(EtagEvents::ETAG_NOT_FOUND, array($this, 'etagNotFoundTime')); // todo: If it is turned on, the php fly away with segmentation fault // when phpunit runs. /* * $this->pocDispatcher->addListener(PocEventNames::DIES, array($this, * 'diesTime')); */ }
public function testCompression() { $noh = new NativeOutputHandlersTestCore(); $hasher = new Hasher(); $hasher->addDistinguishVariable("TestCompress" . rand()); $cache = new FileCache(); $outputHandler = new TestOutput(); $outputHandler->header('Accept-Encoding:' . Compress::COMPRESSION_GZIP); // var_dump($outputHandler->getallheaders()); $poc = new Poc(array(Poc::PARAM_CACHE => $cache, Poc::PARAM_TOOLSET => new HttpCapture($outputHandler), PocParams::PARAM_HASHER => $hasher)); $poc->addPlugin(new Compress()); $input1 = "absdefg"; $noh->pocBurner($poc, $input1); $output1 = $noh->getOutput(); $header1 = $outputHandler->getallheaders(); $input2 = "habsdefgh"; $noh->pocBurner($poc, $input2); $output2 = $noh->getOutput(); $header2 = $outputHandler->getallheaders(); // die("BBBBBBBBBBBB".print_r($outputHandler->getallheaders())."AAAAAAAAAAAAAAAA"); $this->assertEquals($output1, $output2); $this->assertEquals(\gzdecode($output1), $input1); // $this->assertEquals($header1, $header2); }
public function consult(BaseEvent $event) { $sentinelCnt = $this->getSentinel(); $this->setSentinel($sentinelCnt + 1); if ($sentinelCnt) { $this->eventDispatcher->dispatch(ROIProtectorEventNames::CONSULT_STARTED, new ROIEvent($this)); if ($sentinelCnt >= 1 and $sentinelCnt <= 2) { while ($this->getSentinel()) { // $this->monoLogger->setLog(self::LOG_TYPE_CIA, // "Sleep: $sentinelCnt"); usleep(500000); } echo $this->poc->fetchCache(); } if ($sentinelCnt >= $this->maxNumberOfConcurrentConnections) { $this->outputHandler->ObPrintCallback($this->getRefreshPage()); $this->outputHandler->stopBuffer(); } } // $this->monoLogger->setLog(self::LOG_TYPE_CIA, "end: $sentinelCnt"); }
public function getOutputFromCache(BaseEvent $event) { $this->outputHandler->startBuffer(CallbackHandler::CALLBACK_CACHE); $this->callbackHandler->getHeaderManipulator()->fetchHeaders(); $this->outputHandler->stopBuffer($this->poc->getOutput()); }