You are here

class SimpleAccessOwnerTestCase in Simple Access 8.3

Same name and namespace in other branches
  1. 6.2 simple_access.test \SimpleAccessOwnerTestCase
  2. 7.2 simple_access.test \SimpleAccessOwnerTestCase

Test Owner permissions.

Hierarchy

Expanded class hierarchy of SimpleAccessOwnerTestCase

File

./simple_access.test, line 11
Tests to check that simple access is working correctly.

View source
class SimpleAccessOwnerTestCase extends DrupalWebTestCase {

  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    return [
      'name' => t('Check owner permissions'),
      'description' => t('Test different owner permissions and make sure access is correct'),
      'group' => t('Simple Access'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp('simple_access');
    $this->node_type = $this
      ->drupalCreateContentType();
    node_access_rebuild();
  }

  /**
   * Test if owner can edit content.
   */
  public function testSimpleAccessOwnerCanEdit() {
    $account = $this
      ->drupalCreateUser();
    $n1 = $this
      ->drupalCreateNode([
      'type' => $this->node_type,
      'uid' => $account->uid,
      'status' => 1,
      'simple_access_owner' => [
        'sa_view' => 1,
      ],
    ]);
    $n2 = $this
      ->drupalCreateNode([
      'type' => $this->node_type,
      'uid' => $account->uid,
      'status' => 1,
      'simple_access_owner' => [
        'sa_view' => 1,
        'sa_update' => 1,
      ],
    ]);
    $n1 = node_load($n1->nid);
    $n1->status = 1;
    $this
      ->assertFalse(node_access('update', $n1, $account), t("Owner doesn't have edit access to content"), 'Access');
    $n2 = node_load($n2->nid);
    $n2->status = 1;
    $this
      ->assertTrue(node_access('update', $n2, $account), t('Owner has edit access to content'), 'Access');
  }

}

Members