setUpFields example

// Create an account, which tests will use. Also ensure the @current_user     // service this account, to ensure certain access check logic in tests works     // as expected.     $this->account = $this->createUser();
    $this->container->get('current_user')->setAccount($this->account);

    // Create an entity.     $entity_type_manager = $this->container->get('entity_type.manager');
    $this->entityStorage = $entity_type_manager->getStorage(static::$entityTypeId);
    $this->uuidKey = $entity_type_manager->getDefinition(static::$entityTypeId)
      ->getKey('uuid');
    $this->entity = $this->setUpFields($this->createEntity()$this->account);

    $this->resourceType = $this->container->get('jsonapi.resource_type.repository')->getByTypeName(static::$resourceTypeName);
  }

  /** * Sets up additional fields for testing. * * @param \Drupal\Core\Entity\EntityInterface $entity * The primary test entity. * @param \Drupal\user\UserInterface $account * The primary test user account. * * @return \Drupal\Core\Entity\EntityInterface * The reloaded entity with the new fields attached. * * @throws \Drupal\Core\Entity\EntityStorageException */
/** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['field_test_views']): void {
    parent::setUp($import_test_views$modules);

    $this->account = $this->drupalCreateUser(['administer views']);
    $this->drupalLogin($this->account);

    $this->setUpFieldStorages(1, 'text');
    $this->setUpFields();
  }

  /** * Tests basic field handler settings in the UI. */
  public function testHandlerUI() {
    $url = "admin/structure/views/nojs/handler/test_view_fieldapi/default/field/field_name_0";
    $this->drupalGet($url);

    // Tests the available formatter options.     $options = $this->assertSession()->selectExists('edit-options-type')->findAll('css', 'option');
    
Home | Imprint | This part of the site doesn't use cookies.