Newer
Older
* Definition of Drupal\views\Tests\Plugin\AccessTest
namespace Drupal\views\Tests\Plugin;
Alex Pott
committed
use Drupal\views\Tests\ViewTestData;
*
* @todo It probably make sense to split the test up by one for role/perm/none
* and the two generic ones.
class AccessTest extends PluginTestBase {
catch
committed
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_access_none', 'test_access_static', 'test_access_dynamic');
public static function getInfo() {
return array(
'name' => 'Access',
'description' => 'Tests pluggable access for views.',
'group' => 'Views Plugins'
);
}
protected function setUp() {
$this->enableViewsTestModule();
Alex Pott
committed
ViewTestData::importTestViews(get_class($this), array('views_test_data'));
$this->admin_user = $this->drupalCreateUser(array('access all views'));
$this->web_user = $this->drupalCreateUser();
Alex Pott
committed
$this->web_role = $this->web_user->roles[0];
$this->normal_role = $this->drupalCreateRole(array());
$this->normal_user = $this->drupalCreateUser(array('views_test_data test permission'));
Alex Pott
committed
Alex Pott
committed
// @todo: How to add a new item to the roles field list.
$this->normal_user->getNGEntity()->roles[2]->value = $this->normal_role;
Bram Goffings
committed
// @todo when all the plugin information is cached make a reset function and
// call it here.
}
/**
* Tests none access plugin.
*/
function testAccessNone() {
catch
committed
$view = views_get_view('test_access_none');
$view->setDisplay();
$this->assertTrue($view->display_handler->access($this->admin_user), t('Admin-Account should be able to access the view everytime'));
$this->assertTrue($view->display_handler->access($this->web_user));
$this->assertTrue($view->display_handler->access($this->normal_user));
}
/**
* @todo Test abstract access plugin.
*/
/**
* Tests static access check.
*
* @see Drupal\views_test\Plugin\views\access\StaticTest
catch
committed
$view = views_get_view('test_access_static');
$view->setDisplay();
Daniel Wehner
committed
$access_plugin = $view->display_handler->getPlugin('access');
$this->assertFalse($access_plugin->access($this->normal_user));
Alex Pott
committed
$this->drupalGet('test_access_static');
$this->assertResponse(403);
Alex Pott
committed
$display = &$view->storage->getDisplay('default');
$display['display_options']['access']['options']['access'] = TRUE;
Alex Pott
committed
$view->save();
$this->container->get('router.builder')->rebuild();
$this->assertTrue($access_plugin->access($this->normal_user));
Alex Pott
committed
$this->drupalGet('test_access_static');
$this->assertResponse(200);