Chris@0: profile != 'standard') { Chris@0: $this->drupalCreateContentType([ Chris@0: 'type' => 'page', Chris@0: 'name' => 'Basic page', Chris@0: 'display_submitted' => FALSE, Chris@0: ]); Chris@0: $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); Chris@0: } Chris@0: $this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('node'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that node access correctly grants or denies access. Chris@0: * Chris@0: * @param array $ops Chris@0: * An associative array of the expected node access grants for the node Chris@0: * and account, with each key as the name of an operation (e.g. 'view', Chris@0: * 'delete') and each value a Boolean indicating whether access to that Chris@0: * operation should be granted. Chris@0: * @param \Drupal\node\NodeInterface $node Chris@0: * The node object to check. Chris@0: * @param \Drupal\Core\Session\AccountInterface $account Chris@0: * The user account for which to check access. Chris@0: */ Chris@0: public function assertNodeAccess(array $ops, NodeInterface $node, AccountInterface $account) { Chris@0: foreach ($ops as $op => $result) { Chris@0: $this->assertEqual($result, $this->accessHandler->access($node, $op, $account), $this->nodeAccessAssertMessage($op, $result, $node->language()->getId())); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that node create access correctly grants or denies access. Chris@0: * Chris@0: * @param string $bundle Chris@0: * The node bundle to check access to. Chris@0: * @param bool $result Chris@0: * Whether access should be granted or not. Chris@0: * @param \Drupal\Core\Session\AccountInterface $account Chris@0: * The user account for which to check access. Chris@0: * @param string|null $langcode Chris@0: * (optional) The language code indicating which translation of the node Chris@0: * to check. If NULL, the untranslated (fallback) access is checked. Chris@0: */ Chris@0: public function assertNodeCreateAccess($bundle, $result, AccountInterface $account, $langcode = NULL) { Chris@0: $this->assertEqual($result, $this->accessHandler->createAccess($bundle, $account, [ Chris@0: 'langcode' => $langcode, Chris@0: ]), $this->nodeAccessAssertMessage('create', $result, $langcode)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Constructs an assert message to display which node access was tested. Chris@0: * Chris@0: * @param string $operation Chris@0: * The operation to check access for. Chris@0: * @param bool $result Chris@0: * Whether access should be granted or not. Chris@0: * @param string|null $langcode Chris@0: * (optional) The language code indicating which translation of the node Chris@0: * to check. If NULL, the untranslated (fallback) access is checked. Chris@0: * Chris@0: * @return string Chris@0: * An assert message string which contains information in plain English Chris@0: * about the node access permission test that was performed. Chris@0: */ Chris@0: public function nodeAccessAssertMessage($operation, $result, $langcode = NULL) { Chris@0: return format_string( Chris@0: 'Node access returns @result with operation %op, language code %langcode.', Chris@0: [ Chris@0: '@result' => $result ? 'true' : 'false', Chris@0: '%op' => $operation, Chris@17: '%langcode' => !empty($langcode) ? $langcode : 'empty', Chris@0: ] Chris@0: ); Chris@0: } Chris@0: Chris@0: }