These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @package spamprotection |
||
5 | */ |
||
6 | class FormSpamProtectionExtensionTest extends SapphireTest |
||
7 | { |
||
8 | protected $usesDatabase = false; |
||
9 | |||
10 | /** |
||
11 | * @var Form |
||
12 | */ |
||
13 | protected $form = null; |
||
14 | |||
15 | public function setUp() |
||
16 | { |
||
17 | parent::setUp(); |
||
18 | |||
19 | $this->form = new Form($this, 'Form', new FieldList( |
||
20 | new TextField('Title'), |
||
21 | new TextField('Comment'), |
||
22 | new TextField('URL') |
||
23 | ), new FieldList() |
||
24 | ); |
||
25 | $this->form->disableSecurityToken(); |
||
26 | } |
||
27 | |||
28 | public function testEnableSpamProtection() |
||
29 | { |
||
30 | Config::inst()->update( |
||
31 | 'FormSpamProtectionExtension', 'default_spam_protector', |
||
32 | 'FormSpamProtectionExtensionTest_FooProtector' |
||
33 | ); |
||
34 | |||
35 | $form = $this->form->enableSpamProtection(); |
||
36 | |||
37 | $this->assertEquals('Foo', $form->Fields()->fieldByName('Captcha')->Title()); |
||
38 | } |
||
39 | |||
40 | public function testEnableSpamProtectionCustomProtector() |
||
41 | { |
||
42 | $form = $this->form->enableSpamProtection(array( |
||
43 | 'protector' => 'FormSpamProtectionExtensionTest_BarProtector' |
||
44 | )); |
||
45 | |||
46 | $this->assertEquals('Bar', $form->Fields()->fieldByName('Captcha')->Title()); |
||
47 | } |
||
48 | |||
49 | View Code Duplication | public function testEnableSpamProtectionCustomTitle() |
|
0 ignored issues
–
show
|
|||
50 | { |
||
51 | $form = $this->form->enableSpamProtection(array( |
||
52 | 'protector' => 'FormSpamProtectionExtensionTest_BarProtector', |
||
53 | 'title' => 'Baz', |
||
54 | )); |
||
55 | |||
56 | $this->assertEquals('Baz', $form->Fields()->fieldByName('Captcha')->Title()); |
||
57 | } |
||
58 | |||
59 | View Code Duplication | public function testCustomOptions() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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.
Loading history...
|
|||
60 | { |
||
61 | $form = $this->form->enableSpamProtection(array( |
||
62 | 'protector' => 'FormSpamProtectionExtensionTest_BazProtector', |
||
63 | 'title' => 'Qux', |
||
64 | 'name' => 'Borris' |
||
65 | )); |
||
66 | |||
67 | $this->assertEquals('Qux', $form->Fields()->fieldByName('Borris')->Title()); |
||
68 | } |
||
69 | |||
70 | View Code Duplication | public function testInsertBefore() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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.
Loading history...
|
|||
71 | { |
||
72 | $form = $this->form->enableSpamProtection(array( |
||
73 | 'protector' => 'FormSpamProtectionExtensionTest_FooProtector', |
||
74 | 'insertBefore' => 'URL' |
||
75 | )); |
||
76 | |||
77 | $fields = $form->Fields(); |
||
78 | $this->assertEquals('Title', $fields[0]->Title()); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<FormSpamProtectionExtensionTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
79 | $this->assertEquals('Comment', $fields[1]->Title()); |
||
80 | $this->assertEquals('Foo', $fields[2]->Title()); |
||
81 | $this->assertEquals('URL', $fields[3]->Title()); |
||
82 | } |
||
83 | |||
84 | View Code Duplication | public function testInsertBeforeMissing() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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.
Loading history...
|
|||
85 | { |
||
86 | $form = $this->form->enableSpamProtection(array( |
||
87 | 'protector' => 'FormSpamProtectionExtensionTest_FooProtector', |
||
88 | 'insertBefore' => 'NotAField' |
||
89 | )); |
||
90 | |||
91 | // field should default to the end instead |
||
92 | $fields = $form->Fields(); |
||
93 | $this->assertEquals('Title', $fields[0]->Title()); |
||
94 | $this->assertEquals('Comment', $fields[1]->Title()); |
||
95 | $this->assertEquals('URL', $fields[2]->Title()); |
||
96 | $this->assertEquals('Foo', $fields[3]->Title()); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @package spamprotection |
||
102 | */ |
||
103 | View Code Duplication | class FormSpamProtectionExtensionTest_BazProtector implements SpamProtector, TestOnly |
|
104 | { |
||
105 | public function getFormField($name = null, $title = null, $value = null) |
||
106 | { |
||
107 | return new TextField($name, $title, $value); |
||
108 | } |
||
109 | |||
110 | public function setFieldMapping($fieldMapping) |
||
111 | { |
||
112 | } |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @package spamprotection |
||
117 | */ |
||
118 | View Code Duplication | class FormSpamProtectionExtensionTest_BarProtector implements SpamProtector, TestOnly |
|
119 | { |
||
120 | public function getFormField($name = null, $title = null, $value = null) |
||
121 | { |
||
122 | $title = $title ?: 'Bar'; |
||
123 | return new TextField($name, $title, $value); |
||
124 | } |
||
125 | |||
126 | public function setFieldMapping($fieldMapping) |
||
127 | { |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @package spamprotection |
||
133 | */ |
||
134 | View Code Duplication | class FormSpamProtectionExtensionTest_FooProtector implements SpamProtector, TestOnly |
|
135 | { |
||
136 | public function getFormField($name = null, $title = null, $value = null) |
||
137 | { |
||
138 | return new TextField($name, 'Foo', $value); |
||
139 | } |
||
140 | |||
141 | public function setFieldMapping($fieldMapping) |
||
142 | { |
||
143 | } |
||
144 | } |
||
145 |
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.