diff --git a/src/Tests/UserEmotionTest.php b/src/Tests/UserEmotionTest.php index 9717c78..d0cb571 100644 --- a/src/Tests/UserEmotionTest.php +++ b/src/Tests/UserEmotionTest.php @@ -29,11 +29,18 @@ class UserEmotionTest extends WebTestBase { /** * A user with permission to create content and upload images. * - * @var object + * @var \Drupal\user\UserInterface */ protected $adminUser; /** + * Retrieves the entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManager + */ + protected $entityTypeManager; + + /** * {@inheritdoc} */ protected function setUp() { @@ -47,6 +54,8 @@ class UserEmotionTest extends WebTestBase { 'administer users', ]); $this->drupalLogin($this->adminUser); + + $this->entityTypeManager = \Drupal::entityTypeManager(); } /** @@ -88,7 +97,7 @@ class UserEmotionTest extends WebTestBase { ])->addConstraint('UserEmotion'); $field_config->save(); - $form_display = \Drupal::entityTypeManager() + $form_display = $this->entityTypeManager ->getStorage('entity_form_display') ->load($entity_type . '.' . $type_name . '.' . 'default'); if (!$form_display) { @@ -98,7 +107,7 @@ class UserEmotionTest extends WebTestBase { 'mode' => 'default', 'status' => TRUE, ]; - $form_display = \Drupal::entityTypeManager() + $form_display = $this->entityTypeManager ->getStorage('entity_form_display') ->create($values); } @@ -107,7 +116,7 @@ class UserEmotionTest extends WebTestBase { 'settings' => $widget_settings, ])->save(); - $display = \Drupal::entityTypeManager() + $display = $this->entityTypeManager ->getStorage('entity_view_display') ->load($entity_type . '.' . $type_name . '.' . 'default'); @@ -118,7 +127,7 @@ class UserEmotionTest extends WebTestBase { 'mode' => 'default', 'status' => TRUE, ]; - $display = \Drupal::entityTypeManager() + $display = $this->entityTypeManager ->getStorage('entity_view_display') ->create($values); } @@ -161,6 +170,7 @@ class UserEmotionTest extends WebTestBase { ]; $field = $this->createImageField('images', $entity_type, $type, $storage_settings, $field_settings, $widget_settings); + // Get the field id and return it. $field_id = $field->id(); return $field_id; } @@ -199,12 +209,13 @@ class UserEmotionTest extends WebTestBase { * Detection is disabled. */ public function testNoUserEmotionDetection() { + // Create an image field for the user picture and get its id. $field_id = $this->getImageFieldId('user', 'user'); // Ensuring that the Emotion Detection feature is disabled. - $this->drupalGet("admin/config/people/accounts/fields/$field_id"); - $user_name = $this->createUserWithProfilePicture(); + $this->drupalGet('admin/config/people/accounts/fields/' . $field_id); + $username = $this->createUserWithProfilePicture(); $this->assertNoText('Please upload a photo where you are smiling and happy'); - $this->assertText("Created a new user account for $user_name. No email has been sent"); + $this->assertText("Created a new user account for $username. No email has been sent"); } /** @@ -212,15 +223,17 @@ class UserEmotionTest extends WebTestBase { * enabled. */ public function testUserEmotionDetection() { + // Create an image field for the user picture and get its id. $field_id = $this->getImageFieldId('user', 'user'); // Enabling the Emotion Detection feature. $edit = [ 'emotion_detect' => 1, ]; - $this->drupalPostForm("admin/config/people/accounts/fields/$field_id", $edit, t('Save settings')); - $this->drupalGet("admin/config/people/accounts/fields/$field_id"); - $user_name = $this->createUserWithProfilePicture(); + $this->drupalPostForm('admin/config/people/accounts/fields/' . $field_id, $edit, t('Save settings')); + // Ensuring that the Emotion Detection feature is enabled. + $this->drupalGet('admin/config/people/accounts/fields/' . $field_id); + $username = $this->createUserWithProfilePicture(); $this->assertText('Please upload a photo where you are smiling and happy'); - $this->assertText("Created a new user account for $user_name. No email has been sent"); + $this->assertText("Created a new user account for $username. No email has been sent"); } }