You are here

function AclTest::testNodeAclCreateDelete in ACL 8

Includes acl_create_acl, acl_delete_acl, acl_get_id_by_name

File

src/Tests/AclTest.php, line 60

Class

AclTest
Test case for ACL module.

Namespace

Drupal\acl\Tests

Code

function testNodeAclCreateDelete() {

  // Add a node.
  $node1 = $this
    ->drupalCreateNode(array(
    'type' => 'page',
    'promote' => 0,
  ));
  $this
    ->assertTrue((bool) Node::load($node1
    ->id()), t('Page node created.'));
  acl_create_acl('test1', $node1
    ->getTitle());
  $acl_id = acl_get_id_by_name('test1', $node1
    ->getTitle());
  $this
    ->assertNotNull($acl_id, t('ACL ID was successfully found.'));
  $records = \Drupal::database()
    ->select('acl')
    ->fields('acl', [
    'acl_id',
    'name',
  ])
    ->condition('acl_id', $acl_id)
    ->execute()
    ->fetchAll();
  $this
    ->assertEquals(count($records), 1, t('ACL was successfully created.'));
  acl_delete_acl($records[0]->acl_id);
  $records = \Drupal::database()
    ->select('acl')
    ->fields('acl', [
    'acl_id',
    'name',
  ])
    ->condition('acl_id', $records[0]->acl_id)
    ->execute()
    ->fetchAll();
  $this
    ->assertTrue(TRUE, var_export($records, TRUE));
  $this
    ->assertEquals(count($records), 0, t('ACL was successfully removed.'));
}