Issue #1754218 by dawehner: Add a generic testcase for the access base.
parent
d7749d7048
commit
8354c8939a
|
@ -50,36 +50,6 @@ class AccessTest extends PluginTestBase {
|
|||
$this->assertTrue($view->display_handler->access($this->normal_user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests perm access plugin.
|
||||
*/
|
||||
function testAccessPerm() {
|
||||
$view = $this->createViewFromConfig('test_access_perm');
|
||||
|
||||
$access_plugin = $view->display_handler->getPlugin('access');
|
||||
|
||||
$this->assertTrue($view->display_handler->access($this->admin_user), t('Admin-Account should be able to access the view everytime'));
|
||||
$this->assertFalse($view->display_handler->access($this->web_user));
|
||||
$this->assertTrue($view->display_handler->access($this->normal_user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests role access plugin.
|
||||
*/
|
||||
function testAccessRole() {
|
||||
$view = $this->createViewFromConfig('test_access_role');
|
||||
|
||||
$view->displayHandlers['default']->options['access']['options']['role'] = array(
|
||||
$this->normal_role => $this->normal_role,
|
||||
);
|
||||
|
||||
$access_plugin = $view->display_handler->getPlugin('access');
|
||||
|
||||
$this->assertTrue($view->display_handler->access($this->admin_user), t('Admin-Account should be able to access the view everytime'));
|
||||
$this->assertFalse($view->display_handler->access($this->web_user));
|
||||
$this->assertTrue($view->display_handler->access($this->normal_user));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Test abstract access plugin.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of Drupal\views\Tests\User\AccessPermissionTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\views\Tests\User;
|
||||
|
||||
/**
|
||||
* Tests views perm access plugin.
|
||||
*
|
||||
* @see Views\user\Plugin\views\access\Permission
|
||||
*/
|
||||
class AccessPermissionTest extends AccessTestBase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'User: Access permission',
|
||||
'description' => 'Tests views permission access plugin.',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests perm access plugin.
|
||||
*/
|
||||
function testAccessPerm() {
|
||||
$view = $this->createViewFromConfig('test_access_perm');
|
||||
|
||||
$access_plugin = $view->display_handler->getPlugin('access');
|
||||
$this->assertTrue($access_plugin instanceof \Views\user\Plugin\views\access\Permission, 'Make sure the right class got instantiated.');
|
||||
|
||||
$this->assertTrue($view->display_handler->access($this->adminUser), t('Admin-Account should be able to access the view everytime'));
|
||||
$this->assertFalse($view->display_handler->access($this->webUser));
|
||||
$this->assertTrue($view->display_handler->access($this->normalUser));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of Drupal\views\Tests\User\AccessRoleTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\views\Tests\User;
|
||||
|
||||
/**
|
||||
* Tests views role access plugin.
|
||||
*
|
||||
* @see Views\user\Plugin\views\access\Role
|
||||
*/
|
||||
class AccessRoleTest extends AccessTestBase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'User: Access role',
|
||||
'description' => 'Tests views role access plugin.',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests role access plugin.
|
||||
*/
|
||||
function testAccessRole() {
|
||||
$view = $this->createViewFromConfig('test_access_role');
|
||||
|
||||
$view->displayHandlers['default']->options['access']['options']['role'] = array(
|
||||
$this->normalRole => $this->normalRole,
|
||||
);
|
||||
|
||||
$access_plugin = $view->display_handler->getPlugin('access');
|
||||
$this->assertTrue($access_plugin instanceof \Views\user\Plugin\views\access\Role, 'Make sure the right class got instantiated.');
|
||||
|
||||
|
||||
$this->assertTrue($view->display_handler->access($this->adminUser), t('Admin-Account should be able to access the view everytime'));
|
||||
$this->assertFalse($view->display_handler->access($this->webUser));
|
||||
$this->assertTrue($view->display_handler->access($this->normalUser));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of Drupal\views\Tests\Uses\AccessTestBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\views\Tests\User;
|
||||
|
||||
/**
|
||||
* A common test base class for the user access plugin tests.
|
||||
*/
|
||||
abstract class AccessTestBase extends UserTestBase {
|
||||
|
||||
/**
|
||||
* Contains a user object that can access all views.
|
||||
*
|
||||
* @var Drupal\user\User
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* Contains a user object that has no special permissions.
|
||||
*
|
||||
* @var Drupal\user\User
|
||||
*/
|
||||
protected $webUser;
|
||||
|
||||
/**
|
||||
* Contains a user object that has the 'views_test_data test permission'.
|
||||
*
|
||||
* @var Drupal\user\User
|
||||
*/
|
||||
protected $normalUser;
|
||||
|
||||
/**
|
||||
* Contains a role ID that is used by the webUser.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $webRole;
|
||||
|
||||
/**
|
||||
* Contains a role ID that is used by the normalUser.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $normalRole;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('access all views'));
|
||||
$this->webUser = $this->drupalCreateUser();
|
||||
$this->webRole = current($this->webUser->roles);
|
||||
|
||||
$this->normalRole = $this->drupalCreateRole(array());
|
||||
$this->normalUser = $this->drupalCreateUser(array('views_test_data test permission'));
|
||||
$this->normalUser->roles[$this->normalRole] = $this->normalRole;
|
||||
// @todo when all the plugin information is cached make a reset function and
|
||||
// call it here.
|
||||
}
|
||||
}
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Definition of Drupal\views\Plugin\views\access\Permission.
|
||||
* Definition of Views\user\Plugin\views\access\Permission.
|
||||
*/
|
||||
|
||||
namespace Drupal\views\Plugin\views\access;
|
||||
namespace Views\user\Plugin\views\access;
|
||||
|
||||
use Drupal\Core\Annotation\Plugin;
|
||||
use Drupal\views\Plugin\views\access\AccessPluginBase;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
|
||||
/**
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Definition of Drupal\views\Plugin\views\access\Role.
|
||||
* Definition of Views\user\Plugin\views\access\Role.
|
||||
*/
|
||||
|
||||
namespace Drupal\views\Plugin\views\access;
|
||||
namespace Views\user\Plugin\views\access;
|
||||
|
||||
use Drupal\Core\Annotation\Plugin;
|
||||
use Drupal\views\Plugin\views\access\AccessPluginBase;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
|
||||
/**
|
Loading…
Reference in New Issue