3 namespace Drupal\Tests\rest\Functional\EntityResource\Term;
5 use Drupal\taxonomy\Entity\Term;
6 use Drupal\taxonomy\Entity\Vocabulary;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
9 abstract class TermResourceTestBase extends EntityResourceTestBase {
14 public static $modules = ['taxonomy'];
19 protected static $entityTypeId = 'taxonomy_term';
24 protected static $patchProtectedFieldNames = [
29 * @var \Drupal\taxonomy\TermInterface
36 protected function setUpAuthorization($method) {
39 $this->grantPermissionsToTestedRole(['access content']);
44 // @todo Update once https://www.drupal.org/node/2824408 lands.
45 $this->grantPermissionsToTestedRole(['administer taxonomy']);
53 protected function createEntity() {
54 $vocabulary = Vocabulary::load('camelids');
56 // Create a "Camelids" vocabulary.
57 $vocabulary = Vocabulary::create([
64 // Create a "Llama" taxonomy term.
65 $term = Term::create(['vid' => $vocabulary->id()])
67 ->setChangedTime(123456789);
76 protected function getExpectedNormalizedEntity() {
82 ['value' => $this->entity->uuid()],
86 'target_id' => 'camelids',
87 'target_type' => 'taxonomy_vocabulary',
88 'target_uuid' => Vocabulary::load('camelids')->uuid(),
111 'value' => $this->entity->getChangedTime(),
114 'default_langcode' => [
125 protected function getNormalizedPostEntity() {
129 'target_id' => 'camelids',
134 'value' => 'Dramallama',
143 protected function getExpectedUnauthorizedAccessMessage($method) {
144 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
145 return parent::getExpectedUnauthorizedAccessMessage($method);
150 return "The 'access content' permission is required.";
152 return "The 'administer taxonomy' permission is required.";
154 return "The following permissions are required: 'edit terms in camelids' OR 'administer taxonomy'.";
156 return "The following permissions are required: 'delete terms in camelids' OR 'administer taxonomy'.";
158 return parent::getExpectedUnauthorizedAccessMessage($method);