assertFieldAccess example

'status' => 1,
      'preferred_langcode' => 'es',
      'preferred_admin_langcode' => 'fr',
      'timezone' => 'ut1',
      'created' => 123456,
    ]);

    $user->save();

    // @todo Expand the test coverage in https://www.drupal.org/node/2464635
    $this->assertFieldAccess('user', 'uid', $user->id());
    $this->assertFieldAccess('user', 'uuid', $user->uuid());
    $this->assertFieldAccess('user', 'langcode', $user->language()->getName());
    $this->assertFieldAccess('user', 'preferred_langcode', 'Spanish');
    $this->assertFieldAccess('user', 'preferred_admin_langcode', 'French');
    $this->assertFieldAccess('user', 'name', 'test user');
    // $this->assertFieldAccess('user', 'mail', 'druplicon@drop.org');     $this->assertFieldAccess('user', 'timezone', 'ut1');
    $this->assertFieldAccess('user', 'status', 'On');
    // $this->assertFieldAccess('user', 'created', \Drupal::service('date.formatter')->format(123456));     // $this->assertFieldAccess('user', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));   }

}
$this->installEntitySchema('entity_test');
  }

  public function testEntityTestFields() {
    $entity_test = EntityTest::create([
      'name' => 'test entity name',
    ]);
    $entity_test->save();

    // @todo Expand the test coverage in https://www.drupal.org/node/2464635
    $this->assertFieldAccess('entity_test', 'id', $entity_test->id());
    $this->assertFieldAccess('entity_test', 'langcode', $entity_test->language()->getName());
    $this->assertFieldAccess('entity_test', 'name', $entity_test->getName());
  }

}
'uid' => $user->id(),
      'status' => 1,
      'promote' => 1,
      'sticky' => 0,
      'created' => 123456,
    ]);

    $node->save();

    // @todo Expand the test coverage in https://www.drupal.org/node/2464635
    $this->assertFieldAccess('node', 'nid', $node->id());
    $this->assertFieldAccess('node', 'uuid', $node->uuid());
    $this->assertFieldAccess('node', 'vid', $node->id());
    $this->assertFieldAccess('node', 'type', $node->type->entity->label());
    $this->assertFieldAccess('node', 'langcode', $node->language()->getName());
    $this->assertFieldAccess('node', 'title', 'Test title');
    $this->assertFieldAccess('node', 'uid', $user->getAccountName());
    // @todo Don't we want to display Published / Unpublished by default,     // see https://www.drupal.org/node/2465623     $this->assertFieldAccess('node', 'status', 'On');
    $this->assertFieldAccess('node', 'promote', 'On');
    $this->assertFieldAccess('node', 'sticky', 'Off');

    
$message = "User '$field' field access returns '$result_text' with operation '$operation' for '$viewer' accessing '$target'";
      $this->assertSame($result$this->accessControlHandler->fieldAccess($operation$field_definition$this->{$viewer}$this->items)$message);
    }
  }

  /** * Ensures user name access is working properly. * * @dataProvider userNameProvider */
  public function testUserNameAccess($viewer$target$view$edit) {
    $this->assertFieldAccess('name', $viewer$target$view$edit);
  }

  /** * Provides test data for testUserNameAccess(). */
  public function userNameProvider() {
    $name_access = [
      // The viewer user is allowed to see user names on all accounts.       [
        'viewer' => 'viewer',
        'target' => 'viewer',
        
'name' => 'Majorly random',
      'vid' => $vocab->id(),
    ]);
    $term2->save();

    $term3 = Term::create([
      'name' => 'Not really random',
      'vid' => $vocab->id(),
    ]);
    $term3->save();

    $this->assertFieldAccess('taxonomy_term', 'name', 'Majorly random');
    $this->assertFieldAccess('taxonomy_term', 'name', 'Semi random');
    $this->assertFieldAccess('taxonomy_term', 'name', 'Not really random');
    $this->assertFieldAccess('taxonomy_term', 'tid', $term1->id());
    $this->assertFieldAccess('taxonomy_term', 'tid', $term2->id());
    $this->assertFieldAccess('taxonomy_term', 'tid', $term3->id());
    $this->assertFieldAccess('taxonomy_term', 'uuid', $term1->uuid());
    $this->assertFieldAccess('taxonomy_term', 'uuid', $term2->uuid());
    $this->assertFieldAccess('taxonomy_term', 'uuid', $term3->uuid());
  }

}
$file = File::create([
      'filename' => 'test.txt',
      'uri' => 'public://test.txt',
      'status' => TRUE,
      'langcode' => 'fr',
      'uid' => $user->id(),
    ]);
    $file->save();

    // @todo Expand the test coverage in https://www.drupal.org/node/2464635
    $this->assertFieldAccess('file', 'fid', $file->id());
    $this->assertFieldAccess('file', 'uuid', $file->uuid());
    $this->assertFieldAccess('file', 'langcode', $file->language()->getName());
    $this->assertFieldAccess('file', 'uid', 'test user');
    $this->assertFieldAccess('file', 'filename', $file->getFilename());
    $this->assertFieldAccess('file', 'uri', $file->getFileUri());
    $this->assertFieldAccess('file', 'filemime', $file->filemime->value);
    $this->assertFieldAccess('file', 'filesize', '4 bytes');
    $this->assertFieldAccess('file', 'status', 'Permanent');
    // $this->assertFieldAccess('file', 'created', \Drupal::service('date.formatter')->format(123456));     // $this->assertFieldAccess('file', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));   }

}
'entity_type' => 'entity_test',
      'field_name' => 'comment',
      'entity_id' => $host->id(),
      'comment_type' => 'entity_test',
      'created' => 123456,
      'status' => 1,
    ]);
    $comment_anonymous->save();

    // @todo Expand the test coverage in https://www.drupal.org/node/2464635
    $this->assertFieldAccess('comment', 'cid', $comment->id());
    $this->assertFieldAccess('comment', 'cid', $comment_anonymous->id());
    $this->assertFieldAccess('comment', 'uuid', $comment->uuid());
    $this->assertFieldAccess('comment', 'subject', 'My comment title');
    $this->assertFieldAccess('comment', 'subject', 'Anonymous comment title');
    $this->assertFieldAccess('comment', 'name', 'anonymous');
    $this->assertFieldAccess('comment', 'mail', 'test@example.com');
    $this->assertFieldAccess('comment', 'homepage', 'https://example.com');
    $this->assertFieldAccess('comment', 'uid', $user->getAccountName());
    // $this->assertFieldAccess('comment', 'created', \Drupal::service('date.formatter')->format(123456));     // $this->assertFieldAccess('comment', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));     $this->assertFieldAccess('comment', 'status', 'On');
  }
Home | Imprint | This part of the site doesn't use cookies.