pageTextContains example

parent::setUp($import_test_views$modules);

    $this->drupalPlaceBlock('page_title_block');
  }

  public function testViewsWizardAndListing() {
    $this->drupalCreateContentType(['type' => 'article']);
    $this->drupalCreateContentType(['type' => 'page']);

    // Check if we can access the main views admin page.     $this->drupalGet('admin/structure/views');
    $this->assertSession()->pageTextContains('Add view');

    // Create a simple and not at all useful view.     $view1 = [];
    $view1['label'] = $this->randomMachineName(16);
    $view1['id'] = strtolower($this->randomMachineName(16));
    $view1['description'] = $this->randomMachineName(16);
    $view1['page[create]'] = FALSE;
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view1, 'Save and edit');
    $this->assertSession()->statusCodeEquals(200);
    $this->drupalGet('admin/structure/views');
    

    $this->drupalLogin($admin_user);

    $types = ['header', 'footer', 'empty'];
    $labels = [];
    foreach ($types as $type) {
      $edit_path = 'admin/structure/views/nojs/handler/test_example_area/default/' . $type . '/test_example';

      // First setup an empty label.       $this->drupalGet($edit_path);
      $this->submitForm([], 'Apply');
      $this->assertSession()->pageTextContains('Test Example area');

      // Then setup a no empty label.       $labels[$type] = $this->randomMachineName();
      $this->drupalGet($edit_path);
      $this->submitForm(['options[admin_label]' => $labels[$type]], 'Apply');
      // Make sure that the new label appears on the site.       $this->assertSession()->pageTextContains($labels[$type]);

      // Test that the settings (empty/admin_label) are accessible.       $this->drupalGet($edit_path);
      $this->assertSession()->fieldExists('options[admin_label]');
      
protected $defaultTheme = 'stark';

  /** * Tests using an object as the form callback. * * @see \Drupal\form_test\EventSubscriber\FormTestEventSubscriber::onKernelRequest() */
  public function testObjectFormCallback() {
    $config_factory = $this->container->get('config.factory');

    $this->drupalGet('form-test/object-builder');
    $this->assertSession()->pageTextContains('The FormTestObject::buildForm() method was used for this form.');
    $this->assertSession()->elementExists('xpath', '//form[@id="form-test-form-test-object"]');
    $this->submitForm(['bananas' => 'green'], 'Save');
    $this->assertSession()->pageTextContains('The FormTestObject::validateForm() method was used for this form.');
    $this->assertSession()->pageTextContains('The FormTestObject::submitForm() method was used for this form.');
    $value = $config_factory->get('form_test.object')->get('bananas');
    $this->assertSame('green', $value);

    $this->drupalGet('form-test/object-arguments-builder/yellow');
    $this->assertSession()->pageTextContains('The FormTestArgumentsObject::buildForm() method was used for this form.');
    $this->assertSession()->elementExists('xpath', '//form[@id="form-test-form-test-arguments-object"]');
    $this->submitForm([], 'Save');
    
$this->assertFieldValues($entity_1, 'field_unlimited', [2, 3]);
    $this->assertFieldValues($entity_2, 'field_single', [11]);
    $this->assertFieldValues($entity_2, 'field_unlimited', [12, 13]);

    // Submit invalid values and check that errors are reported on the     // correct widgets.     $edit = [
      'field_unlimited[1][value]' => -1,
    ];
    $this->drupalGet('test-entity/nested/1/2');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains("Unlimited field does not accept the value -1.");
    // Entity 1: check that the error was flagged on the correct element.     $error_field = $this->assertSession()->fieldExists('edit-field-unlimited-1-value');
    $this->assertTrue($error_field->hasClass('error'));
    $edit = [
      'entity_2[field_unlimited][1][value]' => -1,
    ];
    $this->drupalGet('test-entity/nested/1/2');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains("Unlimited field does not accept the value -1.");
    // Entity 2: check that the error was flagged on the correct element.     $error_field = $this->assertSession()->fieldExists('edit-entity-2-field-unlimited-1-value');
    
// Visit the Help page and make sure no warnings or notices are thrown.     $this->drupalGet('admin/help/field');

    // Enable the Options, Email and Field API Test modules.     \Drupal::service('module_installer')->install(['options', 'field_test']);

    $this->drupalGet('admin/help/field');
    $this->assertSession()->linkExists('Options', 0, 'Options module is listed on the Field help page.');
    // Verify that modules with field types that do not implement hook_help are     // listed.     $this->assertSession()->pageTextContains('Field API Test');
    $this->assertSession()->linkNotExists('Field API Test', 'Modules with field types that do not implement hook_help are not linked.');
    $this->assertSession()->linkNotExists('Link', 'Modules that have not been installed, are not listed.');
  }

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

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

    // Submit a phrase wrapped in double quotes to include the punctuation.     $edit = ['keys' => '"bunny\'s"'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->pageTextContains($node->label());

    // Check if the author is linked correctly to the user profile page.     $username = $node->getOwner()->getAccountName();
    $this->assertSession()->linkExists($username);

    // Search for "&" and verify entities are not broken up in the output.     $edit = ['keys' => '&'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->responseNotContains('<strong>&</strong>amp;');
    $this->assertSession()->statusMessageContains('You must include at least one keyword', 'warning');

    
