Skip to content

Commit 1ba4a5e

Browse files
committed
Reformat Test files
1 parent 1202edb commit 1ba4a5e

File tree

2 files changed

+163
-163
lines changed

2 files changed

+163
-163
lines changed

tests/libraries/TwigHelperTest.php

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
11
<?php
22

3-
require __DIR__.'/../../libraries/Twig.php';
3+
require __DIR__ . '/../../libraries/Twig.php';
44

55
class TwigHelperTest extends PHPUnit_Framework_TestCase
66
{
7-
public static function setUpBeforeClass()
8-
{
9-
parent::setUpBeforeClass();
10-
$CI =& get_instance();
11-
$CI->load->helper('url');
12-
}
7+
public static function setUpBeforeClass()
8+
{
9+
parent::setUpBeforeClass();
10+
$CI =& get_instance();
11+
$CI->load->helper('url');
12+
}
1313

14-
public function setUp()
15-
{
16-
$twig = new Twig();
14+
public function setUp()
15+
{
16+
$twig = new Twig();
1717

18-
$loader = new Twig_Loader_Array([
19-
'base_url' => '{{ base_url(\'"><s>abc</s><a name="test\') }}',
20-
'site_url' => '{{ site_url(\'"><s>abc</s><a name="test\') }}',
21-
'anchor' => '{{ anchor(uri, title, attributes) }}',
22-
]);
23-
$setLoader = ReflectionHelper::getPrivateMethodInvoker(
24-
$twig, 'setLoader'
25-
);
26-
$setLoader($loader);
18+
$loader = new Twig_Loader_Array([
19+
'base_url' => '{{ base_url(\'"><s>abc</s><a name="test\') }}',
20+
'site_url' => '{{ site_url(\'"><s>abc</s><a name="test\') }}',
21+
'anchor' => '{{ anchor(uri, title, attributes) }}',
22+
]);
23+
$setLoader = ReflectionHelper::getPrivateMethodInvoker(
24+
$twig, 'setLoader'
25+
);
26+
$setLoader($loader);
2727

28-
$resetTwig = ReflectionHelper::getPrivateMethodInvoker(
29-
$twig, 'resetTwig'
30-
);
31-
$resetTwig();
28+
$resetTwig = ReflectionHelper::getPrivateMethodInvoker(
29+
$twig, 'resetTwig'
30+
);
31+
$resetTwig();
3232

33-
$addFunctions = ReflectionHelper::getPrivateMethodInvoker(
34-
$twig, 'addFunctions'
35-
);
36-
$addFunctions();
33+
$addFunctions = ReflectionHelper::getPrivateMethodInvoker(
34+
$twig, 'addFunctions'
35+
);
36+
$addFunctions();
3737

38-
$this->obj = $twig;
39-
$this->twig = $twig->getTwig();
40-
}
38+
$this->obj = $twig;
39+
$this->twig = $twig->getTwig();
40+
}
4141

42-
public function test_anchor()
43-
{
44-
$actual = $this->twig->render(
45-
'anchor',
46-
[
47-
'uri' => 'news/local/123',
48-
'title' => 'My News',
49-
'attributes' => ['title' => 'The best news!']
50-
]
51-
);
52-
$expected = '<a href="http://localhost/index.php/news/local/123" title="The best news!">My News</a>';
53-
$this->assertEquals($expected, $actual);
42+
public function test_anchor()
43+
{
44+
$actual = $this->twig->render(
45+
'anchor',
46+
[
47+
'uri' => 'news/local/123',
48+
'title' => 'My News',
49+
'attributes' => ['title' => 'The best news!']
50+
]
51+
);
52+
$expected = '<a href="http://localhost/index.php/news/local/123" title="The best news!">My News</a>';
53+
$this->assertEquals($expected, $actual);
5454

55-
$actual = $this->twig->render(
56-
'anchor',
57-
[
58-
'uri' => 'news/local/123',
59-
'title' => '<s>abc</s>',
60-
'attributes' => ['<s>name</s>' => '<s>val</s>']
61-
]
62-
);
63-
$expected = '<a href="http://localhost/index.php/news/local/123" &lt;s&gt;name&lt;/s&gt;="&lt;s&gt;val&lt;/s&gt;">&lt;s&gt;abc&lt;/s&gt;</a>';
64-
$this->assertEquals($expected, $actual);
65-
}
55+
$actual = $this->twig->render(
56+
'anchor',
57+
[
58+
'uri' => 'news/local/123',
59+
'title' => '<s>abc</s>',
60+
'attributes' => ['<s>name</s>' => '<s>val</s>']
61+
]
62+
);
63+
$expected = '<a href="http://localhost/index.php/news/local/123" &lt;s&gt;name&lt;/s&gt;="&lt;s&gt;val&lt;/s&gt;">&lt;s&gt;abc&lt;/s&gt;</a>';
64+
$this->assertEquals($expected, $actual);
65+
}
6666

67-
public function test_base_url()
68-
{
69-
$actual = $this->twig->render('base_url');
70-
$expected = 'http://localhost/&quot;&gt;&lt;s&gt;abc&lt;/s&gt;&lt;a name=&quot;test';
71-
$this->assertEquals($expected, $actual);
72-
}
67+
public function test_base_url()
68+
{
69+
$actual = $this->twig->render('base_url');
70+
$expected = 'http://localhost/&quot;&gt;&lt;s&gt;abc&lt;/s&gt;&lt;a name=&quot;test';
71+
$this->assertEquals($expected, $actual);
72+
}
7373

74-
public function test_site_url()
75-
{
76-
$actual = $this->twig->render('site_url');
77-
$expected = 'http://localhost/index.php/&quot;&gt;&lt;s&gt;abc&lt;/s&gt;&lt;a name=&quot;test';
78-
$this->assertEquals($expected, $actual);
79-
}
74+
public function test_site_url()
75+
{
76+
$actual = $this->twig->render('site_url');
77+
$expected = 'http://localhost/index.php/&quot;&gt;&lt;s&gt;abc&lt;/s&gt;&lt;a name=&quot;test';
78+
$this->assertEquals($expected, $actual);
79+
}
8080
}

