public function test_admin_toolbar_for_home_page()
 {
     $this->go_to_with_template(home_url());
     $this->assertTrue($this->html->is_active());
     $this->assertTrue($this->html->should_dispatch());
     ob_start();
     $this->html->dispatch();
     $output = ob_get_clean();
     $this->assertNotEmpty($output);
     $expected = array('admin' => false, 'assets' => true, 'conditionals' => false, 'db_callers' => true, 'db_components' => true, 'db_queries' => true, 'debug_bar' => false, 'environment' => true, 'hooks' => true, 'http' => true, 'languages' => true, 'overview' => false, 'php_errors' => false, 'redirects' => false, 'request' => true, 'theme' => true, 'transients' => true);
     $collectors = QM_Collectors::init();
     $menu = $this->html->js_admin_bar_menu();
     $this->assertInternalType('array', $menu);
     $this->assertArrayHasKey('top', $menu);
     $this->assertArrayHasKey('sub', $menu);
     $this->assertNotEmpty($menu['sub']);
     foreach ($collectors as $collector) {
         $this->assertArrayHasKey($collector->id, $expected, sprintf('%s is not present in the test menu', $collector->id));
         if ($expected[$collector->id]) {
             $this->assertArrayHasKey('query-monitor-' . $collector->id, $menu['sub']);
         } else {
             $this->assertArrayNotHasKey('query-monitor-' . $collector->id, $menu['sub']);
         }
     }
 }
Esempio n. 2
0
 public function get_outputters($outputter_id)
 {
     $out = array();
     $collectors = QM_Collectors::init();
     $collectors->process();
     $this->outputters = apply_filters("qm/outputter/{$outputter_id}", array(), $collectors);
     /* @var QM_Output[] */
     foreach ($this->outputters as $id => $outputter) {
         $out[$id] = $outputter;
     }
     return $out;
 }
Esempio n. 3
0
function register_qm_collectors_debug_bar()
{
    global $debug_bar;
    if (class_exists('Debug_Bar') || qm_debug_bar_being_activated()) {
        return;
    }
    $collectors = QM_Collectors::init();
    $qm = QueryMonitor::init();
    require_once $qm->plugin_path('classes/debug_bar.php');
    $debug_bar = new Debug_Bar();
    $redundant = array('debug_bar_actions_addon_panel', 'debug_bar_remote_requests_panel', 'debug_bar_screen_info_panel', 'ps_listdeps_debug_bar_panel');
    foreach ($debug_bar->panels as $panel) {
        $panel_id = strtolower(get_class($panel));
        if (in_array($panel_id, $redundant)) {
            continue;
        }
        $collector = new QM_Collector_Debug_Bar();
        $collector->set_id("debug_bar_{$panel_id}");
        $collector->set_panel($panel);
        $collectors->add($collector);
    }
}
Esempio n. 4
0
    protected function after_output()
    {
        $collectors = QM_Collectors::init();
        echo '<div class="qm qm-half qm-clear" id="qm-authentication">';
        echo '<table cellspacing="0">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>' . esc_html__('Authentication', 'query-monitor') . '</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
        if (!self::user_verified()) {
            echo '<tr>';
            echo '<td>' . esc_html__('You can set an authentication cookie which allows you to view Query Monitor output when you&rsquo;re not logged in.', 'query-monitor') . '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td><a href="#" class="qm-auth" data-action="on">' . esc_html__('Set authentication cookie', 'query-monitor') . '</a></td>';
            echo '</tr>';
        } else {
            echo '<tr>';
            echo '<td>' . esc_html__('You currently have an authentication cookie which allows you to view Query Monitor output.', 'query-monitor') . '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td><a href="#" class="qm-auth" data-action="off">' . esc_html__('Clear authentication cookie', 'query-monitor') . '</a></td>';
            echo '</tr>';
        }
        echo '</tbody>';
        echo '</table>';
        echo '</div>';
        echo '</div>';
        echo '</div>';
        $json = array('menu' => $this->js_admin_bar_menu(), 'ajax_errors' => array());
        echo '<script type="text/javascript">' . "\n\n";
        echo 'var qm = ' . json_encode($json) . ';' . "\n\n";
        ?>
		if ( 'undefined' === typeof QM_i18n ) {
			document.getElementById( 'qm' ).style.display = 'block';
		}
		<?php 
        echo '</script>' . "\n\n";
    }
Esempio n. 5
0
 public function action_shutdown()
 {
     # @TODO this should move to each dispatcher so it can decide when it wants to do its output
     # eg. the JSON dispatcher needs to output inside the 'json_post_dispatch' filter, not on shutdown
     if (!$this->should_process()) {
         return;
     }
     $collectors = QM_Collectors::init();
     $dispatchers = QM_Dispatchers::init();
     foreach ($collectors as $collector) {
         $collector->tear_down();
         $collector->process();
     }
     foreach ($dispatchers as $dispatcher) {
         if (!$dispatcher->is_active()) {
             continue;
         }
         $dispatcher->before_output();
         $outputters = apply_filters("qm/outputter/{$dispatcher->id}", array(), $collectors);
         foreach ($outputters as $outputter) {
             $outputter->output();
         }
         $dispatcher->after_output();
     }
 }