class ParagraphsAccessTest

Same name in this branch
  1. 8.x-1.x paragraphs/tests/src/Kernel/ParagraphsAccessTest.php \Drupal\Tests\paragraphs\Kernel\ParagraphsAccessTest
  2. 8.x-1.x paragraphs/tests/src/Functional/WidgetStable/ParagraphsAccessTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsAccessTest
  3. 8.x-1.x paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsAccessTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsAccessTest

@coversDefaultClass \Drupal\paragraphs\ParagraphAccessControlHandler @group paragraphs

Hierarchy

  • class \Drupal\Tests\paragraphs\Kernel\ParagraphsAccessTest extends \Drupal\KernelTests\KernelTestBase

Expanded class hierarchy of ParagraphsAccessTest

File

paragraphs/tests/src/Kernel/ParagraphsAccessTest.php, line 17

Namespace

Drupal\Tests\paragraphs\Kernel
View source
class ParagraphsAccessTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'paragraphs',
  ];

  /**
   * @covers ::checkCreateAccess
   *
   * @dataProvider createAccessTestCases
   */
  public function testCreateAccess($request_format, AccessResult $expected_result) {
    $cache_contexts_manager = $this
      ->prophesize(CacheContextsManager::class);
    $cache_contexts_manager
      ->assertValidTokens()
      ->willReturn(TRUE);
    $cache_contexts_manager
      ->reveal();
    $this->container
      ->set('cache_contexts_manager', $cache_contexts_manager);
    $expected_result
      ->addCacheContexts([
      'request_format',
    ]);
    $request = new Request();
    $request
      ->setRequestFormat($request_format);
    $this->container
      ->get('request_stack')
      ->push($request);
    $result = $this->container
      ->get('entity_type.manager')
      ->getAccessControlHandler('paragraph')
      ->createAccess(NULL, NULL, [], TRUE);
    $this
      ->assertEquals($expected_result, $result);
    $this->container
      ->get('request_stack')
      ->pop();
  }

  /**
   * Test cases for ::testCreateAccess.
   */
  public static function createAccessTestCases() {
    return [
      'Allowed HTML request format' => [
        'html',
        AccessResult::allowed(),
      ],
      'Forbidden other formats' => [
        'json',
        AccessResult::neutral(),
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsAccessTest::$modules protected static property
ParagraphsAccessTest::createAccessTestCases public static function Test cases for ::testCreateAccess.
ParagraphsAccessTest::testCreateAccess public function @covers ::checkCreateAccess