1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-01-17 11:08:14 +01:00
php-cimage/docs/api/files/test%2FCWhitelistTest.php.txt

96 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

2015-03-04 11:00:36 +01:00
<?php
/**
* A testclass
*
*/
class CWhitelistTest extends \PHPUnit_Framework_TestCase
{
/*
* remote_whitelist
*/
private $remote_whitelist = [
'\.facebook\.com$',
'^(?:images|photos-[a-z])\.ak\.instagram\.com$',
'\.google\.com$',
];
/**
* Provider for hostname matching the whitelist.
*
* @return array
*/
public function providerHostnameMatch()
{
return [
[
"any.facebook.com",
"images.ak.instagram.com",
"google.com",
],
];
}
/**
* Provider for hostname not matching the whitelist.
*
* @return array
*/
public function providerHostnameNoMatch()
{
return [
[
"example.com",
".com",
"img.jpg",
],
];
}
/**
* Test
*
* @param string $hostname matches the whitelist
*
* @return void
*
* @dataProvider providerHostnameMatch
*
*/
public function testRemoteHostWhitelistMatch($hostname)
{
$whitelist = new CWhitelist();
$whitelist->set($this->remote_whitelist);
$res = $whitelist->check($hostname);
$this->assertTrue($res, "Should be a valid hostname on the whitelist: '$hostname'.");
}
/**
* Test
*
* @param string $hostname not matching the whitelist
*
* @return void
*
* @dataProvider providerHostnameNoMatch
*
*/
public function testRemoteHostWhitelistNoMatch($hostname)
{
$whitelist = new CWhitelist();
$whitelist->set($this->remote_whitelist);
$res = $whitelist->check($hostname);
$this->assertFalse($res, "Should not be a valid hostname on the whitelist: '$hostname'.");
}
}