drupalGet example

/** * Tests creating a 'block_content' entity view. */
  public function testViewAddBlockContent() {
    $view = [];
    $view['label'] = $this->randomMachineName(16);
    $view['id'] = strtolower($this->randomMachineName(16));
    $view['description'] = $this->randomMachineName(16);
    $view['page[create]'] = FALSE;
    $view['show[wizard_key]'] = 'block_content';
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Save and edit');

    $view_storage_controller = $this->container->get('entity_type.manager')->getStorage('view');
    /** @var \Drupal\views\Entity\View $view */
    $view = $view_storage_controller->load($view['id']);

    $display_options = $view->getDisplay('default')['display_options'];

    $this->assertEquals('block_content', $display_options['filters']['reusable']['entity_type']);
    $this->assertEquals('reusable', $display_options['filters']['reusable']['entity_field']);
    $this->assertEquals('boolean', $display_options['filters']['reusable']['plugin_id']);
    
'administer entity_test display',
      'administer entity_test form display',
      'view the administration theme',
    ]));
  }

  /** * Tests that layouts are unique per view mode. */
  public function testEntityViewModes() {
    // By default, the field is not visible.     $this->drupalGet('entity_test/1/test');
    $this->assertSession()->elementNotExists('css', '.layout__region--content ');
    $this->drupalGet('entity_test/1');
    $this->assertSession()->elementNotExists('css', '.layout__region--content');

    // Change the layout for the "test" view mode. See     // core.entity_view_mode.entity_test.test.yml.     $this->drupalGet('entity_test/structure/entity_test/display');
    $this->click('#edit-modes');
    $this->getSession()->getPage()->checkField('display_modes_custom[test]');
    $this->submitForm([], 'Save');
    $this->clickLink('configure them');
    
'administer entity_test fields',
      'administer entity_test display',
      'administer entity_test form display',
      'view the administration theme',
    ]));
  }

  /** * Tests the use of regions for entity form displays. */
  public function testEntityForm() {
    $this->drupalGet('entity_test/manage/1/edit');
    $this->assertSession()->fieldExists('field_test_text[0][value]');

    $this->drupalGet('entity_test/structure/entity_test/form-display');
    $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
    $this->getSession()->getPage()->pressButton('Show row weights');
    $this->assertSession()->waitForElementVisible('css', '[name="fields[field_test_text][region]"]');
    $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'hidden');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());

    $this->submitForm([], 'Save');
    
->set('default', 'olivero')
      ->set('admin', 'claro')
      ->save();

    // Log in as an administrator who can see the administrative theme.     $admin_user = $this->drupalCreateUser(['view the administration theme']);
    $this->drupalLogin($admin_user);
    // Visit an administrative page that runs a test batch, and check that the     // theme that was used during batch execution (which the batch callback     // function saved as a variable) matches the theme used on the     // administrative page.     $this->drupalGet('admin/batch-test/test-theme');
    // The stack should contain the name of the theme used on the progress     // page.     $this->assertEquals(['claro']batch_test_stack(), 'A progressive batch correctly uses the theme of the page that started the batch.');
  }

  /** * Tests that the batch API progress page shows the title correctly. */
  public function testBatchProgressPageTitle() {
    // Visit an administrative page that runs a test batch, and check that the     // title shown during batch execution (which the batch callback function
// Check that at least one module implements hook_node_grants() as this test     // only tests this case.     // @see \node_test_node_grants()     $this->assertTrue(\Drupal::moduleHandler()->hasImplementations('node_grants'));

    // Create an unpublished node.     $referenced = $this->createNode(['status' => FALSE]);
    // Create a node referencing $referenced.     $node = $this->createNode(['ref' => $referenced]);

    // Check that the referenced entity link doesn't show on the host entity.     $this->drupalGet($node->toUrl());
    $this->assertSession()->linkNotExists($referenced->label());

    // Publish the referenced node.     $referenced->setPublished()->save();

    // Check that the referenced entity link shows on the host entity.     $this->getSession()->reload();
    $this->assertSession()->linkExists($referenced->label());
  }

}
// Set page revision setting 'create new revision'. This will mean new     // revisions are created by default when the node is edited.     $type = NodeType::load('page');
    $type->setNewRevision(TRUE);
    $type->save();

    // Create the node.     $node = $this->drupalCreateNode();

    // Verify the checkbox is checked on the node edit form.     $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->checkboxChecked('edit-revision');

    // Uncheck the create new revision checkbox and save the node.     $edit = ['revision' => FALSE];
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save');

    // Load the node again and check the revision is the same as before.     $node_storage->resetCache([$node->id()]);
    $node_revision = $node_storage->load($node->id(), TRUE);
    $this->assertEquals($node->getRevisionId()$node_revision->getRevisionId(), "After an existing node is saved with 'Create new revision' unchecked, a new revision is not created.");

    
