/** @test */ public function it_should_use_all_the_blocks_defined_in_the_current_template() { $price = new Text('price'); $captcha = new Captcha('captcha', new FakeCaptchaAdapter()); $html = $this->environment->render('forms/captcha.html.twig', ['price' => $price->buildView(), 'captcha' => $captchaView = $captcha->buildView()]); $this->assertEquals(sprintf('<div class="form-group"><label for="price">Price</label><div class="input-group"><div class="input-group-addon">$</div><input type="text" name="price" id="price" class="form-control"><div class="input-group-addon">.00</div></div></div><div class="form-group"><label>Please type this word below</label><img alt="" src="/images/capctha/%s.png"><br><input name="captcha[input]" type="text"><input name="captcha[id]" type="hidden" value="%s"></div>', $captchaView->options['captcha_id'], $captchaView->options['captcha_id']), $html); }
/** @test */ public function it_should_process_an_element_with_a_label() { $name = new Text('name'); $nameView = $name->buildView(); $options = ['attr' => ['class' => 'js-tooltip'], 'label' => 'Name', 'label_attr' => ['class' => 'required-label']]; $processedOptions = $this->options->process($nameView, $options); $this->assertEquals(['element' => $nameView, 'isValid' => true, 'attr' => ['class' => 'js-tooltip', 'type' => 'text', 'name' => 'name'], 'options' => [], 'label' => 'Name', 'label_attr' => ['class' => 'required-label']], $processedOptions); }
/** @test */ public function it_should_render_a_form_element_error_messages() { $name = new Text('name'); $name->setMessages(['Name is required and cannot be empty', 'Name length should be at least 3 characters']); $label = $this->renderer->renderErrors($name->buildView()); $this->assertEquals('<ul class="list-unstyled"><li class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> Name is required and cannot be empty</li><li class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> Name length should be at least 3 characters</li></ul>', $label); $name->setMessages([]); $label = $this->renderer->renderErrors($name->buildView()); $this->assertEquals('', $label); }
/** @test */ public function it_should_render_a_form_element_error_messages() { $name = new Text('name'); $name->setMessages(['Name is required and cannot be empty', 'Name length should be at least 3 characters']); $label = $this->renderer->renderErrors($name->buildView()); $this->assertEquals('<ul><li>Name is required and cannot be empty</li><li>Name length should be at least 3 characters</li></ul>', $label); $name->setMessages([]); $label = $this->renderer->renderErrors($name->buildView()); $this->assertEquals('', $label); }
/** * @param ElementView $view * @return MoneyView */ public function buildView(ElementView $view = null) { $view = new MoneyView(); /** @var MoneyView $view */ $view = parent::buildView($view); $view->amount = $this->amount->buildView(); $view->currency = $this->currency; $view->block = 'money'; return $view; }
function it_should_add_error_messages_to_the_corresponding_element(Text $username, Password $password) { $usernameMessages = ['Username cannot be empty']; $username->beConstructedWith(['username']); $username->name()->willReturn('username'); $password->beConstructedWith(['password']); $password->name()->willReturn('password'); $username->setMessages($usernameMessages)->shouldBeCalled(); $this->add($username)->add($password); $this->setErrorMessages(['username' => $usernameMessages]); }
function it_should_render_an_element_label(FormTheme $theme, Template $template) { $username = new Text('username'); $labelAttributes = ['class' => 'js-label']; $elementId = 'username'; $usernameView = $username->buildView(); $theme->loadTemplateFor('label')->willReturn($template); $theme->blocks()->willReturn([]); $this->renderLabel($usernameView, 'Username', $elementId, $labelAttributes); $template->displayBlock('label', ['label' => 'Username', 'attr' => $labelAttributes + ['for' => $elementId], 'is_required' => $usernameView->isRequired], [])->shouldHaveBeenCalled(); }