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']); }
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'])); }
/** * @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()); }
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 __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); $this->nativeOutputHandler = new NativeOutputHandlersTestCore(); $this->pocContainer = new \Pimple(); $this->pocContainer['poc'] = function () { $cache = new FileCache(); $hasher = new Hasher(); $hasher->addDistinguishVariable(rand()); $poc = new Poc(array(Poc::PARAM_CACHE => $cache, Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()))); return $poc; }; $this->pocContainer['noh'] = function () { return new NativeOutputHandlersTestCore(); }; $this->pocContainer['cia'] = function () { return new ROIProtector(); }; $this->cia = new ROIProtector(); }
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 fetchCache() { $this->pocDispatcher->dispatch(PocEventNames::FUNCTION_FETCHCACHE_BEGINNING, new BaseEvent($this)); $this->output = $this->cache->fetch($this->hasher->getKey()); if ($this->output) { $this->pocDispatcher->dispatch(PocEventNames::GET_OUTPUT_FROM_CACHE, new BaseEvent($this)); } }
public function testPocWithDifferentHashers() { $testAdapter = new NativeOutputHandlersTestCore(); $objects = new \Pimple(); $ttl = self::$TTL; $objects['c1'] = function () use($ttl) { return new FileCache(array(CacheParams::PARAM_TTL => $ttl)); }; $objects['c2'] = function () use($ttl) { return new FileCache(array(CacheParams::PARAM_TTL => $ttl)); }; $cacheHandler1 = $objects['c1']; $hasher1 = new Hasher(); $hasher1->addDistinguishVariable("a" . rand()); $poc1 = new Poc(array(Poc::PARAM_HASHER => $hasher1, Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()))); $testAdapter->pocBurner($poc1, self::NEEDLE); $output1 = $testAdapter->getOutput(); $hasher2 = new Hasher(); $hasher2->addDistinguishVariable("b" . rand()); $poc2 = new Poc(array(Poc::PARAM_HASHER => $hasher2, Poc::PARAM_TOOLSET => new HttpCapture(new TestOutput()))); $testAdapter->pocBurner($poc2, self::TESTSTRING2); $output2 = $testAdapter->getOutput(); $this->assertTrue($output1 != $output2); }