public function formlets() { $alwaysTrue = V::fn(function ($_) { return true; }); $pure = F::pure(V::val(42)); return array(array($pure->satisfies($alwaysTrue, "ERROR"))); }
public function asFormlet($values) { $this->formlet_collected = F::pure(L::collect()); foreach ($values as $value) { $this->formlet_collected = $this->formlet_collected->cmb(F::pure(V::val($value))); } $this->formlet_collected = $this->formlet_collected->cmb(F::pure(V::val(new Stop()))); $ns = NameSource::instantiate("test"); $repr = $this->formlet_collected->instantiate($ns); $this->formlet_result = $repr["collector"]->collect(array()); }
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"); }
public function formlets() { return array(array(F::fieldset("Static: ", F::pure(V::val(42))))); }
/** * Append a span with class error to input formlet if the formlet collects * errors. * * @param IFormlet $formlet * @return IFormlet */ public static function with_errors(IFormlet $formlet) { return F::with_errors($formlet); }
public function formlets() { return array(array(F::pure(V::val(42)))); }
public function formlets() { $p = F::pure(V::val(42)); return array(array($p->cmb($p))); }
public function formlets() { return array(array(F::text("TEXT"))); }
public static function with_errors(Formlet $other) { return $other->mapHTML(V::fn(function ($dict, $html) { $name = self::html_get_depth_first_name($html); if ($name === null) { throw new Exception("_with_errors applied to un-named Formlet."); } $errors = $dict->errors($name); if ($errors === null) { return $html; } foreach ($errors as $error) { $html = H::concat($html, H::tag("span", array("class" => "error"), H::text($error))); } return $html; })); }
public function formlets() { return array(array(F::submit("SUBMIT"))); }
public function formlets() { return array(array(F::input("text"))); }
protected function assertFormletsEqual(Formlet $a, Formlet $b, $value, $contains_applicable) { // Two formlets are considered equal, when their observable output // is equal (that is like extensional equality?) $ns_a = NameSource::instantiate("test"); $ns_b = NameSource::instantiate("test"); $ns = NameSource::instantiate("test"); $repr_a = $a->instantiate($ns_a); $repr_b = $b->instantiate($ns_b); $name_and_ns = $ns->getNameAndNext(); $inp = array($name_and_ns["name"] => "100"); $val_a = $repr_a["collector"]->collect($inp); $val_b = $repr_b["collector"]->collect($inp); // This will only work if equal works as expected on the result, that // is the thing checked really is equality and not identity. if (!$contains_applicable) { if ($val_a->isError()) { print_r($val_a->toDict()); } $this->assertEquals($val_a->get(), $val_b->get()); } else { $this->assertEquals($val_a->apply($value)->get(), $val_b->apply($value)->get()); } $dict_a = new RenderDict($inp, $val_a); $dict_b = new RenderDict($inp, $val_b); $rendered_a = $repr_a["builder"]->build()->render(); $rendered_b = $repr_b["builder"]->build()->render(); $this->assertEquals($rendered_a, $rendered_b); $rendered_a2 = $repr_a["builder"]->buildWithDict($dict_a)->render(); $rendered_b2 = $repr_b["builder"]->buildWithDict($dict_b)->render(); $this->assertEquals($rendered_a2, $rendered_b2); }
public function formlets() { return array(array(F::text_input()), array(F::email()), array(F::password()), array(F::search()), array(F::url())); }
public function formlets() { return array(array(F::textarea()), array(F::textarea_raw())); }