Completed
Branch master (5105da)
by Stefano
02:21
created

ViewTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 84
rs 10
c 1
b 0
f 0
1
<?php
2
3
class ViewTest extends PHPUnit_Framework_TestCase {
4
5
  public function __construct(){
6
    // Build some templates
7
    $TEMPLATE_DIR = sys_get_temp_dir();
8
    @mkdir("$TEMPLATE_DIR/special");
9
10
    file_put_contents("$TEMPLATE_DIR/special/hello.php",<<<'EOT'
11
Hello, <?= $this->name ?>!
12
EOT
13
    );
14
15
    file_put_contents("$TEMPLATE_DIR/test.php",<<<'EOT'
16
TESTIFICATE
17
EOT
18
    );
19
20
    file_put_contents("$TEMPLATE_DIR/global.php",<<<'EOT'
21
<?=$this->THE_DARKNESS?>
22
EOT
23
    );
24
25
    file_put_contents("$TEMPLATE_DIR/test_var.php",<<<'EOT'
26
<?=$this->var?>
27
EOT
28
    );
29
30
    file_put_contents("$TEMPLATE_DIR/index_pass.php",<<<'EOT'
31
[<?= $this->partial('special/hello') ?>]
32
EOT
33
    );
34
35
    file_put_contents("$TEMPLATE_DIR/index_override.php",<<<'EOT'
36
[<?= $this->partial('special/hello',['name'=>'Daryl']) ?>]
37
EOT
38
    );
39
40
    // Init View handler
41
    View::using(new View\PHP($TEMPLATE_DIR));
42
  }
43
44
  public function testRender(){
45
    $results = (string)View::from('test');
46
    $this->assertEquals('TESTIFICATE', $results);
47
  }
48
49
  public function testRenderWithParameters(){
50
    $results = (string)View::from('test_var')->with(['var'=>1]);
51
    $this->assertEquals('1', $results);
52
  }
53
54
  public function testRenderWithParametersShorthand(){
55
    $results = (string)View::from('test_var')->with(['var'=>1]);
56
    $this->assertEquals('1', $results);
57
  }
58
59
  public function testGlobalParameters(){
60
    View::addGlobal('THE_DARKNESS','Jakie');
61
    $results = (string)View::from('global');
62
    $this->assertEquals('Jakie', $results);
63
  }
64
65
  public function testPHPViewSimpleRenderWithVariables(){
66
    $results = (string)View::from('special/hello',    ['name'=>'Rick']);
67
    $this->assertEquals('Hello, Rick!', $results);
68
  }
69
70
  public function testPHPViewPartialsRenderWithVariables(){
71
    $results = (string)View::from('index_pass',       ['name'=>'Rick']);
72
    $this->assertEquals('[Hello, Rick!]', $results);
73
  }
74
75
  public function testPHPViewPartialsOverridingVariables(){
76
    $results = (string)View::from('index_override',   ['name'=>'Rick']);
77
    $this->assertEquals('[Hello, Daryl!]', $results);
78
  }
79
80
  public function testTemplateExists(){
81
    $this->assertTrue(View::exists('special/hello'));
82
    $this->assertFalse(View::exists('im/fake/template'));
83
  }
84
85
86
}
87
88