This repository was archived by the owner on May 16, 2020. It is now read-only.
forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParserPluginTest.php
More file actions
107 lines (80 loc) · 2.63 KB
/
Copy pathParserPluginTest.php
File metadata and controls
107 lines (80 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
class ParserPluginTest extends \CIUnitTestCase
{
/**
* @var \CodeIgniter\View\Parser
*/
protected $parser;
/**
* @var \CodeIgniter\Validation\Validation
*/
protected $validator;
protected function setUp()
{
parent::setUp();
\Config\Services::reset(true);
$this->parser = \Config\Services::parser();
$this->validator = \Config\Services::validation();
}
public function testCurrentURL()
{
helper('url');
$template = '{+ current_url +}';
$this->assertEquals(current_url(), $this->parser->renderString($template));
}
public function testPreviousURL()
{
helper('url');
$template = '{+ previous_url +}';
// Ensure a previous URL exists to work with.
$_SESSION['_ci_previous_url'] = 'http://example.com/foo';
$this->assertEquals(previous_url(), $this->parser->renderString($template));
}
public function testMailto()
{
helper('url');
$template = '{+ mailto email=foo@example.com title=Silly +}';
$this->assertEquals(mailto('foo@example.com', 'Silly'), $this->parser->renderString($template));
}
public function testSafeMailto()
{
helper('url');
$template = '{+ safe_mailto email=foo@example.com title=Silly +}';
$this->assertEquals(safe_mailto('foo@example.com', 'Silly'), $this->parser->renderString($template));
}
public function testLang()
{
$template = '{+ lang Number.terabyteAbbr +}';
$this->assertEquals('TB', $this->parser->renderString($template));
}
public function testValidationErrors()
{
$this->validator->setError('email', 'Invalid email address');
$template = '{+ validation_errors field=email +}';
$this->assertEquals($this->setHints($this->validator->showError('email')), $this->setHints($this->parser->renderString($template)));
}
public function testRoute()
{
// prime the pump
$routes = service('routes');
$routes->add('path/(:any)/to/(:num)', 'myController::goto/$1/$2');
$template = '{+ route myController::goto string 13 +}';
$this->assertEquals('/path/string/to/13', $this->parser->renderString($template));
}
public function testSiteURL()
{
$template = '{+ siteURL +}';
$this->assertEquals('http://example.com/index.php', $this->parser->renderString($template));
}
public function testValidationErrorsList()
{
$this->validator->setError('email', 'Invalid email address');
$this->validator->setError('username', 'User name must be unique');
$template = '{+ validation_errors +}';
$this->assertEquals($this->setHints($this->validator->listErrors()), $this->setHints($this->parser->renderString($template)));
}
public function setHints($output)
{
return preg_replace('/(<!-- DEBUG-VIEW+) (\w+) (\d+)/', '${1}', $output);
}
}