Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
tao_helpers_form_elements_xhtml_Button
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
4 / 4
7
100.00% covered (success)
100.00%
1 / 1
 setIcon
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 setType
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 setTestId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung
19 *                         (under the project TAO-TRANSFER);
20 *               2009-2012 (update and modification) Public Research Centre Henri Tudor
21 *                         (under the project TAO-SUSTAIN & TAO-DEV);
22 *
23 */
24
25use oat\tao\helpers\form\elements\xhtml\XhtmlRenderingTrait;
26
27/**
28 * Short description of class tao_helpers_form_elements_xhtml_Button
29 *
30 * @access public
31 * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
32 * @package tao
33 */
34class tao_helpers_form_elements_xhtml_Button extends tao_helpers_form_elements_Button
35{
36    use XhtmlRenderingTrait;
37
38    /**
39     *
40     * @var string
41     */
42    protected $icon = '';
43
44    /**
45     *
46     * @var string
47     */
48    protected $type = 'button';
49
50    /**
51     *
52     * @var string
53     */
54    protected $iconPosition = '';
55
56    public function setIcon($icon, $position = 'before')
57    {
58        $this->icon = '<span class="' . $icon . '"></span>';
59        $this->iconPosition = $position;
60    }
61
62    /**
63     * Short description of method render
64     *
65     * @access public
66     * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
67     * @return string
68     */
69    public function render()
70    {
71        $returnValue = $this->renderLabel();
72
73        $content = _dh($this->value);
74
75        if ($this->icon) {
76            $content = $this->iconPosition === 'before' ? $this->icon . ' ' . $content : $content . ' ' . $this->icon;
77        }
78
79        $returnValue .= "<button type='{$this->type}' name='{$this->name}' id='{$this->name}";
80        $returnValue .= $this->renderAttributes();
81        $returnValue .= ' value="' . _dh($this->value) . '">' . $content . '</button>';
82
83        return $returnValue;
84    }
85
86    /**
87     * Sets allowed by html5 buttons type
88     *
89     * @param string $type
90     */
91    public function setType($type)
92    {
93        if (
94            in_array(strtolower($type), [
95            'button',
96            'submit',
97            'reset'])
98        ) {
99            $this->type = $type;
100        }
101    }
102
103    /**
104     * Sets data-testid attribute
105     *
106     * @param string $testId
107     */
108    public function setTestId($testId)
109    {
110        $this->setAttribute('data-testid', $testId);
111    }
112}