$settings['test_view_field'] = [['value' => $this->testViewFieldValue]];
    $this->node = $this->drupalCreateNode($settings);
  }

  /** * Tests that hook_entity_field_access() is called. */
  public function testFieldAccess() {

    // Assert the text is visible.     $this->drupalGet('node/' . $this->node->id());
    $this->assertSession()->pageTextContains($this->testViewFieldValue);

    // Assert the text is not visible for anonymous users.     // The field_test module implements hook_entity_field_access() which will     // specifically target the 'test_view_field' field.     $this->drupalLogout();
    $this->drupalGet('node/' . $this->node->id());
    $this->assertSession()->pageTextNotContains($this->testViewFieldValue);
  }

}

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

    // Visit a Drupal page that requires login.     $this->drupalGet('test-page');
    $this->assertSession()->statusCodeEquals(200);

    // Test page contains some text.     $this->assertSession()->pageTextContains('Test page text.');

    // Check that returned plain text is correct.     $text = $this->getTextContent();
    $this->assertStringContainsString('Test page text.', $text);
    $this->assertStringNotContainsString('</html>', $text);
    // Ensure Drupal Javascript settings are not part of the page text.     $this->assertArrayHasKey('currentPathIsAdmin', $this->getDrupalSettings()['path']);
    $this->assertStringNotContainsString('currentPathIsAdmin', $text);

    // Response includes cache tags that we can assert.     $this->assertSession()->responseHeaderExists('X-Drupal-Cache-Tags');
    
// Delete all blocks and verify saving the block layout results in a     // validation error.     $block_storage = \Drupal::service('entity_type.manager')->getStorage('block');
    $blocks = $block_storage->loadMultiple();
    foreach ($blocks as $block) {
      $block->delete();
    }
    $this->drupalGet('admin/structure/block');
    $blocks_table = $this->xpath("//tr[@class='block-enabled']");
    $this->assertEmpty($blocks_table, 'The blocks table is now empty.');
    $this->submitForm([], 'Save blocks');
    $this->assertSession()->pageTextContains('No blocks settings to update');

  }

  /** * Tests block admin page exists and functions correctly. */
  public function testBlockAdminUiPage() {
    // Visit the blocks admin ui.     $this->drupalGet('admin/structure/block');
    // Look for the blocks table.     $this->assertSession()->elementExists('xpath', "//table[@id='blocks']");
    
// Submit a valid date and ensure it is accepted.       $date_format = DateFormat::load('html_date')->getPattern();
      $time_format = DateFormat::load('html_time')->getPattern();

      $edit = [
        "{$field_name}[0][value][date]" => $date->format($date_format),
      ];
      $this->submitForm($edit, 'Save');
      preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
      $id = $match[1];
      $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been created.');
      $this->assertSession()->responseContains($date->format($date_format));
      $this->assertSession()->responseNotContains($date->format($time_format));

      // Verify the date doesn't change if using a timezone that is UTC+12 when       // the entity is edited through the form.       $entity = EntityTest::load($id);
      $this->assertEquals('2012-12-31', $entity->{$field_name}->value);
      $this->drupalGet('entity_test/manage/' . $id . '/edit');
      $this->submitForm([], 'Save');
      $this->drupalGet('entity_test/manage/' . $id . '/edit');
      $this->submitForm([], 'Save');
      
      if ($x <= 12) {
        $edit['parent'] = $term1->id();
      }
      $term = $this->createTerm($this->vocabulary, $edit);
      $children = $taxonomy_storage->loadChildren($term1->id());
      $parents = $taxonomy_storage->loadParents($term->id());
      $terms_array[$x] = Term::load($term->id());
    }

    // Get Page 1. Parent term and terms 1-13 are displayed.     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
    $this->assertSession()->pageTextContains($term1->getName());
    for ($x = 1; $x <= 13; $x++) {
      $this->assertSession()->pageTextContains($terms_array[$x]->getName());
    }

    // Get Page 2. Parent term and terms 1-18 are displayed.     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 1]]);
    $this->assertSession()->pageTextContains($term1->getName());
    for ($x = 1; $x <= 18; $x++) {
      $this->assertSession()->pageTextContains($terms_array[$x]->getName());
    }

    
