Completed
Pull Request — master (#636)
by Franco
22:13
created

EditableFormFieldTest::testCustomTemplates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package userforms
5
 */
6
7
class EditableFormFieldTest extends FunctionalTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
10
    public static $fixture_file = 'userforms/tests/EditableFormFieldTest.yml';
11
12
    public function testFormFieldPermissions()
13
    {
14
        $text = $this->objFromFixture('EditableTextField', 'basic-text');
15
16
        $this->logInWithPermission('ADMIN');
17
        $this->assertTrue($text->canCreate());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
18
        $this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
19
        $this->assertTrue($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
20
        $this->assertTrue($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
21
22
        $text->setReadonly(true);
23
        $this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
24
        $this->assertFalse($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
25
        $this->assertFalse($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
26
27
        $text->setReadonly(false);
28
        $this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
29
        $this->assertTrue($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
30
        $this->assertTrue($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
31
32
        $member = Member::currentUser();
33
        $member->logout();
34
35
        $this->logInWithPermission('SITETREE_VIEW_ALL');
36
        $this->assertFalse($text->canCreate());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
37
38
        $text->setReadonly(false);
39
        $this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
40
        $this->assertFalse($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
41
        $this->assertFalse($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
42
43
        $text->setReadonly(true);
44
        $this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

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...
45
        $this->assertFalse($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
46
        $this->assertFalse($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
47
    }
48
49
    public function testCustomRules()
50
    {
51
        $this->logInWithPermission('ADMIN');
52
        $form = $this->objFromFixture('UserDefinedForm', 'custom-rules-form');
53
54
        $checkbox = $form->Fields()->find('ClassName', 'EditableCheckbox');
0 ignored issues
show
Bug introduced by
The method Fields() does not exist on DataObject. Did you maybe mean beforeUpdateCMSFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
55
        $field = $form->Fields()->find('ClassName', 'EditableTextField');
0 ignored issues
show
Bug introduced by
The method Fields() does not exist on DataObject. Did you maybe mean beforeUpdateCMSFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
56
57
        $rules = $checkbox->DisplayRules();
58
59
        // form has 2 fields - a checkbox and a text field
60
        // it has 1 rule - when ticked the checkbox hides the text field
61
        $this->assertEquals(1, $rules->Count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
62
        $this->assertEquals($rules, $checkbox->EffectiveDisplayRules());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
63
64
        $checkboxRule = $rules->First();
65
        $checkboxRule->ConditionFieldID = $field->ID;
66
67
        $this->assertEquals($checkboxRule->Display, 'Hide');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
68
        $this->assertEquals($checkboxRule->ConditionOption, 'HasValue');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
69
        $this->assertEquals($checkboxRule->FieldValue, '6');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
70
71
        // If field is required then all custom rules are disabled
72
        $checkbox->Required = true;
73
        $this->assertEquals(0, $checkbox->EffectiveDisplayRules()->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
74
    }
75
76
    /**
77
     * @covers EditableOption::getValue
78
     */
79
    public function testEditableOptionEmptyValue()
80
    {
81
        $option = $this->objFromFixture('EditableOption', 'option-1');
82
        $option->Value = '';
83
84
         // Disallow empty values
85
         EditableOption::set_allow_empty_values(false);
86
        $this->assertEquals($option->Title, $option->Value);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
87
88
        $option->Value = 'test';
89
        $this->assertEquals('test', $option->Value);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
90
91
         // Allow empty values
92
         EditableOption::set_allow_empty_values(true);
93
        $option->Value = '';
94
        $this->assertEquals('', $option->Value);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
95
    }
96
97 View Code Duplication
    public function testEditableDropdownField()
0 ignored issues
show
Duplication introduced by
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...
98
    {
99
        $dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
100
101
        $field = $dropdown->getFormField();
102
103
104
        $this->assertThat($field, $this->isInstanceOf('DropdownField'));
0 ignored issues
show
Bug introduced by
The method isInstanceOf() does not seem to exist on object<EditableFormFieldTest>.

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...
Bug introduced by
The method assertThat() does not seem to exist on object<EditableFormFieldTest>.

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...
105
        $values = $field->getSource();
106
107
        $this->assertEquals(array('Option 1' => 'Option 1', 'Option 2' => 'Option 2'), $values);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
108
    }
109
110 View Code Duplication
    public function testEditableRadioField()
0 ignored issues
show
Duplication introduced by
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...
111
    {
112
        $radio = $this->objFromFixture('EditableRadioField', 'radio-field');
113
114
        $field = $radio->getFormField();
115
116
        $this->assertThat($field, $this->isInstanceOf('OptionsetField'));
0 ignored issues
show
Bug introduced by
The method isInstanceOf() does not seem to exist on object<EditableFormFieldTest>.

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...
Bug introduced by
The method assertThat() does not seem to exist on object<EditableFormFieldTest>.

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...
117
        $values = $field->getSource();
118
119
        $this->assertEquals(array('Option 5' => 'Option 5', 'Option 6' => 'Option 6'), $values);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
120
    }
121
122
    public function testMultipleOptionDuplication()
123
    {
124
        $dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
125
126
        $clone = $dropdown->duplicate();
127
128
        $this->assertEquals($clone->Options()->Count(), $dropdown->Options()->Count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
129
130
        foreach ($clone->Options() as $option) {
131
            $orginal = $dropdown->Options()->find('Title', $option->Title);
132
133
            $this->assertEquals($orginal->Sort, $option->Sort);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
134
        }
135
    }
136
137
    public function testFileField()
138
    {
139
        $fileField = $this->objFromFixture('EditableFileField', 'file-field');
140
        $formField = $fileField->getFormField();
141
142
        $this->assertContains('jpg', $formField->getValidator()->getAllowedExtensions());
143
        $this->assertNotContains('notallowedextension', $formField->getValidator()->getAllowedExtensions());
144
    }
145
146
    public function testFileFieldAllowedExtensionsBlacklist()
147
    {
148
        Config::inst()->update('EditableFileField', 'allowed_extensions_blacklist', array('jpg'));
149
        $fileField = $this->objFromFixture('EditableFileField', 'file-field');
150
        $formField = $fileField->getFormField();
151
152
        $this->assertNotContains('jpg', $formField->getValidator()->getAllowedExtensions());
153
    }
154
155
    /**
156
     * Verify that unique names are automatically generated for each formfield
157
     */
158
    public function testUniqueName()
159
    {
160
        $textfield1 = new EditableTextField();
161
        $this->assertEmpty($textfield1->Name);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<EditableFormFieldTest>.

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...
162
163
        // Write values
164
        $textfield1->write();
165
        $textfield2 = new EditableTextField();
166
        $textfield2->write();
167
        $checkboxField = new EditableCheckbox();
168
        $checkboxField->write();
169
170
        // Test values are in the expected format
171
        $this->assertRegExp('/^EditableTextField_.+/', $textfield1->Name);
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<EditableFormFieldTest>.

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...
172
        $this->assertRegExp('/^EditableTextField_.+/', $textfield2->Name);
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<EditableFormFieldTest>.

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...
173
        $this->assertRegExp('/^EditableCheckbox_.+/', $checkboxField->Name);
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<EditableFormFieldTest>.

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...
174
        $this->assertNotEquals($textfield1->Name, $textfield2->Name);
0 ignored issues
show
Bug introduced by
The method assertNotEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
175
    }
176
177
    public function testLengthRange()
178
    {
179
        /** @var EditableTextField $textField */
180
        $textField = $this->objFromFixture('EditableTextField', 'basic-text');
181
182
        // Empty range
183
        /** @var TextField $formField */
184
        $textField->MinLength = 0;
0 ignored issues
show
Documentation introduced by
The property MinLength does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
185
        $textField->MaxLength = 0;
0 ignored issues
show
Documentation introduced by
The property MaxLength does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
186
        $attributes = $textField->getFormField()->getAttributes();
187
        $this->assertFalse(isset($attributes['maxLength']));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
188
        $this->assertFalse(isset($attributes['data-rule-minlength']));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
189
        $this->assertFalse(isset($attributes['data-rule-maxlength']));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
190
191
        // Test valid range
192
        $textField->MinLength = 10;
0 ignored issues
show
Documentation introduced by
The property MinLength does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
193
        $textField->MaxLength = 20;
0 ignored issues
show
Documentation introduced by
The property MaxLength does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
194
        $attributes = $textField->getFormField()->getAttributes();
195
        $this->assertEquals(20, $attributes['maxLength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
196
        $this->assertEquals(20, $attributes['size']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
197
        $this->assertEquals(10, $attributes['data-rule-minlength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
198
        $this->assertEquals(20, $attributes['data-rule-maxlength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
199
200
        // textarea
201
        $textField->Rows = 3;
0 ignored issues
show
Documentation introduced by
The property Rows does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
202
        $attributes = $textField->getFormField()->getAttributes();
203
        $this->assertFalse(isset($attributes['maxLength']));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

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...
204
        $this->assertEquals(10, $attributes['data-rule-minlength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
205
        $this->assertEquals(20, $attributes['data-rule-maxlength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
206
    }
207
208
    public function testFormatDisplayRules()
209
    {
210
        $field = $this->objFromFixture('EditableFormField', 'irdNumberField');
211
        $displayRules = $field->formatDisplayRules();
212
        $this->assertNotNull($displayRules);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<EditableFormFieldTest>.

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...
213
        $this->assertCount(1, $displayRules['operations']);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<EditableFormFieldTest>.

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...
214
215
        // Field is initially visible, so the "view" method should be to hide it
216
        $this->assertSame('addClass("hide")', $displayRules['view']);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<EditableFormFieldTest>.

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...
217
        // The opposite method should be to return it to its original state, i.e. show it again
218
        $this->assertSame('removeClass("hide")', $displayRules['opposite']);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<EditableFormFieldTest>.

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...
219
    }
220
221
    /**
222
     * Tests that certain elements are rendered with custom templates
223
     */
224
    public function testCustomTemplates()
225
    {
226
        $radio = $this->objFromFixture('EditableRadioField', 'radio-field');
227
        $this->assertEquals('UserFormsOptionSetField', $radio->getFormField()->getTemplate());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
228
229
        $checkboxGroup = $this->objFromFixture('EditableCheckboxGroupField', 'checkbox-group');
230
        $this->assertEquals('UserFormsCheckboxSetField', $checkboxGroup->getFormField()->getTemplate());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

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...
231
    }
232
}
233