As the title said. That is the best practice.

Comments

bojanz created an issue. See original summary.

kavbiswa’s picture

Assigned: Unassigned » kavbiswa

I am working on this issue. will update the patch file with the changes.

kavbiswa’s picture

Assigned: kavbiswa » Unassigned
Status: Active » Needs review
StatusFileSize
new29.55 KB

Please review the patch

Status: Needs review » Needs work

The last submitted patch, 3: entity_api_3059103.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

piotr pakulski’s picture

StatusFileSize
new26.84 KB

Removing \Drupal:: static calls from kernel tests.

piotr pakulski’s picture

piotr pakulski’s picture

Status: Needs work » Needs review
bojanz’s picture

Status: Needs review » Needs work
diff --git a/tests/src/Kernel/QueryAccess/QueryAccessTest.php b/tests/src/Kernel/QueryAccess/QueryAccessTest.php
index 4302786..a8e7999 100644
--- a/tests/src/Kernel/QueryAccess/QueryAccessTest.php
+++ b/tests/src/Kernel/QueryAccess/QueryAccessTest.php
@@ -50,6 +50,7 @@ class QueryAccessTest extends EntityKernelTestBase {
    */
   protected function setUp() {
     parent::setUp();
+    $this->setUpCurrentUser(['uid' => 1]);
 
     $this->installEntitySchema('entity_test_enhanced');
     $this->installConfig(['entity_module_test']);
@@ -93,17 +94,13 @@ class QueryAccessTest extends EntityKernelTestBase {
     $third_entity->save();
 
     $this->entities = [$first_entity, $second_entity, $third_entity];
-    $this->storage = \Drupal::entityTypeManager()->getStorage('entity_test_enhanced');
+    $this->storage = $this->entityTypeManager->getStorage('entity_test_enhanced');
   }
 
   /**
    * Tests EntityQuery filtering.
    */
   public function testEntityQuery() {
-    // Admin permission, full access.
-    $admin_user = $this->createUser([], ['administer entity_test_enhanced']);
-    \Drupal::currentUser()->setAccount($admin_user);

This code is not equivalent. We were testing a user with the "administer entity_test_enhanced" permission, but now we are using uid 1 which satisfies any permission. That means that if there's a bug with fetching the admin permission from the entity type, it will no longer get caught.

dsdeiz’s picture

Status: Needs work » Needs review
StatusFileSize
new26.62 KB
new1009 bytes

Patch attached.

dsdeiz’s picture

StatusFileSize
new4.33 KB
new26.19 KB

Sorry, missed others.

  • bojanz committed e11c410 on 8.x-1.x
    Issue #3059103 by dsdeiz, paqu83, kavbiswa: Replace \Drupal with $this->...
bojanz’s picture

Status: Needs review » Fixed

Thanks, everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.