I have a method of a class that returns me the list of fields that have been created outside of core Drupal. The method is the following.
/** * @param $contentType * @return array $fields */ public function getContentTypeFields($contentType) { /** @var DrupalCoreEntityEntityFieldManagerInterface $entityManager */ $entityManager = Drupal::service('entity_field.manager'); $fields = array(); if (!empty($contentType)) { $fields = array_filter( $entityManager->getFieldDefinitions('node', $contentType), function ($fieldDefinition) { return $fieldDefinition instanceof FieldConfigInterface; } ); } return $fields; }
It accepts a content type name and returns an array of fields that aren’t the default Drupal fields.
How can I write a unit Test for this method?