Exemple #1
0
 /**
  * Basic tests for the Section builder classes.
  *
  * Any test here could potentially fail because of a failure in the constructed section.
  *
  * @throws \Exception
  */
 public function testBuilder()
 {
     $content = "content";
     $label = "label";
     $writable = SectionBuilder::begin()->setId("s" . (string) rand())->addContent($content)->addLabel($label)->build();
     $id = "i" . (string) rand();
     $title = "title";
     $classes = [(string) rand(), (string) rand()];
     $breadCrumbs = ["name" => "http://link"];
     $baseHref = ".";
     $header = "header";
     $subHeader = "subHeader";
     $type = PageBuilder::TYPE_FULL_HEADER;
     $page = PageBuilder::begin()->setId($id)->setTitle($title)->addClass($classes[0])->addClass($classes[1])->setBaseHref($baseHref)->addBreadCrumb(array_keys($breadCrumbs)[0], array_values($breadCrumbs)[0])->addWritable($writable)->setHeader($header)->setSubHeader($subHeader)->setType($type)->build();
     $writables = $this->flattenWritables($page->getWritableBearer());
     $this->assertEquals($id, $page->getId());
     $this->assertArraySubset($classes, $page->getClasses());
     $this->assertEquals($title, $page->getTitle());
     $this->assertContains($writable, $writables);
     $this->assertEquals($baseHref, $page->getBaseHref());
     $this->assertEquals($type, $page->getType());
     $breadCrumbFilter = function ($writable) use($breadCrumbs) {
         return $writable instanceof Link && $writable->getURI() === array_values($breadCrumbs)[0] && $writable->getText() === array_keys($breadCrumbs)[0];
     };
     $headerFilter = function ($writable) use($header) {
         return $writable instanceof SectionInterface && $writable->getType() === SectionInterface::TYPE_HEADER && $writable->getWritables()[0] instanceof FieldInterface && strpos($writable->getWritables()[0]->getInitial(), $header) !== false;
     };
     $subheaderFilter = function ($writable) use($subHeader) {
         return $writable instanceof SectionInterface && $writable->getType() === SectionInterface::TYPE_SUBHEADER && $writable->getWritables()[0] instanceof FieldInterface && strpos($writable->getWritables()[0]->getInitial(), $subHeader) !== false;
     };
     $this->assertEquals(1, sizeof(array_filter($writables, $breadCrumbFilter)));
     $this->assertEquals(1, sizeof(array_filter($writables, $headerFilter)));
     $this->assertEquals(1, sizeof(array_filter($writables, $subheaderFilter)));
 }
Exemple #2
0
 /**
  * @param mixed $object
  * @return $this
  */
 public function addObject($object)
 {
     $object = $this->wrapObject($object);
     $labels = $object->getUnqualifiedTitleCasedColumnNames();
     foreach ($object->getValues() as $name => $value) {
         $this->addWritable(SectionBuilder::begin()->setType(SectionBuilder::TYPE_SPAN)->addContent($value)->build(), $name)->setColumnLabel($name, $labels[$name]);
     }
     return $this;
 }
 /**
  * @return PageInterface
  * @throws Exception If the a query has not been provided.
  */
 public function build()
 {
     $this->validateInitializer();
     $this->validateRenderer();
     if ($this->queries === []) {
         throw new Exception("For an object manager page, you must provide a Propel query(ies) using ::addQuery.");
     }
     $pageContents = WritableBearerBuilder::begin()->addWritable(SectionBuilder::begin()->setType(SectionBuilder::TYPE_DIV)->setId('page-content')->addWritable(SectionBuilder::begin()->setType(SectionBuilder::TYPE_DIV)->setId('page-content-head')->addWritable($this->buildTopMatter())->build())->addWritable(SectionBuilder::begin()->setType(SectionBuilder::TYPE_DIV)->setId('page-content-body')->addWritable($this->buildWritableBearer())->addWritable(SectionBuilder::begin()->setId('admin-tables-container')->build())->build())->build())->build();
     $admin = new Admin($this->id, $this->type, $this->classes, $this->data, $this->title, $this->baseHref, $this->initializer, $this->renderer, $pageContents, $this->queries);
     return $admin;
 }
Exemple #4
0
 /**
  * Basic tests for the Section builder classes.
  *
  * Any test here could potentially fail because of a failure in the constructed section.
  *
  * @throws \Exception
  */
 public function testBuilder()
 {
     $field = new Field([], [], "literal", "A literal field", []);
     $content = "content\ncontent";
     $label = "label";
     $writable = $field;
     $id = "s" . (string) rand();
     $classes = [(string) rand(), (string) rand()];
     $scriptContents = "c" . (string) rand();
     $section = SectionBuilder::begin()->setId($id)->addClass($classes[0])->addClass($classes[1])->addContent($content)->addLabel($label)->addScript($scriptContents)->addWritable($writable)->build();
     $this->assertEquals($id, $section->getId());
     $this->assertEquals($classes, $section->getClasses());
     $this->assertEquals(nl2br($content), $section->getWritables()[0]->getInitial());
     $this->assertEquals($label, $section->getWritables()[1]->getInitial());
     $this->assertEquals($scriptContents, $section->getWritables()[2]->getContents());
     $this->assertContains($writable, $section->getWritables());
     $this->assertEquals(4, sizeof($section->getWritables()));
     $this->assertEquals("base", $section->getType());
 }
Exemple #5
0
 /**
  * @return PageInterface
  * @throws \Exception If the type of the page has not been set.
  */
 public function build()
 {
     if ($this->type === null) {
         throw new \Exception("You must set a page type using ::setType before calling this function.");
     }
     $this->validateInitializer();
     $this->validateRenderer();
     $writable = WritableBearerBuilder::begin()->addWritable(SectionBuilder::begin()->setType(SectionBuilder::TYPE_DIV)->setId('page-content')->addWritable(SectionBuilder::begin()->setType(SectionBuilder::TYPE_DIV)->setId('page-content-head')->addWritable($this->buildTopMatter())->build())->addWritable(SectionBuilder::begin()->setType(SectionBuilder::TYPE_DIV)->setId('page-content-body')->addWritable($this->buildWritableBearer())->build())->build())->build();
     return new Page($this->id, $this->type, $this->classes, $this->data, $this->title, $this->baseHref, $this->initializer, $this->renderer, $writable);
 }
 /**
  * Test that an initializer will initialize a page's section's form.
  */
 public function testVisitPage()
 {
     $_SERVER["REQUEST_METHOD"] = "POST";
     $initializer = new Initializer();
     $form = $this->makeMockForm();
     $this->assertEquals("", $form->validated);
     $page = PageBuilder::begin()->setId("test-page")->addWritable(SectionBuilder::begin()->setId("s" . (string) rand())->addWritable($form)->build())->setType("full-header")->build();
     $initializer->visitPage($page);
     $this->assertTrue($form->validated);
 }
Exemple #7
0
 /**
  * @return WritableInterface
  */
 protected function makeDelete()
 {
     $this->getObjectOr404()->delete();
     return SectionBuilder::begin()->addContent('Object deleted')->build();
 }
 /**
  * @param string $class
  * @return $this
  */
 public function addBreak($class = '')
 {
     $contentBuilder = SectionBuilder::begin()->setType(SectionBuilder::TYPE_BREAK);
     if ($class !== '') {
         $contentBuilder->addClass($class);
     }
     $this->addWritable($contentBuilder->build());
     return $this;
 }
Exemple #9
0
 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);
 }