Nabble\SemaltBlocker\Blocker::protect PHP Method

protect() public static method

public static protect ( $action = '' )
    public static function protect($action = '')
    {
        if (!defined('SEMALT_UNIT_TESTING')) {
            Updater::update();
        }
        if (!self::isRefererOnBlocklist()) {
            return;
        }
        self::doBlock($action);
        if (!defined('SEMALT_UNIT_TESTING')) {
            exit;
        }
    }

Same methods

Blocker::protect ( string $action = '' )

Usage Example

Example #1
0
 /**
  * @depends testBlocked
  */
 public function testBlock()
 {
     $this->mockGoodReferer();
     ob_start();
     \Nabble\SemaltBlocker\Blocker::protect();
     $output = ob_get_clean();
     $this->assertEmpty($output, 'Shouldn\'t output anything');
     $this->mockBadReferer();
     ob_start();
     \Nabble\SemaltBlocker\Blocker::protect();
     $output = ob_get_clean();
     $explodedExplanation = explode('%s', \Nabble\SemaltBlocker\Blocker::$explanation);
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     $this->assertContains($explodedExplanation[0], $output, 'Should contain explanation');
     ob_start();
     \Nabble\SemaltBlocker\Blocker::protect('TEST_MESSAGE');
     $output = ob_get_clean();
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     $this->assertContains('TEST_MESSAGE', $output, 'Should contain test message');
     ob_start();
     \Nabble\SemaltBlocker\Blocker::protect('http://www.google.com');
     $output = ob_get_clean();
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     // @todo test headers
 }
All Usage Examples Of Nabble\SemaltBlocker\Blocker::protect