'{{text}}', ]; $this->templates = new StringTemplate($templates); $this->context = new NullContext([]); } /** * Test render in a simple case. */ public function testRenderSimple(): void { $button = new ButtonWidget($this->templates); $result = $button->render(['name' => 'my_input'], $this->context); $expected = [ 'button' => ['type' => 'submit', 'name' => 'my_input'], '/button', ]; $this->assertHtml($expected, $result); } /** * Test render with custom type */ public function testRenderType(): void { $button = new ButtonWidget($this->templates); $data = [ 'name' => 'my_input', 'type' => 'button', 'text' => 'Some button', ]; $result = $button->render($data, $this->context); $expected = [ 'button' => ['type' => 'button', 'name' => 'my_input'], 'Some button', '/button', ]; $this->assertHtml($expected, $result); } /** * Test render with a text */ public function testRenderWithText(): void { $button = new ButtonWidget($this->templates); $data = [ 'text' => 'Some ', 'onclick' => '', ]; $result = $button->render($data, $this->context); $expected = [ 'button' => ['type' => 'submit', 'onclick' => '<escape me>'], 'Some <value>', '/button', ]; $this->assertHtml($expected, $result); $data['escapeTitle'] = false; $result = $button->render($data, $this->context); $expected = [ 'button' => ['type' => 'submit', 'onclick' => '<escape me>'], 'Some ', '/button', ]; $this->assertHtml($expected, $result); } /** * Test render with additional attributes. */ public function testRenderAttributes(): void { $button = new ButtonWidget($this->templates); $data = [ 'name' => 'my_input', 'text' => 'Go', 'class' => 'btn', 'required' => true, ]; $result = $button->render($data, $this->context); $expected = [ 'button' => [ 'type' => 'submit', 'name' => 'my_input', 'class' => 'btn', 'required' => 'required', ], 'Go', '/button', ]; $this->assertHtml($expected, $result); } /** * Ensure templateVars option is hooked up. */ public function testRenderTemplateVars(): void { $this->templates->add([ 'button' => '', ]); $button = new ButtonWidget($this->templates); $data = [ 'templateVars' => ['custom' => 'value'], 'text' => 'Go', ]; $result = $button->render($data, $this->context); $expected = [ 'button' => [ 'type' => 'submit', 'custom' => 'value', ], 'Go', '/button', ]; $this->assertHtml($expected, $result); } }