You are here

public function AuthcacheViewsTest::testFragmentGet in Authenticated User Page Caching (Authcache) 7.2

Ensure that a block can be retrieved from the front controller.

File

modules/authcache_views/authcache_views.test, line 221
Test cases for the Authcache Views module.

Class

AuthcacheViewsTest
Tests for markup substitution.

Code

public function testFragmentGet() {
  $view = views_get_view('tracker');
  $view->disabled = FALSE;
  $view->display['page']->display_options['authcache'] = array(
    'status' => '1',
    'lifespan' => '3600',
    'peruser' => '1',
    'perpage' => '1',
    'clients' => array(
      'authcache_p13n_test' => array(
        'status' => '1',
        'weight' => '0',
      ),
    ),
    'fallback' => 'cancel',
  );
  $view->display['page']->display_options['path'] = 'test-tracker';
  views_save_view($view);
  ctools_export_load_object_reset();
  authcache_p13n_request_router_rebuild();
  $request_id = 'frag/views/tracker/page';

  // FIXME: We should'nt need to mess around with $_GET here in order to
  // restore proper context for authcache_p13n_request_get_callback.
  $orig_get = $_GET;
  $_GET = array(
    'q' => 'test-tracker',
  );
  $url = authcache_p13n_request_get_callback($request_id, NULL);
  $_GET = $orig_get;
  $this
    ->assertTrue($url);
  $this
    ->drupalGet($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $this
    ->assertText($this->nodeByAnon->title, 'Test node authored by anonymous user in the list');
  $this
    ->assertText($this->nodeByAdmin->title, 'Test node authored by admin user in the list');

  // FIXME: ditto.
  $orig_get = $_GET;
  $_GET = array(
    'q' => 'test-tracker/0',
  );
  $url = authcache_p13n_request_get_callback($request_id, NULL);
  $_GET = $orig_get;
  $this
    ->assertTrue($url);
  $this
    ->drupalGet($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $this
    ->assertText($this->nodeByAnon->title, 'Test node authored by anonymous user in the list');
  $this
    ->assertNoText($this->nodeByAdmin->title, 'Test node authored by admin user not in the list');

  // FIXME: ditto.
  $orig_get = $_GET;
  $_GET = array(
    'q' => 'test-tracker/1',
  );
  $url = authcache_p13n_request_get_callback($request_id, NULL);
  $_GET = $orig_get;
  $this
    ->assertTrue($url);
  $this
    ->drupalGet($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $this
    ->assertNoText($this->nodeByAnon->title, 'Test node authored by anonymous user not in the list');
  $this
    ->assertText($this->nodeByAdmin->title, 'Test node authored by admin user in the list');
}