public function testFromRenderWithPassword() { $formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['status' => ['template' => 't4web-form-renderer/element/select', 'variables' => ['labels' => [1 => 'Active', 2 => 'In active', 3 => 'Deleted']]]], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']]; $factory = new Factory(); $form = $factory->create($formConfig); $form->setData(['status' => 3]); $form->setMessages(['status' => ["This field is required"]]); $rawHtml = $this->renderer->render($form); $this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create"> <div class="box-body"> <div class="form-group has-error"> <label>Select</label> <select name="status" class="form-control"> <option value="1" >Active</option> <option value="2" >In active</option> <option value="3" selected>Deleted</option> </select> <p class="help-block">This field is required</p> </div> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" id="submit-btn">Submit</button> <a class="btn btn-default" href="/admin/list">Cancel</a> </div> </form>'), preg_replace('/\\s+/', ' ', $rawHtml)); }
public function testFromRenderWithCheckbox() { $formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['terms' => ['template' => 't4web-form-renderer/element/checkbox', 'variables' => ['label' => 'Terms']]], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']]; $factory = new Factory(); $form = $factory->create($formConfig); $form->setData(['terms' => 1]); $form->setMessages(['terms' => ["You must read and check"]]); $rawHtml = $this->renderer->render($form); $this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create"> <div class="box-body"> <div class="form-group has-error"> <div class="checkbox"> <label> <input type="checkbox" name="terms" value="1"> Terms </label> </div> <p class="help-block">You must read and check</p> </div> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" id="submit-btn">Submit</button> <a class="btn btn-default" href="/admin/list">Cancel</a> </div> </form>'), preg_replace('/\\s+/', ' ', $rawHtml)); }
public function testFromRenderWithHidden() { $formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['id' => ['template' => 't4web-form-renderer/element/hidden']], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']]; $factory = new Factory(); $form = $factory->create($formConfig); $form->setData(['id' => 123]); $rawHtml = $this->renderer->render($form); $this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create"> <div class="box-body"> <input type="hidden" name="id" class="form-control" value="123"> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" id="submit-btn">Submit</button> <a class="btn btn-default" href="/admin/list">Cancel</a> </div> </form>'), preg_replace('/\\s+/', ' ', $rawHtml)); }
public function testFromRenderWithFile() { $formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['file' => ['template' => 't4web-form-renderer/element/file', 'variables' => ['label' => 'File']]], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']]; $factory = new Factory(); $form = $factory->create($formConfig); $form->setMessages(['file' => ["This field is required"]]); $rawHtml = $this->renderer->render($form); $this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create"> <div class="box-body"> <div class="form-group has-error"> <label class="control-label">File</label> <input type="file" name="file" class="form-control"> <p class="help-block">This field is required</p> </div> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" id="submit-btn">Submit</button> <a class="btn btn-default" href="/admin/list">Cancel</a> </div> </form>'), preg_replace('/\\s+/', ' ', $rawHtml)); }
public function testFromRenderWithPassword() { $formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['options' => ['template' => 't4web-form-renderer/element/radio', 'variables' => ['labels' => [1 => 'Option one', 2 => 'Option two', 3 => 'Option three']]]], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']]; $factory = new Factory(); $form = $factory->create($formConfig); $form->setData(['options' => 2]); $form->setMessages(['options' => ["This field is required"]]); $rawHtml = $this->renderer->render($form); $this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create"> <div class="box-body"> <div class="form-group has-error"> <div class="radio"> <label> <input type="radio" name="options" value="1" > Option one </label> </div> <div class="radio"> <label> <input type="radio" name="options" value="2" checked=""> Option two </label> </div> <div class="radio"> <label> <input type="radio" name="options" value="3" > Option three </label> </div> <p class="help-block">This field is required</p> </div> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" id="submit-btn">Submit</button> <a class="btn btn-default" href="/admin/list">Cancel</a> </div> </form>'), preg_replace('/\\s+/', ' ', $rawHtml)); }
public function testFromRenderWithEnctype() { $this->formConfig['variables']['inputFileExists'] = true; $factory = new Factory(); $form = $factory->create($this->formConfig); $form->setData(['name' => 'Sample name', 'link' => '/bar/baz']); $rawHtml = $this->renderer->render($form); $this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create" enctype="multipart/form-data"> <div class="box-body"> <div class="form-group"> <label class="control-label">Name</label> <input type="text" name="name" placeholder="Enter name" class="form-control" value="Sample name"> </div> <div class="form-group"> <label class="control-label">Link</label> <input type="text" name="link" placeholder="Enter link" class="form-control" value="/bar/baz"> </div> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" id="submit-btn">Submit</button> <a class="btn btn-default" href="/admin/list">Cancel</a> </div> </form>'), preg_replace('/\\s+/', ' ', $rawHtml)); }