Completed
Pull Request — master (#28)
by Vitaliy
04:03
created

SelectTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 0
cbo 3
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testRendering() 0 11 1
A testHandleRequest() 0 12 1
1
<?php
2
3
4
  namespace Tests\Fiv\Form\Element;
5
6
7
  use Fiv\Form\Element\Select;
8
  use Fiv\Form\FormData;
9
10
  /**
11
   *
12
   */
13
  class SelectTest extends \PHPUnit_Framework_TestCase {
14
15
    /**
16
     *
17
     */
18
    public function testRendering() {
19
      $select = new Select();
20
      $select->setName('lang');
21
      $select->setOptions(['ru' => 'Russian', 'ua' => 'Ukrainian']);
22
23
      $selectHtml = $select->render();
24
      $this->assertContains('<select name="lang" ', $selectHtml);
25
      $this->assertContains('<option value="ru">Russian</option>', $selectHtml);
26
      $this->assertContains('<option value="ua">Ukrainian</option>', $selectHtml);
27
      $this->assertContains('</select>', $selectHtml);
28
    }
29
30
31
    /**
32
     *
33
     */
34
    public function testHandleRequest() {
35
      $select = new Select();
36
      $select->setName('lang');
37
      $select->setOptions(['ru' => 'Russian', 'ua' => 'Ukrainian']);
38
39
      $select->handle(new FormData('post', ['lang' => 'ru']));
40
      $this->assertEquals('ru', $select->getValue());
41
      $select->handle(new FormData('post', []));
42
      $this->assertEquals('ru', $select->getValue());
43
      $select->handle(new FormData('post', ['lang' => 'pl']));
44
      $this->assertEquals('ru', $select->getValue());
45
    }
46
  }