Skip to content

Commit 6c7526c

Browse files
committed
Continuation for Security and Table code-coverage, add coverage report to travis
1 parent 650f2a2 commit 6c7526c

11 files changed

Lines changed: 88 additions & 41 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ before_script:
1919
- sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
2020
- sh -c "if [ '$DB' = 'mysql' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
2121

22-
script: phpunit --configuration tests/travis/$DB.phpunit.xml
22+
script: phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml
2323

2424
branches:
2525
only:

system/core/Security.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public function csrf_verify()
191191
* Set Cross Site Request Forgery Protection Cookie
192192
*
193193
* @return object
194+
* @codeCoverageIgnore
194195
*/
195196
public function csrf_set_cookie()
196197
{

tests/codeigniter/core/Security_test.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,36 @@ public function test_xss_clean()
7070

7171
$this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string);
7272
}
73+
74+
// --------------------------------------------------------------------
75+
76+
public function test_xss_hash()
77+
{
78+
$this->assertEmpty($this->security->xss_hash);
79+
80+
// Perform hash
81+
$this->security->xss_hash();
82+
83+
$this->assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash) === 1);
84+
}
85+
86+
// --------------------------------------------------------------------
87+
88+
public function test_entity_decode()
89+
{
90+
$encoded = '<div>Hello <b>Booya</b></div>';
91+
$decoded = $this->security->entity_decode($encoded);
92+
93+
$this->assertEquals('<div>Hello <b>Booya</b></div>', $decoded);
94+
}
95+
96+
// --------------------------------------------------------------------
97+
98+
public function test_sanitize_filename()
99+
{
100+
$filename = './<!--foo-->';
101+
$safe_filename = $this->security->sanitize_filename($filename);
102+
103+
$this->assertEquals('foo', $safe_filename);
104+
}
73105
}

tests/codeigniter/libraries/Table_test.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,26 @@ function test_set_from_object()
291291
);
292292
}
293293

294-
// Test main generate method
295-
// --------------------------------------------------------------------
294+
function test_generate()
295+
{
296+
// Prepare the data
297+
$data = array(
298+
array('Name', 'Color', 'Size'),
299+
array('Fred', 'Blue', 'Small'),
300+
array('Mary', 'Red', 'Large'),
301+
array('John', 'Green', 'Medium')
302+
);
303+
304+
$table = $this->table->generate($data);
305+
306+
// Test the table header
307+
$this->assertTrue(strpos($table, '<th>Name</th>') !== FALSE);
308+
$this->assertTrue(strpos($table, '<th>Color</th>') !== FALSE);
309+
$this->assertTrue(strpos($table, '<th>Size</th>') !== FALSE);
310+
311+
// Test the first entry
312+
$this->assertTrue(strpos($table, '<td>Fred</td>') !== FALSE);
313+
$this->assertTrue(strpos($table, '<td>Blue</td>') !== FALSE);
314+
$this->assertTrue(strpos($table, '<td>Small</td>') !== FALSE);
315+
}
296316
}

tests/mocks/autoloader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function autoload($class)
2222
);
2323

2424
$ci_libraries = array(
25-
'Calendar', 'Cart', 'Driver',
25+
'Calendar', 'Cart', 'Driver_Library',
2626
'Email', 'Encrypt', 'Form_validation',
2727
'Ftp', 'Image_lib', 'Javascript',
2828
'Log', 'Migration', 'Pagination',
@@ -50,7 +50,7 @@ function autoload($class)
5050
elseif (in_array($subclass, $ci_libraries))
5151
{
5252
$dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
53-
$class = $subclass;
53+
$class = ($subclass == 'Driver_Library') ? 'Driver' : $subclass;
5454
}
5555
elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3)
5656
{

tests/travis/mysql.phpunit.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
<directory suffix="test.php">../codeigniter</directory>
1818
</testsuite>
1919
</testsuites>
20-
<filters>
21-
<blacklist>
22-
<directory suffix=".php">PEAR_INSTALL_DIR</directory>
23-
<directory suffix=".php">PHP_LIBDIR</directory>
24-
</blacklist>
25-
</filters>
20+
<filter>
21+
<whitelist addUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">../../system</directory>
23+
</whitelist>
24+
</filter>
2625
</phpunit>

tests/travis/pdo/mysql.phpunit.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
<directory suffix="test.php">../../codeigniter</directory>
1818
</testsuite>
1919
</testsuites>
20-
<filters>
21-
<blacklist>
22-
<directory suffix=".php">PEAR_INSTALL_DIR</directory>
23-
<directory suffix=".php">PHP_LIBDIR</directory>
24-
</blacklist>
25-
</filters>
20+
<filter>
21+
<whitelist addUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">../../../system</directory>
23+
</whitelist>
24+
</filter>
2625
</phpunit>

tests/travis/pdo/pgsql.phpunit.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
<directory suffix="test.php">../../codeigniter</directory>
1818
</testsuite>
1919
</testsuites>
20-
<filters>
21-
<blacklist>
22-
<directory suffix=".php">PEAR_INSTALL_DIR</directory>
23-
<directory suffix=".php">PHP_LIBDIR</directory>
24-
</blacklist>
25-
</filters>
20+
<filter>
21+
<whitelist addUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">../../../system</directory>
23+
</whitelist>
24+
</filter>
2625
</phpunit>

tests/travis/pdo/sqlite.phpunit.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
<directory suffix="test.php">../../codeigniter</directory>
1818
</testsuite>
1919
</testsuites>
20-
<filters>
21-
<blacklist>
22-
<directory suffix=".php">PEAR_INSTALL_DIR</directory>
23-
<directory suffix=".php">PHP_LIBDIR</directory>
24-
</blacklist>
25-
</filters>
20+
<filter>
21+
<whitelist addUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">../../../system</directory>
23+
</whitelist>
24+
</filter>
2625
</phpunit>

tests/travis/pgsql.phpunit.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
<directory suffix="test.php">../codeigniter</directory>
1818
</testsuite>
1919
</testsuites>
20-
<filters>
21-
<blacklist>
22-
<directory suffix=".php">PEAR_INSTALL_DIR</directory>
23-
<directory suffix=".php">PHP_LIBDIR</directory>
24-
</blacklist>
25-
</filters>
20+
<filter>
21+
<whitelist addUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">../../system</directory>
23+
</whitelist>
24+
</filter>
2625
</phpunit>

0 commit comments

Comments
 (0)