Ejemplo n.º 1
0
 function depth_first_searches()
 {
     $is_text = V::fn(function ($html) {
         return $html instanceof HTMLText;
     });
     $get_text = V::fn(function ($html) {
         return $html->content();
     });
     return array(array(H::text("Hello World"), $is_text, $get_text, "Hello World"), array(H::nop(), $is_text, $get_text, null), array(H::tag("foo", array(), H::text("Hello World")), $is_text, $get_text, "Hello World"), array(H::tag("foo", array(), H::concat(H::text("Hello World"), H::text("Hello World"))), $is_text, $get_text, "Hello World"), array(H::tag("foo", array(), H::concat(H::tag("bar", array(), H::concat(H::text("Hello World"), H::text("Blub"))), H::text("Blaw"))), $is_text, $get_text, "Hello World"));
 }
Ejemplo n.º 2
0
 public function testMappedTwice()
 {
     $d = new RenderDict(array("foo" => "bar"), V::val(0));
     $n = NameSource::instantiate("test");
     $f = F::text("foobar");
     $rdict1 = null;
     $rhtml1 = null;
     $rdict2 = null;
     $rhtml2 = null;
     $transformation = V::fn(function ($dict, $html) use(&$rdict1, &$rhtml1) {
         $rdict1 = $dict;
         $rhtml1 = $html;
         return H::nop();
     });
     $transformation2 = V::fn(function ($dict, $html) use(&$rdict2, &$rhtml2) {
         $rdict2 = $dict;
         $rhtml2 = $html;
         return H::text("baz");
     });
     $f2 = $f->mapHTML($transformation)->mapHTML($transformation2);
     $i = $f2->instantiate($n);
     $r1 = $i["builder"]->build();
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict2);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $rhtml1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLNop", $rhtml2);
     $this->assertEquals($rhtml1->render(), "foobar");
     $this->assertEquals($rhtml2->render(), "");
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $r1);
     $this->assertEquals($r1->render(), "baz");
     $r2 = $i["builder"]->buildWithDict($d);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict2);
     $this->assertEquals($d, $rdict1);
     $this->assertEquals($d, $rdict2);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $rhtml1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLNop", $rhtml2);
     $this->assertEquals($rhtml1->render(), "foobar");
     $this->assertEquals($rhtml2->render(), "");
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $r2);
     $this->assertEquals($r2->render(), "baz");
 }
Ejemplo n.º 3
0
 function html_and_results()
 {
     return array(array(H::text("foo"), "foo"), array(H::nop(), ""));
 }
Ejemplo n.º 4
0
 public function buildWithDict(RenderDict $dict)
 {
     return H::nop();
 }
Ejemplo n.º 5
0
 public function testMappedTwiceBuilder()
 {
     $d = new RenderDict(array("foo" => "bar"), V::val(0));
     $b = new TextBuilder("foobar");
     $rdict1 = null;
     $rhtml1 = null;
     $rdict2 = null;
     $rhtml2 = null;
     $transformation = V::fn(function ($dict, $html) use(&$rdict1, &$rhtml1) {
         $rdict1 = $dict;
         $rhtml1 = $html;
         return H::nop();
     });
     $transformation2 = V::fn(function ($dict, $html) use(&$rdict2, &$rhtml2) {
         $rdict2 = $dict;
         $rhtml2 = $html;
         return H::text("baz");
     });
     $b2 = $b->map($transformation)->map($transformation2);
     $r1 = $b2->build();
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict2);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $rhtml1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLNop", $rhtml2);
     $this->assertEquals($rhtml1->render(), "foobar");
     $this->assertEquals($rhtml2->render(), "");
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $r1);
     $this->assertEquals($r1->render(), "baz");
     $r2 = $b2->buildWithDict($d);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict2);
     $this->assertEquals($d, $rdict1);
     $this->assertEquals($d, $rdict2);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $rhtml1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLNop", $rhtml2);
     $this->assertEquals($rhtml1->render(), "foobar");
     $this->assertEquals($rhtml2->render(), "");
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $r2);
     $this->assertEquals($r2->render(), "baz");
 }