ShortcutSetResourceTestBase.php in Drupal 8        
                          
                  
                        
  
  
  
  
File
  core/modules/shortcut/tests/src/Functional/Rest/ShortcutSetResourceTestBase.php
  
    View source  
  <?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class ShortcutSetResourceTestBase extends EntityResourceTestBase {
  
  public static $modules = [
    'shortcut',
  ];
  
  protected static $entityTypeId = 'shortcut_set';
  
  protected static $patchProtectedFieldNames = [];
  
  protected $entity;
  
  protected function setUpAuthorization($method) {
    switch ($method) {
      case 'GET':
        $this
          ->grantPermissionsToTestedRole([
          'access shortcuts',
        ]);
        break;
      case 'POST':
      case 'PATCH':
        $this
          ->grantPermissionsToTestedRole([
          'access shortcuts',
          'customize shortcut links',
        ]);
        break;
      case 'DELETE':
        $this
          ->grantPermissionsToTestedRole([
          'administer shortcuts',
        ]);
        break;
    }
  }
  
  protected function createEntity() {
    $set = ShortcutSet::create([
      'id' => 'llama_set',
      'label' => 'Llama Set',
    ]);
    $set
      ->save();
    return $set;
  }
  
  protected function getExpectedNormalizedEntity() {
    return [
      'id' => 'llama_set',
      'uuid' => $this->entity
        ->uuid(),
      'label' => 'Llama Set',
      'status' => TRUE,
      'langcode' => 'en',
      'dependencies' => [],
    ];
  }
  
  protected function getNormalizedPostEntity() {
    
  }
  
  protected function getExpectedUnauthorizedAccessMessage($method) {
    if ($this
      ->config('rest.settings')
      ->get('bc_entity_resource_permissions')) {
      return parent::getExpectedUnauthorizedAccessMessage($method);
    }
    switch ($method) {
      case 'GET':
        return "The 'access shortcuts' permission is required.";
      default:
        return parent::getExpectedUnauthorizedAccessMessage($method);
    }
  }
}