protected $defaultTheme = 'stark';

  /** * A node type without moderation state disabled. * * @covers \Drupal\content_moderation\EntityTypeInfo::formAlter * @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter */
  public function testNotModerated() {
    $this->drupalLogin($this->adminUser);
    $this->createContentTypeFromUi('Not moderated', 'not_moderated');
    $this->assertSession()->pageTextContains('The content type Not moderated has been added.');
    $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'not_moderated');
    $this->drupalGet('node/add/not_moderated');
    $this->assertSession()->pageTextContains('Save');
    $this->submitForm([
      'title[0][value]' => 'Test',
    ], 'Save');
    $this->assertSession()->pageTextContains('Not moderated Test has been created.');
  }

  /** * Tests enabling moderation on an existing node-type, with content. * * @covers \Drupal\content_moderation\EntityTypeInfo::formAlter * @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter */
$this->assertSession()->elementTextContains('xpath', '//h1', $text);

      $original_configuration = [
        'field' => 'id_broken',
        'id' => 'id_broken',
        'relationship' => 'none',
        'table' => 'views_test_data',
        'plugin_id' => 'numeric',
      ];

      foreach ($original_configuration as $key => $value) {
        $this->assertSession()->pageTextContains($key . ': ' . $value);
      }
    }
  }

  /** * Ensures that neither node type or node ID appears multiple times. * * @see \Drupal\views\EntityViewsData */
  public function testNoDuplicateFields() {
    $handler_types = ['field', 'filter', 'sort', 'argument'];

    
$session = $this->assertSession();

    // Get valid credentials.     $edit = $this->getCredentials();
    $version = $edit['version'];
    $edits = $this->translatePostValues($edit);

    $this->drupalGet('/upgrade');
    $session->responseContains("Upgrade a site by importing its files and the data from its database into a clean and empty new install of Drupal $this->destinationSiteVersion.");

    $this->submitForm([], 'Continue');
    $session->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.');
    $session->fieldExists('mysql[host]');

    // Ensure submitting the form with invalid database credentials gives us a     // nice warning.     $this->submitForm([$edit['driver'] . '[database]' => 'wrong'] + $edits, 'Review upgrade');
    $session->pageTextContains('Resolve all issues below to continue the upgrade.');

    // Resubmit with correct credentials.     $this->submitForm($edits, 'Review upgrade');
    $this->submitForm([], 'I acknowledge I may lose data. Continue anyway.');
    $session->statusCodeEquals(200);

    
$node = Node::create([
      'title' => 'Host node',
      'type' => $node_type->id(),
      'field_related_media' => [
        'target_id' => $image_media_id,
      ],
    ]);
    $node->save();

    $this->drupalGet('/node/' . $node->id());
    // Media field (field_related_media) is there.     $assert_session->pageTextContains('Related media');
    // Media name element is not there.     $assert_session->pageTextNotContains($image_media_name);
    // Only one image is present.     $assert_session->elementsCount('xpath', '//img', 1);
    // The image has the correct image style.     $assert_session->elementAttributeContains('xpath', '//img', 'src', '/styles/large/');
  }

}
Home | Imprint | This part of the site doesn't use cookies.