@@ 16-89 (lines=74) @@ | ||
13 | * |
|
14 | * @since 1.0 |
|
15 | */ |
|
16 | class JFormFieldDatabaseConnectionTest extends \PHPUnit_Framework_TestCase |
|
17 | { |
|
18 | /** |
|
19 | * Sets up dependencies for the test. |
|
20 | * |
|
21 | * @return void |
|
22 | * |
|
23 | * @since 1.0 |
|
24 | */ |
|
25 | protected function setUp() |
|
26 | { |
|
27 | // The real class cannot be autoloaded |
|
28 | \Joomla\Form\FormHelper::loadFieldClass('databaseConnection'); |
|
29 | ||
30 | parent::setUp(); |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Test the getInput method. |
|
35 | * |
|
36 | * @return void |
|
37 | * |
|
38 | * @since 1.0 |
|
39 | */ |
|
40 | public function testGetInput() |
|
41 | { |
|
42 | $form = new JFormInspector('form1'); |
|
43 | ||
44 | $this->assertThat( |
|
45 | $form->load('<form><field name="databaseconnection" type="databaseconnection" supported="mysqli" /></form>'), |
|
46 | $this->isTrue(), |
|
47 | 'Line:' . __LINE__ . ' XML string should load successfully.' |
|
48 | ); |
|
49 | ||
50 | /** @var Field_DatabaseConnection $field */ |
|
51 | $field = \Joomla\Form\FormHelper::loadFieldType('databaseConnection'); |
|
52 | $field->setForm($form); |
|
53 | ||
54 | $this->assertThat( |
|
55 | $field->setup($form->getXml()->field, 'value'), |
|
56 | $this->isTrue(), |
|
57 | 'Line:' . __LINE__ . ' The setup method should return true.' |
|
58 | ); |
|
59 | ||
60 | $this->assertThat( |
|
61 | strlen($field->input), |
|
62 | $this->greaterThan(0), |
|
63 | 'Line:' . __LINE__ . ' The getInput method should return something without error; in this case, a "Mysqli" option.' |
|
64 | ); |
|
65 | ||
66 | $this->assertThat( |
|
67 | $form->load('<form><field name="databaseconnection" type="databaseconnection" supported="non-existing" /></form>'), |
|
68 | $this->isTrue(), |
|
69 | 'Line:' . __LINE__ . ' XML string should load successfully.' |
|
70 | ); |
|
71 | ||
72 | $field = \Joomla\Form\FormHelper::loadFieldType('databaseConnection'); |
|
73 | $field->setForm($form); |
|
74 | ||
75 | $this->assertThat( |
|
76 | $field->setup($form->getXml()->field, 'value'), |
|
77 | $this->isTrue(), |
|
78 | 'Line:' . __LINE__ . ' The setup method should return true.' |
|
79 | ); |
|
80 | ||
81 | $this->assertThat( |
|
82 | strlen($field->input), |
|
83 | $this->greaterThan(0), |
|
84 | 'Line:' . __LINE__ . ' The getInput method should return something without error; in this case, a "None" option.' |
|
85 | ); |
|
86 | ||
87 | // TODO: Should check all the attributes have come in properly. |
|
88 | } |
|
89 | } |
|
90 |
@@ 17-101 (lines=85) @@ | ||
14 | * |
|
15 | * @since 1.0 |
|
16 | */ |
|
17 | class JFormFieldRadioTest extends \PHPUnit_Framework_TestCase |
|
18 | { |
|
19 | /** |
|
20 | * Sets up dependancies for the test. |
|
21 | * |
|
22 | * @return void |
|
23 | */ |
|
24 | protected function setUp() |
|
25 | { |
|
26 | // The real class cannot be autoloaded |
|
27 | \Joomla\Form\FormHelper::loadFieldClass('radio'); |
|
28 | ||
29 | parent::setUp(); |
|
30 | } |
|
31 | ||
32 | /** |
|
33 | * Test the getInput method. |
|
34 | * |
|
35 | * @return void |
|
36 | */ |
|
37 | public function testGetInput() |
|
38 | { |
|
39 | $form = new JFormInspector('form1'); |
|
40 | ||
41 | $this->assertThat( |
|
42 | $form->load('<form><field name="radio" type="radio" /></form>'), |
|
43 | $this->isTrue(), |
|
44 | 'Line:' . __LINE__ . ' XML string should load successfully.' |
|
45 | ); |
|
46 | ||
47 | /** @var Field_Radio $field */ |
|
48 | $field = \Joomla\Form\FormHelper::loadFieldType('radio'); |
|
49 | $field->setForm($form); |
|
50 | ||
51 | $this->assertThat( |
|
52 | $field->setup($form->getXml()->field, 'value'), |
|
53 | $this->isTrue(), |
|
54 | 'Line:' . __LINE__ . ' The setup method should return true.' |
|
55 | ); |
|
56 | ||
57 | $this->assertThat( |
|
58 | strlen($field->input), |
|
59 | $this->greaterThan(0), |
|
60 | 'Line:' . __LINE__ . ' The getInput method should return something without error.' |
|
61 | ); |
|
62 | ||
63 | // TODO: Should check all the attributes have come in properly. |
|
64 | } |
|
65 | ||
66 | /** |
|
67 | * Test the getOptions method. |
|
68 | * |
|
69 | * @return void |
|
70 | * |
|
71 | * @since 1.0 |
|
72 | */ |
|
73 | public function testGetOptions() |
|
74 | { |
|
75 | $form = new JFormInspector('form1'); |
|
76 | ||
77 | $this->assertThat( |
|
78 | $form->load('<form><field name="radio" type="radio"><option value="0">No</option><item value="1">Yes</item></field></form>'), |
|
79 | $this->isTrue(), |
|
80 | 'Line:' . __LINE__ . ' XML string should load successfully.' |
|
81 | ); |
|
82 | ||
83 | /** @var Field_Radio $field */ |
|
84 | $field = \Joomla\Form\FormHelper::loadFieldType('radio'); |
|
85 | $field->setForm($form); |
|
86 | ||
87 | $this->assertThat( |
|
88 | $field->setup($form->getXml()->field, 'value'), |
|
89 | $this->isTrue(), |
|
90 | 'Line:' . __LINE__ . ' The setup method should return true.' |
|
91 | ); |
|
92 | ||
93 | $this->assertThat( |
|
94 | strlen($field->input), |
|
95 | $this->logicalNot( |
|
96 | $this->StringContains('Yes') |
|
97 | ), |
|
98 | 'Line:' . __LINE__ . ' The field should not contain a Yes option.' |
|
99 | ); |
|
100 | } |
|
101 | } |
|
102 |