tests/libraries/TwigTest.php

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,106 @@
22

33
class TwigTest extends PHPUnit_Framework_TestCase
44
{
5-
public static function setUpBeforeClass()
6-
{
7-
parent::setUpBeforeClass();
8-
$CI =& get_instance();
9-
$CI->load->library('twig');
10-
$CI->load->helper('url_helper');
11-
$CI->load->helper('form_helper');
12-
}
13-
14-
public function testRedner()
15-
{
16-
$obj = new Twig(['paths' => __DIR__ . '/../templates/']);
17-
18-
$data = [
19-
'name' => 'CodeIgniter',
20-
];
21-
$output = $obj->render('welcome', $data);
22-
$this->assertEquals('Hello CodeIgniter!'."\n", $output);
23-
}
24-
25-
public function testDisplay()
26-
{
27-
$obj = new Twig(['paths' => __DIR__ . '/../templates/']);
28-
29-
$data = [
30-
'name' => 'CodeIgniter',
31-
];
32-
$obj->display('welcome', $data);
33-
$CI =& get_instance();
34-
$output = $CI->output->get_output();
35-
$this->assertEquals('Hello CodeIgniter!'."\n", $output);
36-
}
37-
38-
public function testAddGlobal()
39-
{
40-
$obj = new Twig(['paths' => __DIR__ . '/../templates/']);
41-
$obj->addGlobal('sitename', 'Twig Test Site');
42-
43-
$output = $obj->render('global');
44-
$this->assertEquals('<title>Twig Test Site</title>'."\n", $output);
45-
}
46-
47-
public function testAddFunctionsRunsOnlyOnce()
48-
{
49-
$obj = new Twig(['paths' => __DIR__ . '/../templates/']);
50-
51-
$data = [
52-
'name' => 'CodeIgniter',
53-
];
54-
55-
$ref_obj = new ReflectionObject($obj);
56-
$ref_property = $ref_obj->getProperty('functions_added');
57-
$ref_property->setAccessible(true);
58-
$functions_added = $ref_property->getValue($obj);
59-
$this->assertEquals(false, $functions_added);
60-
61-
$output = $obj->render('welcome', $data);
62-
63-
$ref_obj = new ReflectionObject($obj);
64-
$ref_property = $ref_obj->getProperty('functions_added');
65-
$ref_property->setAccessible(true);
66-
$functions_added = $ref_property->getValue($obj);
67-
$this->assertEquals(true, $functions_added);
68-
69-
// Calls render() twice
70-
$output = $obj->render('welcome', $data);
71-
72-
$ref_obj = new ReflectionObject($obj);
73-
$ref_property = $ref_obj->getProperty('functions_added');
74-
$ref_property->setAccessible(true);
75-
$functions_added = $ref_property->getValue($obj);
76-
$this->assertEquals(true, $functions_added);
77-
}
78-
79-
public function testFunctionAsIs()
80-
{
81-
$obj = new Twig([
82-
'paths' => __DIR__ . '/../templates/',
83-
'functions' => ['md5'],
84-
'cache' => false,
85-
]);
86-
87-
$output = $obj->render('functions_asis');
88-
$this->assertEquals('900150983cd24fb0d6963f7d28e17f72'."\n", $output);
89-
}
90-
91-
public function testFunctionSafe()
92-
{
93-
$obj = new Twig([
94-
'paths' => __DIR__ . '/../templates/',
95-
'functions_safe' => ['test_safe'],
96-
'cache' => false,
97-
]);
98-
99-
$output = $obj->render('functions_safe');
100-
$this->assertEquals('<s>test</s>'."\n", $output);
101-
}
5+
public static function setUpBeforeClass()
6+
{
7+
parent::setUpBeforeClass();
8+
$CI =& get_instance();
9+
$CI->load->library('twig');
10+
$CI->load->helper('url_helper');
11+
$CI->load->helper('form_helper');
12+
}
13+
14+
public function testRedner()
15+
{
16+
$obj = new Twig(['paths' => __DIR__ . '/../templates/']);
17+
18+
$data = [
19+
'name' => 'CodeIgniter',
20+
];
21+
$output = $obj->render('welcome', $data);
22+
$this->assertEquals('Hello CodeIgniter!' . "\n", $output);
23+
}
24+
25+
public function testDisplay()
26+
{
27+
$obj = new Twig(['paths' => __DIR__ . '/../templates/']);
28+
29+
$data = [
30+
'name' => 'CodeIgniter',
31+
];
32+
$obj->display('welcome', $data);
33+
$CI =& get_instance();
34+
$output = $CI->output->get_output();
35+
$this->assertEquals('Hello CodeIgniter!' . "\n", $output);
36+
}
37+
38+
public function testAddGlobal()
39+
{
40+
$obj = new Twig(['paths' => __DIR__ . '/../templates/']);
41+
$obj->addGlobal('sitename', 'Twig Test Site');
42+
43+
$output = $obj->render('global');
44+
$this->assertEquals('<title>Twig Test Site</title>' . "\n", $output);
45+
}
46+
47+
public function testAddFunctionsRunsOnlyOnce()
48+
{
49+
$obj = new Twig(['paths' => __DIR__ . '/../templates/']);
50+
51+
$data = [
52+
'name' => 'CodeIgniter',
53+
];
54+
55+
$ref_obj = new ReflectionObject($obj);
56+
$ref_property = $ref_obj->getProperty('functions_added');
57+
$ref_property->setAccessible(true);
58+
$functions_added = $ref_property->getValue($obj);
59+
$this->assertEquals(false, $functions_added);
60+
61+
$output = $obj->render('welcome', $data);
62+
63+
$ref_obj = new ReflectionObject($obj);
64+
$ref_property = $ref_obj->getProperty('functions_added');
65+
$ref_property->setAccessible(true);
66+
$functions_added = $ref_property->getValue($obj);
67+
$this->assertEquals(true, $functions_added);
68+
69+
// Calls render() twice
70+
$output = $obj->render('welcome', $data);
71+
72+
$ref_obj = new ReflectionObject($obj);
73+
$ref_property = $ref_obj->getProperty('functions_added');
74+
$ref_property->setAccessible(true);
75+
$functions_added = $ref_property->getValue($obj);
76+
$this->assertEquals(true, $functions_added);
77+
}
78+
79+
public function testFunctionAsIs()
80+
{
81+
$obj = new Twig([
82+
'paths' => __DIR__ . '/../templates/',
83+
'functions' => ['md5'],
84+
'cache' => false,
85+
]);
86+
87+
$output = $obj->render('functions_asis');
88+
$this->assertEquals('900150983cd24fb0d6963f7d28e17f72' . "\n", $output);
89+
}
90+
91+
public function testFunctionSafe()
92+
{
93+
$obj = new Twig([
94+
'paths' => __DIR__ . '/../templates/',
95+
'functions_safe' => ['test_safe'],
96+
'cache' => false,
97+
]);
98+
99+
$output = $obj->render('functions_safe');
100+
$this->assertEquals('<s>test</s>' . "\n", $output);
101+
}
102102
}
103103

104104
function test_safe()
105105
{
106-
return '<s>test</s>';
106+
return '<s>test</s>';
107107
}

0 commit comments

Comments
 (0)