Skip to content

Commit 5f3c1f5

Browse files
committed
Use getAccountName. Check uid property.
1 parent 0ebf99a commit 5f3c1f5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Codeception/Module/DrupalUser.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Codeception\Module;
44

55
use Codeception\Module;
6+
use Drupal\Core\Config\StorageInterface;
7+
use Drupal\Core\Entity\EntityStorageInterface;
68
use Drupal\user\Entity\User;
79
use Faker\Factory;
810
use Codeception\Util\Drush;
@@ -158,7 +160,7 @@ public function logInAs($username) {
158160
public function logInWithRole($role) {
159161
$user = $this->createUserWithRoles([$role], Factory::create()->password(12, 14));
160162

161-
$this->logInAs($user->getUsername());
163+
$this->logInAs($user->getAccountName());
162164

163165
return $user;
164166
}
@@ -198,14 +200,21 @@ private function deleteUsersContent($uid) {
198200
continue;
199201
}
200202
try {
203+
/** @var EntityStorageInterface $storage */
201204
$storage = \Drupal::entityTypeManager()->getStorage($cleanup_entity);
202205
}
203206
catch (\Exception $e) {
204207
$errors[] = 'Could not load storage ' . $cleanup_entity;
205208
continue;
206209
}
207210
try {
208-
$entities = $storage->loadByProperties(['uid' => $uid]);
211+
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($cleanup_entity);
212+
foreach ($bundles as $bundle) {
213+
$all_bundle_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions($cleanup_entity, $bundle);
214+
if (isset($all_bundle_fields['uid'])) {
215+
$entities = $storage->loadByProperties(['uid' => $uid]);
216+
}
217+
}
209218
}
210219
catch (\Exception $e) {
211220
$errors[] = 'Could not load entities of type ' . $cleanup_entity . ' by uid ' . $uid;

0 commit comments

Comments
 (0)