コード例 #1
0
 protected function setUp()
 {
     parent::setUp();
     $this->originalPath = \Nabble\SemaltBlocker\Updater::getBlocklistFilename();
     $this->backupPath = str_replace('blocked', $this->backupFilename, $this->originalPath);
     file_put_contents($this->backupPath, file_get_contents($this->originalPath));
 }
コード例 #2
0
 /**
  * @depends testDomainsRetrieval
  */
 public function testForcedDomainsUpdate()
 {
     $domainList = \Nabble\SemaltBlocker\Updater::getNewDomainList();
     file_put_contents($this->blockFile, '');
     \Nabble\SemaltBlocker\Updater::$ttl = 60 * 60 * 24 * 9999;
     // = 9999 days;
     \Nabble\SemaltBlocker\Updater::update(true);
     $this->assertStringEqualsFile($this->blockFile, $domainList, 'Blocked file should match online domain list');
 }
コード例 #3
0
ファイル: test.php プロジェクト: alister/semalt-blocker
<?php

$BLOCKLIST = __DIR__ . DIRECTORY_SEPARATOR . 'blocked';
copy(__DIR__ . DIRECTORY_SEPARATOR . './../domains/blocked', $BLOCKLIST);
chmod($BLOCKLIST, 0777);
include 'semaltblocker.php';
$_SERVER["HTTP_REFERER"] = 'http://semalt.com';
try {
    // Test blocking
    $expected = 'Blocking because referral domain (semalt.com) is found on blocklist';
    $actual = \Nabble\SemaltBlocker\Blocker::blocked(true);
    if (!@assert($expected === $actual)) {
        throw new Exception('Blocking domains failed');
    }
    // Test updating
    file_put_contents($BLOCKLIST, '');
    \Nabble\SemaltBlocker\Updater::update(true);
    $expected = \Nabble\SemaltBlocker\Updater::getNewDomainList();
    $actual = file_get_contents($BLOCKLIST);
    if (!@assert($expected === $actual)) {
        throw new Exception('Updating domains failed');
    }
} catch (Exception $e) {
    echo $e->getMessage() . '<br/>' . PHP_EOL;
}
echo 'All tests finished' . PHP_EOL;
unlink($BLOCKLIST);