public function visitPage(PageInterface $page) { static::$used = true; parent::visitPage($page); }
public function testVisitPage() { $writer = new HTMLWriter(); $pageType = PageBuilder::TYPE_FULL_HEADER; $pageHeader = "Page Header"; $pageSubHeader = "Page subheader"; $id = "p" . (string) rand(); $classes = [(string) rand(), (string) rand()]; $data = ['d' . (string) rand() => (string) rand(), 'd' . (string) rand() => (string) rand()]; $breadCrumbs = ['t' . (string) rand() => 'u' . (string) rand()]; $section = SectionBuilder::begin()->setId("s" . (string) rand())->addLabel("Label")->addContent("Some content.")->build(); $page = PageBuilder::begin()->setId($id)->addClass($classes[0])->addClass($classes[1])->addWritable($section)->addData(array_keys($data)[0], array_values($data)[0])->addData(array_keys($data)[1], array_values($data)[1])->setHeader($pageHeader)->setSubHeader($pageSubHeader)->setType($pageType)->setTitle("Page Title")->setBaseHref(".")->addBreadCrumb(array_keys($breadCrumbs)[0], array_values($breadCrumbs)[0])->build(); // Add project CSS and JS $cssFile1 = "/path/to/file/1.css"; $cssFile2 = "/path/to/file/2.css"; $jsFile1 = "/path/to/file/1.js"; $jsFile2 = "/path/to/file/2.js"; Settings::getInstance()->addProjectCSS($cssFile1); Settings::getInstance()->addProjectCSS($cssFile2); Settings::getInstance()->addProjectJS($jsFile1); Settings::getInstance()->addProjectJS($jsFile2); // Provide a request URI, for the page's hash function $requestURI = (string) rand(); $_SERVER["REQUEST_URI"] = $requestURI; // Get result and strip quotes, for easier analysis $result = $this->stripQuotes($writer->visitPage($page)); $this->assertContains("<html>", $result); $this->assertContains("<head>", $result); $this->assertContains("<title>Page Title</title>", $result); $this->assertContains("<base href=.", $result); $this->assertContains("</head>", $result); $this->assertContains("<body id={$id}", $result); $this->assertContains("class=" . implode(" ", $classes), $result); $this->assertContains("data-" . array_keys($data)[0] . "=" . array_values($data)[0], $result); $this->assertContains("data-" . array_keys($data)[1] . "=" . array_values($data)[1], $result); $this->assertContains("href=" . array_values($breadCrumbs)[0] . ">" . array_keys($breadCrumbs)[0] . "</a>", $result); $this->assertRegExp("/h1.*class=header.*{$pageHeader}.*h1/s", $result); $this->assertRegExp("/h2.*class=subheader.*{$pageSubHeader}.*h2/s", $result); $this->assertContains("<div class=section-label >Label</div>", $result); $this->assertContains($cssFile1, $result); $this->assertContains($cssFile2, $result); $this->assertContains($jsFile1, $result); $this->assertContains($jsFile2, $result); }