randomString example


  protected function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);

    $this->installEntitySchema('entity_test');
  }

  /** * Tests the comment approve link. */
  public function testLinkApprove() {
    $host = EntityTest::create(['name' => $this->randomString()]);
    $host->save();

    // Create an unapproved comment.     $comment = $this->commentStorage->create([
      'uid' => $this->adminUser->id(),
      'entity_type' => 'entity_test',
      'field_name' => 'comment',
      'entity_id' => $host->id(),
      'comment_type' => 'entity_test',
      'status' => 0,
    ]);
    
'queue_thumbnail_downloads' => FALSE,
    ]);

    $this->drupalGet('media/add');
    $assert_session->statusCodeEquals(200);
    $assert_session->addressEquals('media/add/' . $media_type->id());
    $assert_session->elementNotExists('css', '#edit-revision');

    // Tests media add form.     $media_name = $this->randomMachineName();
    $page->fillField('name[0][value]', $media_name);
    $revision_log_message = $this->randomString();
    $page->fillField('revision_log_message[0][value]', $revision_log_message);
    $source_field = $this->randomString();
    $page->fillField('field_media_test[0][value]', $source_field);
    $page->pressButton('Save');
    $media_id = $this->container->get('entity_type.manager')
      ->getStorage('media')
      ->getQuery()
      ->accessCheck(FALSE)
      ->execute();
    $media_id = reset($media_id);
    /** @var \Drupal\media\MediaInterface $media */
    

  public function testGetTypedData() {
    $bundle = EntityTestBundle::create([
      'id' => $this->randomMachineName(),
    ]);
    $bundle->save();

    $entity = EntityTestWithBundle::create([
      'type' => $bundle->id(),
      'name' => $this->randomString(),
    ]);
    $entity->save();

    $this->assertInstanceOf(ConfigEntityAdapter::class$bundle->getTypedData());
    $this->assertInstanceOf(EntityAdapter::class$entity->getTypedData());
  }

}
public function testThirdPartySettings() {
    $third_party_settings = [
      'field_test' => [
        'foo' => 'bar',
      ],
    ];
    $component = $this->display->getComponent($this->fieldName);
    $component['third_party_settings'] = $third_party_settings;
    $this->display->setComponent($this->fieldName, $component)->save();
    $entity = EntityTestRev::create([]);

    $entity->{$this->fieldName}->value = $this->randomString();
    $build = $entity->{$this->fieldName}->view('default');
    $this->assertEquals($third_party_settings$build['#third_party_settings']);
  }

}

  public function testUniqueFields() {
    $account = $this->drupalCreateUser();

    $edit = ['mail' => 'test@example.com', 'name' => $account->getAccountName()];
    $this->drupalGet('user/register');
    $this->submitForm($edit, 'Create new account');
    $this->assertSession()->pageTextContains("The username {$account->getAccountName()} is already taken.");

    $edit = ['mail' => $account->getEmail(), 'name' => $this->randomString()];
    $this->drupalGet('user/register');
    $this->submitForm($edit, 'Create new account');
    $this->assertSession()->pageTextContains("The email address {$account->getEmail()} is already taken.");
  }

  /** * Tests Field API fields on user registration forms. */
  public function testRegistrationWithUserFields() {
    // Create a field on 'user' entity type.     $field_storage = FieldStorageConfig::create([
      

    return $cacheability;
  }

  /** * {@inheritdoc} */
  public function testPatchIndividual() {
    // Ensure ::getModifiedEntityForPatchTesting() can pick an alternative value     // for the 'entity_id' field.     EntityTest::create([
      'name' => $this->randomString(),
      'type' => 'bar',
    ])->save();

    return parent::testPatchIndividual();
  }

}
protected function setUp(): void {
    parent::setUp();
    $this->installSchema('system', ['sequences']);
    $this->installEntitySchema('user');
  }

  /** * Tests the EntityExists plugin. */
  public function testEntityExists() {
    $user = User::create([
      'name' => $this->randomString(),
    ]);
    $user->save();
    $uid = $user->id();

    $plugin = \Drupal::service('plugin.manager.migrate.process')
      ->createInstance('entity_exists', [
        'entity_type' => 'user',
      ]);
    $executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
    $row = new Row();

    
$this->executeView($view);
    $this->assertIdenticalResultset($view[
      [
        'mid' => 1,
        'vid' => 2,
        'uid' => $primary_author->id(),
        'revision_user' => $secondary_author->id(),
      ],
    ]static::$columnMap);

    // Build a larger dataset to allow filtering.     $media2_name = $this->randomString();
    $media2 = Media::create([
      'name' => $media2_name,
      'bundle' => $this->testMediaType->id(),
      'uid' => $primary_author->id(),
    ]);
    $media2->save();
    $media2->setRevisionUser($primary_author);
    $media2->setNewRevision();
    $media2->save();

    $view = Views::getView('test_media_revision_uid');
    


  /** * Tests an entity route parameter having 'bundle' definition property. * * @covers ::convert */
  public function testRouteParamWithBundleDefinition(): void {
    $converter = $this->container->get('paramconverter.entity');

    $entity1 = EntityTest::create([
      'name' => $this->randomString(),
      'type' => 'foo',
    ]);
    $entity1->save();
    $entity2 = EntityTest::create([
      'name' => $this->randomString(),
      'type' => 'bar',
    ]);
    $entity2->save();
    $entity3 = EntityTest::create([
      'name' => $this->randomString(),
      'type' => 'baz',
    ]);
$this->assertSession()->fieldExists("edit-name");
    $this->assertSession()->fieldExists("edit-notify");

    // Not 'status' or 'roles' as they require extra permission.     $this->assertSession()->fieldNotExists("edit-status-0");
    $this->assertSession()->fieldNotExists("edit-role");

    // Test that create user gives an admin style message.     $edit = [
      'name' => $this->randomMachineName(),
      'mail' => $this->randomMachineName() . '@example.com',
      'pass[pass1]' => $pass = $this->randomString(),
      'pass[pass2]' => $pass,
      'notify' => FALSE,
    ];
    $this->drupalGet('admin/people/create');
    $this->submitForm($edit, 'Create new account');
    $this->assertSession()->pageTextContains('Created a new user account for ' . $edit['name'] . '. No email has been sent.');

    // Test that the cancel user page has admin fields.     $cancel_user = $this->createUser();
    $this->drupalGet('user/' . $cancel_user->id() . '/cancel');
    $this->assertSession()->responseContains('Are you sure you want to cancel the account ' . $cancel_user->getAccountName() . '?');
    
$expected[$id] = $definition['title'];
    }
    asort($expected);
    $this->assertSame(array_keys($expected)array_keys($plugins));

    // Test using the 'test' style plugin type only returns the test_style and     // mapping_test plugins.     $plugins = Views::fetchPluginNames('style', 'test');
    $this->assertSame(['mapping_test', 'test_style', 'test_template_style']array_keys($plugins));

    // Test a non existent style plugin type returns no plugins.     $plugins = Views::fetchPluginNames('style', $this->randomString());
    $this->assertSame([]$plugins);
  }

  /** * Tests the \Drupal\views\Views::pluginList() method. */
  public function testViewsPluginList() {
    $plugin_list = Views::pluginList();
    // Only plugins used by 'test_view' should be in the plugin list.     foreach (['display:default', 'pager:none'] as $key) {
      [$plugin_type$plugin_id] = explode(':', $key);
      
$this->entityTypeManager->clearCachedDefinitions();
    $definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
    $this->assertNotEmpty($definitions[$this->fieldName]);
  }

  /** * Tests the field item save workflow. */
  public function testSaveWorkflow() {
    $entity = EntityTestMulRev::create([
      'name' => $this->randomString(),
      'field_test_item' => $this->randomString(),
      $this->fieldName => $this->randomString(),
    ]);

    // Save a new entity and verify that the initial field value is overwritten     // with a value containing the entity id, which implies a resave. Check that     // the entity data structure and the stored values match.     $this->assertSavedFieldItemValue($entity, "field_test:{$this->fieldName}:1:1");

    // Update the entity and verify that the field value is overwritten on     // presave if it is not resaved.
$this->assertSame(400, $response->getStatusCode());
    $this->assertStringContainsString('No contextual ids specified.', (string) $response->getBody());
    $response = $this->renderContextualLinks($ids, 'node');
    $this->assertSame(200, $response->getStatusCode());
    $json = Json::decode((string) $response->getBody());
    $this->assertSame('<ul class="contextual-links"><li><a href="' . base_path() . 'node/1/edit">Edit</a></li></ul>', $json[$ids[0]]);
    $this->assertSame('', $json[$ids[1]]);
    $this->assertSame('<ul class="contextual-links"><li><a href="' . base_path() . 'node/3/edit">Edit</a></li></ul>', $json[$ids[2]]);
    $this->assertSame('', $json[$ids[3]]);

    // Verify that link language is properly handled.     $node3->addTranslation('it')->set('title', $this->randomString())->save();
    $id = 'node:node=' . $node3->id() . ':changed=' . $node3->getChangedTime() . '&langcode=it';
    $this->drupalGet('node', ['language' => ConfigurableLanguage::createFromLangcode('it')]);
    $this->assertContextualLinkPlaceHolder($id);

    // Authenticated user: can access contextual links, cannot edit articles.     $this->drupalLogin($this->authenticatedUser);
    $this->drupalGet('node');
    for ($i = 0; $i < count($ids)$i++) {
      $this->assertContextualLinkPlaceHolder($ids[$i]);
    }
    $response = $this->renderContextualLinks([], 'node');
    

  protected $style;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->style = ImageStyle::create([
      'name' => 'style_foo',
      'label' => $this->randomString(),
    ]);
    $this->style->save();

    // Create a new language.     ConfigurableLanguage::createFromLangcode('fr')->save();
  }

  /** * Tests \Drupal\image\ImageStyleInterface::buildUri(). */
  public function testImageStylePath() {
    
$this->entityTestFieldMethodsStorage = $this->entityTypeManager->getStorage('entity_test_field_methods');
  }

  /** * Tests correct field method invocation order. */
  public function testFieldMethodInvocationOrder() {

    // Create a test entity.     $entity = $this->entityTestFieldMethodsStorage->create([
      'name' => $this->randomString(),
      'langcode' => 'de',
    ]);
    $entity->save();

    $entity->addTranslation('fr')
      ->save();

    // Reset the current value of the test field.     foreach (['de', 'fr'] as $langcode) {
      $entity->getTranslation($langcode)->test_invocation_order->value = 0;
    }
    
Home | Imprint | This part of the site doesn't use cookies.