Skip to content

Commit

Permalink
Test dispatcher processing flushes on success
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Aug 12, 2014
1 parent e64f620 commit 7a313ea
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions test/Unit/Dispatcher/PageDispatcher.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,48 @@ public function testDispatcherProcessFixesUri($uri) {
file_put_contents($filePath, "dummy data ($uri)");
}

for($force = 0; $force <= 1; $force++) {
$request = new \StdClass();
$request->forceExtension = !!$force;
$request->indexFilename = "index";
$request->uri = $uriRand;

$this->dispatcher = new PageDispatcher(
$request,
$this->response,
$this->apiFactory,
$this->dbFactory
);


$fixedUri = $this->dispatcher->process();
$this->assertInternalType("string", $fixedUri);
$this->assertEquals(
strtok(strtolower($fixedUri), "."),
strtok(strtolower($uriRand), ".")
);
}
}

public function testDispatcherFlushes() {
$html = "<!doctype html><h1>Test</h1>";
$this->expectOutputRegex("/<!DOCTYPE html>.*<h1>Test<\/h1>.*<\/html>/s");
$content = $this->dispatcher->createResponseContent($html);

$content->flush();
}

public function testDispatcherProcessFlushes() {
// All we need to know is that the content flushes, actual computation is
// tested in other test cases.
$this->expectOutputRegex("/.*<h1>Test<\/h1>.*/s");

$request = new \StdClass();
$request->forceExtension = false;
$request->forceExtension = true;
$request->indexFilename = "index";
$request->uri = $uriRand;
$request->uri = "/test.html";

file_put_contents($this->pageViewDir . "/test.html", "<h1>Test</h1>");

$this->dispatcher = new PageDispatcher(
$request,
Expand All @@ -281,21 +319,7 @@ public function testDispatcherProcessFixesUri($uri) {
$this->dbFactory
);


$fixedUri = $this->dispatcher->process();
$this->assertInternalType("string", $fixedUri);
$this->assertEquals(
strtok(strtolower($fixedUri), "."),
strtok(strtolower($uriRand), ".")
);
}

public function testDispatcherFlushes() {
$html = "<!doctype html><h1>Test</h1>";
$this->expectOutputRegex("/<!DOCTYPE html>.*<h1>Test<\/h1>.*<\/html>/s");
$content = $this->dispatcher->createResponseContent($html);

$content->flush();
$this->dispatcher->process();
}

}#

0 comments on commit 7a313ea

Please sign in to comment.