// @todo Remove this line once https://www.drupal.org/node/2945928 is fixed.     $this->config('node.settings')->set('use_admin_theme', '1')->save();
  }

  /** * Enables content moderation for the test entity type and bundle. */
  protected function enableContentModeration() {
    $this->drupalLogin($this->rootUser);
    $workflow_id = 'editorial';
    $this->drupalGet('/admin/config/workflow/workflows');
    $edit['bundles[' . $this->bundle . ']'] = TRUE;
    $this->drupalGet('admin/config/workflow/workflows/manage/' . $workflow_id . '/type/' . $this->entityTypeId);
    $this->submitForm($edit, 'Save');
    // Ensure the parent environment is up-to-date.     // @see content_moderation_workflow_insert()     \Drupal::service('entity_type.bundle.info')->clearCachedBundles();
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
    $router_builder = $this->container->get('router.builder');
    $router_builder->rebuildIfNeeded();
  }

  
/** * Gets counter of views by path. * * @param string $path * A path to node. * * @return int|null * A counter of views. Returns NULL if the page does not contain statistics. */
  protected function getStatisticsCounter($path) {
    $this->drupalGet($path);
    // Wait while statistics module send ajax request.     $this->assertSession()->assertWaitOnAjaxRequest();
    // Resaving the node to call the hook_node_links_alter(), which is used to     // update information on the page. See statistics_node_links_alter().     $this->node->save();

    $field_counter = $this->getSession()->getPage()->find('css', '.links li');
    return $field_counter ? (int) explode(' ', $field_counter->getText())[0] : NULL;
  }

}

  }

  /** * Tests the "New forum topics" block. */
  public function testNewForumTopicsBlock() {
    $this->drupalLogin($this->adminUser);

    // Enable the new forum topics block.     $block = $this->drupalPlaceBlock('forum_new_block');
    $this->drupalGet('');

    // Create 5 forum topics.     $topics = $this->createForumTopics();

    $this->assertSession()->linkExists('More', 0, 'New forum topics block has a "more"-link.');
    $this->assertSession()->linkByHrefExists('forum', 0, 'New forum topics block has a "more"-link.');

    // We expect all 5 forum topics to appear in the "New forum topics" block.     foreach ($topics as $topic) {
      $this->assertSession()->linkExists($topic, 0, new FormattableMarkup('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topic]));
    }

    
'settings' => [
        'match_operator' => 'CONTAINS',
      ],
    ]);
    // To satisfy config schema, the size setting must be an integer, not just     // a numeric value. See https://www.drupal.org/node/2885441.     $this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);
    $form_display->save();
    $this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);

    // Visit the node add page.     $this->drupalGet('node/add/page');
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $autocomplete_field = $assert_session->waitForElement('css', '[name="' . $field_name . '[0][target_id]"].ui-autocomplete-input');
    $autocomplete_field->setValue('Test');
    $this->getSession()->getDriver()->keyDown($autocomplete_field->getXpath(), ' ');
    $assert_session->waitOnAutocomplete();

    $results = $page->findAll('css', '.ui-autocomplete li');

    $this->assertCount(2, $results);
    
