Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / entity_browser / tests / src / Kernel / Extension / EntityBrowserTest.php
index d737f04e8149de1553c13e41804176e7014268c5..018f17dbc642bac1d3f5abaa046f1784ef8f9984 100644 (file)
@@ -13,6 +13,7 @@ use Drupal\entity_browser\WidgetInterface;
 use Drupal\entity_browser\WidgetSelectorInterface;
 use Drupal\entity_browser\SelectionDisplayInterface;
 use Drupal\KernelTests\KernelTestBase;
+use Drupal\user\Entity\User;
 use Drupal\views\Entity\View;
 
 /**
@@ -467,4 +468,41 @@ class EntityBrowserTest extends KernelTestBase {
     $this->assertEmpty($form_state->getErrors(), t('Validation succeeded where expected'));
   }
 
+  /**
+   * Tests view widget access.
+   */
+  public function testViewWidgetAccess() {
+    $this->installConfig(['entity_browser_test']);
+    $this->installEntitySchema('user');
+    $this->installEntitySchema('user_role');
+
+    /** @var \Drupal\entity_browser\EntityBrowserInterface $entity */
+    $entity = $this->controller->load('test_entity_browser_file');
+
+    $this->assertFalse($entity->getWidget('774798f1-5ec5-4b63-84bd-124cd51ec07d')->access()->isAllowed());
+
+    // Create a user that has permission to access the view and try with it.
+    /** @var \Drupal\user\RoleInterface $role */
+    $role = $this->container->get('entity_type.manager')
+      ->getStorage('user_role')
+      ->create([
+        'name' => $this->randomString(),
+        'id' => $this->randomMachineName(),
+      ]);
+    $role->grantPermission('access content');
+    $role->save();
+
+    $user = $this->container->get('entity_type.manager')
+      ->getStorage('user')
+      ->create([
+        'name' => $this->randomString(),
+        'mail' => 'info@example.com',
+        'roles' => $role->id(),
+      ]);
+    $user->save();
+    \Drupal::currentUser()->setAccount($user);
+
+    $this->assertTrue($entity->getWidget('774798f1-5ec5-4b63-84bd-124cd51ec07d')->access()->isAllowed());
+  }
+
 }