1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. |
4
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Joomla\Form\Tests; |
8
|
|
|
|
9
|
|
|
use Joomla\Form\Field_DatabaseConnection; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Test class for JFormFieldDatabaseConnection. |
13
|
|
|
* |
14
|
|
|
* @since 1.0 |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.