$assert_session = $this->assertSession();

    // Allow the anonymous user to create pages and view media.     $role = Role::load(RoleInterface::ANONYMOUS_ID);
    $this->grantPermissions($role[
      'access content',
      'create basic_page content',
      'view media',
    ]);

    // Ensure the widget works as an anonymous user.     $this->drupalGet('node/add/basic_page');

    // Add to the unlimited cardinality field.     $this->openMediaLibraryForField('field_unlimited_media');

    // Select the first media item (should be Dog).     $this->selectMediaItem(0);
    $this->pressInsertSelected('Added one media item.');

    // Ensure that the selection completed successfully.     $this->waitForText('Dog');
    $assert_session->fieldNotExists('Weight');

    

  protected function uploadImage($uri) {
    $edit = [
      'files[fid]' => \Drupal::service('file_system')->realpath($uri),
    ];
    $this->drupalGet('editor/dialog/image/basic_html');
    $this->drupalGet('editor/dialog/image/basic_html');
    $this->submitForm($edit, 'Upload');
    $uploaded_image_file = $this->container->get('image.factory')->get('public://inline-images/' . basename($uri));
    return [
      (int) $uploaded_image_file->getWidth(),
      (int) $uploaded_image_file->getHeight(),
    ];
  }

  /** * Asserts whether the saved maximum dimensions equal the ones provided. * * @param int|null $width * The expected width of the uploaded image. * @param int|null $height * The expected height of the uploaded image. * * @internal */
// Create custom fields for the media type to store metadata attributes.     $fields = [
      'field_string_file_size' => 'string',
      'field_string_mime_type' => 'string',
    ];
    $this->createMediaTypeFields($fields$media_type_id);

    // Hide the name field widget to test default name generation.     $this->hideMediaTypeFieldWidget('name', $media_type_id);

    $this->drupalGet("admin/structure/media/manage/{$media_type_id}");
    $page->selectFieldOption("field_map[" . File::METADATA_ATTRIBUTE_NAME . "]", 'name');
    $page->selectFieldOption("field_map[" . File::METADATA_ATTRIBUTE_SIZE . "]", 'field_string_file_size');
    $page->selectFieldOption("field_map[" . File::METADATA_ATTRIBUTE_MIME . "]", 'field_string_mime_type');
    $page->pressButton('Save');

    $test_filename = $this->randomMachineName() . '.txt';
    $test_filepath = 'public://' . $test_filename;
    file_put_contents($test_filepath$this->randomMachineName());

    // Create a media item.     $this->drupalGet("media/add/{$media_type_id}");
    
    $body_text = 'The Enricþment Center is cómmīŦŧęđ to the well BɆĬŇĜ of æll påŔťıçȉpǎǹţș. ';
    $body_text .= 'Also meklēt (see #731298)';
    $this->drupalCreateNode(['body' => [['value' => $body_text]]]);

    // Update the search index.     $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();

    // Refresh variables after the treatment.     $this->refreshVariables();

    $edit = ['keys' => 'meklet'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->responseContains('<strong>meklēt</strong>');

    $edit = ['keys' => 'meklēt'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->responseContains('<strong>meklēt</strong>');

    $edit = ['keys' => 'cómmīŦŧęđ BɆĬŇĜ påŔťıçȉpǎǹţș'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests theme preprocess functions being able to attach assets. */
  public function testEarlyRendering() {
    // Render array: non-early & early.     $this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array'));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Hello world!');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'foo');
    $this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array.early'));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Hello world!');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'foo');

    // AjaxResponse: non-early & early.     // @todo Add cache tags assertion when AjaxResponse is made cacheable in     // https://www.drupal.org/node/956186.
Home | Imprint | This part of the site doesn't use cookies.