randomMachineName example



  /** * Tests the block listing for the translate operation. * * There are no blocks placed in the testing profile. Add one, then check * for Translate operation. */
  protected function doBlockListTest() {
    // Add a test block, any block will do.     // Set the machine name so the translate link can be built later.     $id = mb_strtolower($this->randomMachineName(16));
    $this->drupalPlaceBlock('system_powered_by_block', ['id' => $id]);

    // Get the Block listing.     $this->drupalGet('admin/structure/block');

    $translate_link = 'admin/structure/block/manage/' . $id . '/translate';
    // Test if the link to translate the block is on the page.     $this->assertSession()->linkByHrefExists($translate_link);

    // Test if the link to translate actually goes to the translate page.     $this->drupalGet($translate_link);
    
'access administration pages',
    ]);
    $this->drupalLogin($web_user);
  }

  /** * Tests alias functionality through the admin interfaces. */
  public function testTermAlias() {
    // Create a term in the default 'Tags' vocabulary with URL alias.     $vocabulary = Vocabulary::load('tags');
    $description = $this->randomMachineName();
    $edit = [
      'name[0][value]' => $this->randomMachineName(),
      'description[0][value]' => $description,
      'path[0][alias]' => '/' . $this->randomMachineName(),
    ];
    $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
    $this->submitForm($edit, 'Save');
    $tids = \Drupal::entityQuery('taxonomy_term')
      ->accessCheck(FALSE)
      ->condition('name', $edit['name[0][value]'])
      ->condition('default_langcode', 1)
      

  public function testDisplayConfigurable() {
    // Add a comment.     $nid = $this->node->id();
    /** @var \Drupal\comment\CommentInterface $comment */
    $comment = Comment::create([
      'entity_id' => $nid,
      'entity_type' => 'node',
      'field_name' => 'comment',
      'uid' => $this->webUser->id(),
      'status' => CommentInterface::PUBLISHED,
      'subject' => $this->randomMachineName(),
      'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      'comment_body' => [LanguageInterface::LANGCODE_NOT_SPECIFIED => [$this->randomMachineName()]],
    ]);
    $comment->save();
    $assert = $this->assertSession();

    // Check the comment author with Drupal default non-configurable display.     $this->drupalGet('node/' . $nid);
    $assert->elementExists('css', 'p.comment__author span');

    // Enable module to make base fields' displays configurable.
$this->field = FieldConfig::create([
      'field_name' => $field_name,
      'entity_type' => 'entity_test_rev',
      'bundle' => 'entity_test_rev',
      'required' => TRUE,
    ]);
    $this->field->save();

    // Create an entity with field data.     $this->entity = EntityTestRev::create([
      'user_id' => mt_rand(1, 10),
      'name' => $this->randomMachineName(),
      $field_name => $this->randomString(),
    ]);
    $this->entity->save();
  }

  /** * Tests that column-level schema changes are detected for fields with data. */
  public function testColumnUpdate() {
    // Change the field type in the stored schema.     $schema = \Drupal::keyValue('entity.storage_schema.sql')->get('entity_test_rev.field_schema_data.test');
    

      // Bug 3097338, paragraphs were appearing around drupalmedia tags.       '<drupal-media data-caption=" " data-entity-type="media" data-entity-uuid="dbb16f97-cd11-4357-acde-cd09e19e312b"></drupal-media>' => [
        '<p><drupal-media data-caption=" " data-entity-type="media" data-entity-uuid="dbb16f97-cd11-4357-acde-cd09e19e312b"></drupal-media></p>' => FALSE,
      ],
    ];
    // cSpell:enable     $this->assertFilteredString($filter$tests);

    // Very long string hitting PCRE limits.     $limit = max(ini_get('pcre.backtrack_limit')ini_get('pcre.recursion_limit'));
    $source = $this->randomMachineName($limit);
    $result = _filter_autop($source);
    $this->assertEquals($result, '<p>' . $source . "</p>\n", 'Line break filter can process very long strings.');
  }

  /** * Tests filter settings, defaults, access restrictions and similar. * * @todo This is for functions like filter_filter and check_markup, whose * functionality is not completely focused on filtering. Some ideas: * restricting formats according to user permissions, proper cache * handling, defaults -- allowed tags/attributes/protocols. * * @todo It is possible to add script, iframe etc. to allowed tags, but this * makes HTML filter completely ineffective. * * @todo Class, id, name and xmlns should be added to the list of forbidden * attributes, or, better yet, use an allowed attribute list. */
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->installEntitySchema('node');
    $this->installEntitySchema('taxonomy_term');
    $this->installEntitySchema('entity_test');

    $this->nodeType = NodeType::create([
      'type' => mb_strtolower($this->randomMachineName()),
      'name' => $this->randomString(),
    ]);
    $this->nodeType->save();

    // Create a custom bundle.     $this->customBundle = 'test_bundle_' . mb_strtolower($this->randomMachineName());
    entity_test_create_bundle($this->customBundle, NULL, 'entity_test');

    // Prepare the logger for collecting the expected critical error.     $this->container->get($this->testLogServiceName)->cleanLogs();
  }

  
