Completed
Push — master ( 250c3f...5d0c73 )
by Shcherbak
15:55
created

HiddenTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getElement() 0 4 1
A testRender() 0 5 1
A testAttributes() 0 23 2
A testValueWithSlashes() 0 14 1
1
<?php
2
3
  namespace Tests\Form\Form;
4
5
  use Fiv\Form\Element\Input;
6
  use Fiv\Form\Filter\Trim;
7
  use Fiv\Form\Form;
8
9
  /**
10
   * @package Tests\Form\Form
11
   */
12
  class HiddenTest extends \Tests\Form\MainTestCase {
13
14
    /**
15
     * @return \Fiv\Form\Element\Input
16
     */
17
    protected function getElement() {
18
      $form = new Form();
19
      return $form->hidden("test");
20
    }
21
22
23
    public function testRender() {
24
      $element = $this->getElement();
25
26
      $this->assertContains("hidden", (string) $element);
27
    }
28
29
30
    public function testAttributes() {
31
32
      $element = $this->getElement();
33
34
      $this->assertEquals('test', $element->getName());
35
      $this->assertEmpty($element->getClass());
36
37
      $element->setClass("hidden_class");
38
      $this->assertEquals("hidden_class", $element->getClass());
39
40
      $element->setAttribute('data-id', 'custom-id');
41
      $this->assertEquals('custom-id', $element->getAttribute('data-id'));
42
43
      $element->removeAttribute('data-id');
44
      $this->assertEquals(null, $element->getAttribute('data-id'));
45
46
      $error = null;
47
      try {
48
        $element->sendItem();
0 ignored issues
show
Documentation Bug introduced by
The method sendItem does not exist on object<Fiv\Form\Element\Input>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
      } catch (\Exception $error) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
50
      }
51
      $this->assertInstanceOf('Exception', $error);
52
    }
53
54
55
    public function testValueWithSlashes() {
56
57
      $input = new Input();
58
      $input->setName('test');
59
      $input->setType('hidden');
60
      $value = ' 123"234 \' 44 ';
61
62
      $input->addFilter(new Trim());
63
64
      $input->setValue($value);
65
66
      $this->assertContains('<input type="hidden" name="test" value="123&quot;234 &#039; 44"', $input->render());
67
68
    }
69
70
  }