Пример #1
0
 /**
  * Initialize Shield instance and perform authorization.
  * @param  array        $config    Configuration
  * @param  ShieldPanel  $panel     Tracy's ShieldPanel
  * @param  Response     $response  Http response
  */
 public function __construct(array $config, ShieldPanel $panel, Response $response)
 {
     // Store provided properties
     $this->config = array_merge($this->config, $config);
     $this->response = $response;
     // If Tracy panel is enabled
     if ($this->config['debugger']) {
         // Set Shield instance to panel
         $panel->setShield($this);
     }
     // If automatic mode is disabled or user is authorized
     if (!$this->isAutorun() || $this->isAuthorized()) {
         return null;
     }
     // User is unauthorized
     return $this->onUnauthorized();
 }
Пример #2
0
 /**
  * Case - Basic panel test.
  */
 public function testBasic()
 {
     // Get the panel instance
     $panel = new ShieldPanel();
     // Assert returned values from the methods
     $this->assertSame('', $panel->getTab());
     // There is no Shield instance
     $this->assertSame('', $panel->getPanel());
     // Always empty
     $this->assertInternalType('string', $panel->getShieldIcon());
     // Create instance of the Shield class - disabled
     new Shield([], $panel, new Response());
     // Just check first few characters
     $this->assertStringStartsWith('<span title="Shield', $panel->getTab());
     // Create instance of the Shield class - enabled
     new Shield(['enabled' => true], $panel, new Response());
     // Just check first few characters
     $this->assertStringStartsWith('<span title="Shield', $panel->getTab());
 }