$this->serializer = $this->container->get('jsonapi.serializer');
    $this->cacher = $this->container->get('jsonapi.normalization_cacher');
  }

  /** * Tests that link normalization cache information is not lost. * * @see https://www.drupal.org/project/drupal/issues/3077287 */
  public function testLinkNormalizationCacheability() {
    $user = User::create([
      'name' => $this->randomMachineName(),
      'pass' => $this->randomString(),
    ]);
    $user->save();
    $resource_type = $this->resourceTypeRepository->get($user->getEntityTypeId()$user->bundle());
    $resource_object = ResourceObject::createFromEntity($resource_type$user);
    $cache_tag_to_invalidate = 'link_normalization';
    $normalized_links = $this->serializer
      ->normalize($resource_object->getLinks(), 'api_json')
      ->withCacheableDependency((new CacheableMetadata())->addCacheTags([$cache_tag_to_invalidate]));
    assert($normalized_links instanceof CacheableNormalization);
    $normalization_parts = [
      
parent::setUp($import_test_views$modules);
    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    // Add comment field to page node type.     $this->addDefaultCommentField('node', 'page');
  }

  /** * Tests adding a view of comments. */
  public function testCommentWizard() {
    $view = [];
    $view['label'] = $this->randomMachineName(16);
    $view['id'] = strtolower($this->randomMachineName(16));
    $view['show[wizard_key]'] = 'comment';
    $view['page[create]'] = TRUE;
    $view['page[path]'] = $this->randomMachineName(16);

    // Just triggering the saving should automatically choose a proper row     // plugin.     $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Save and edit');
    // Verify that the view saving was successful and the browser got redirected     // to the edit page.

  public function previewNodeImage($image$field_name$type) {
    $edit = [
      'title[0][value]' => $this->randomMachineName(),
    ];
    $edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
    $this->drupalGet('node/add/' . $type);
    $this->submitForm($edit, 'Preview');
  }

  /** * Upload an image to a node. * * @param $image * A file object representing the image to upload. * @param $field_name * Name of the image field the image should be attached to. * @param $type * The type of node to create. * @param $alt * The alt text for the image. Use if the field settings require alt text. */
$this->fieldUninstallValidator->setStringTranslation($this->getStringTranslationStub());
  }

  /** * @covers ::validate */
  public function testValidateNoStorages() {
    $this->fieldUninstallValidator->expects($this->once())
      ->method('getFieldStoragesByModule')
      ->willReturn([]);

    $module = $this->randomMachineName();
    $expected = [];
    $reasons = $this->fieldUninstallValidator->validate($module);
    $this->assertEquals($expected$reasons);
  }

  /** * @covers ::validate */
  public function testValidateDeleted() {
    $field_storage = $this->getMockBuilder('Drupal\field\Entity\FieldStorageConfig')
      ->disableOriginalConstructor()
      

  public function testSupportsDenormalization() {
    $this->assertTrue($this->normalizer->supportsDenormalization($this->data->reveal(), DateTimeIso8601::class));
  }

  /** * @covers ::normalize * @dataProvider providerTestNormalize */
  public function testNormalize($parent_field_item_class$datetime_type$expected_format) {
    $formatted_string = $this->randomMachineName();

    $field_item = $this->prophesize($parent_field_item_class);
    if ($parent_field_item_class === DateTimeItem::class) {
      $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
      $field_storage_definition->getSetting('datetime_type')
        ->willReturn($datetime_type);
      $field_definition = $this->prophesize(FieldDefinitionInterface::class);
      $field_definition->getFieldStorageDefinition()
        ->willReturn($field_storage_definition);
      $field_item->getFieldDefinition()
        ->willReturn($field_definition);
    }
'display_options' => ['path' => 'test/%/extra'],
        'display_plugin' => 'page',
        'id' => 'page_2',
        'display_title' => 'Page 2',
        'position' => 3,
      ],
    ];
    $view = $this->controller->create($config);

    // Tests Drupal\views\Entity\View::addDisplay()     $view = $this->controller->create([]);
    $random_title = $this->randomMachineName();

    $id = $view->addDisplay('page', $random_title);
    $this->assertEquals('page_1', $idnew FormattableMarkup('Make sure the first display (%id_new) has the expected ID (%id)', ['%id_new' => $id, '%id' => 'page_1']));
    $display = $view->get('display');
    $this->assertEquals($random_title$display[$id]['display_title']);

    $random_title = $this->randomMachineName();
    $id = $view->addDisplay('page', $random_title);
    $display = $view->get('display');
    $this->assertEquals('page_2', $idnew FormattableMarkup('Make sure the second display (%id_new) has the expected ID (%id)', ['%id_new' => $id, '%id' => 'page_2']));
    $this->assertEquals($random_title$display[$id]['display_title']);

    
// Populate values to be displayed.     $values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality());
    $entity_init->{$this->fieldTestData->field_name}->setValue($values);
    $values_2 = $this->_generateTestFieldValues($this->fieldTestData->field_storage_2->getCardinality());
    $entity_init->{$this->fieldTestData->field_name_2}->setValue($values_2);

    // Simple formatter, label displayed.     $entity = clone($entity_init);
    $display = \Drupal::service('entity_display.repository')
      ->getViewDisplay($entity_type$entity->bundle(), 'full');

    $formatter_setting = $this->randomMachineName();
    $display_options = [
      'label' => 'above',
      'type' => 'field_test_default',
      'settings' => [
        'test_formatter_setting' => $formatter_setting,
      ],
    ];
    $display->setComponent($this->fieldTestData->field_name, $display_options);

    $formatter_setting_2 = $this->randomMachineName();
    $display_options_2 = [
      

  protected function placeBlock($plugin_id, array $settings = []) {
    $config = \Drupal::configFactory();
    $settings += [
      'plugin' => $plugin_id,
      'region' => 'content',
      'id' => strtolower($this->randomMachineName(8)),
      'theme' => $config->get('system.theme')->get('default'),
      'label' => $this->randomMachineName(8),
      'visibility' => [],
      'weight' => 0,
    ];
    $values = [];
    foreach (['region', 'id', 'theme', 'plugin', 'weight', 'visibility'] as $key) {
      $values[$key] = $settings[$key];
      // Remove extra values that do not belong in the settings array.       unset($settings[$key]);
    }
    

  protected function setUp(): void {
    parent::setUp();

    $this->id = 1;
    $values = [
      'id' => $this->id,
      'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a',
      'defaultLangcode' => [LanguageInterface::LANGCODE_DEFAULT => 'en'],
    ];
    $this->entityTypeId = $this->randomMachineName();
    $this->bundle = $this->randomMachineName();

    $this->entityType = $this->createMock('\Drupal\Core\Entity\EntityTypeInterface');
    $this->entityType->expects($this->any())
      ->method('getKeys')
      ->willReturn([
        'id' => 'id',
        'uuid' => 'uuid',
      ]);

    $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    
Home | Imprint | This part of the site doesn't use cookies.