assertSession example

/** * For authenticated users, the "active" class is set by JavaScript. * * @param string $block_label * The label of the language switching block. * * @see self::testLanguageBlock() */
  protected function doTestLanguageBlockAuthenticated($block_label) {
    // Assert that the language switching block is displayed on the frontpage.     $this->drupalGet('');
    $this->assertSession()->pageTextContains($block_label);

    // Assert that each list item and anchor element has the appropriate data-     // attributes.     $language_switchers = $this->xpath('//div[@id=:id]/ul/li', [':id' => 'block-test-language-block']);
    $list_items = [];
    $anchors = [];
    $labels = [];
    foreach ($language_switchers as $list_item) {
      $list_items[] = [
        'hreflang' => $list_item->getAttribute('hreflang'),
        'data-drupal-link-system-path' => $list_item->getAttribute('data-drupal-link-system-path'),
      ];
$this->updateUser = $this->drupalCreateUser([
      'administer software updates',
    ]);
  }

  public function testInvalidUpdateHook() {
    // Confirm that a module with hook_update_8000() cannot be updated.     $this->drupalLogin($this->updateUser);
    $this->drupalGet($this->updateUrl);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');
    $this->assertSession()->pageTextContains('Some of the pending updates cannot be applied because their dependencies were not met.');
  }

}
$executable->setDisplay('page_1');

    $access_plugin = $executable->display_handler->getPlugin('access');
    $this->assertInstanceOf(Role::class$access_plugin);

    // Test the access() method on the access plugin.     $this->assertFalse($executable->display_handler->access($this->webUser));
    $this->assertTrue($executable->display_handler->access($this->normalUser));

    $this->drupalLogin($this->webUser);
    $this->drupalGet('test-role');
    $this->assertSession()->statusCodeEquals(403);
    $this->assertCacheContext('user.roles');

    $this->drupalLogin($this->normalUser);
    $this->drupalGet('test-role');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertCacheContext('user.roles');

    // Test allowing multiple roles.     $view = Views::getView('test_access_role')->storage;
    $display = &$view->getDisplay('default');
    $display['display_options']['access']['options']['role'] = [
      
'body' => [['value' => $num]],
        'type' => 'page',
        'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        'title' => $doc . ' number',
      ];
      $this->nodes[$doc] = $this->drupalCreateNode($info);
    }

    // Run cron to ensure the content is indexed.     $this->cronRun();
    $this->drupalGet('admin/reports/dblog');
    $this->assertSession()->pageTextContains('Cron run completed');
  }

  /** * Tests that all the numbers can be searched. */
  public function testNumberSearching() {
    $types = array_keys($this->numbers);

    foreach ($types as $type) {
      $number = $this->numbers[$type];
      // If the number is negative, remove the - sign, because - indicates
$comment->save();

    $commenting_user = $this->drupalCreateUser([
      'access printer-friendly version',
      'access comments',
      'post comments',
    ]);
    $this->drupalLogin($commenting_user);

    $this->drupalGet('node/' . $book_node->id());

    $this->assertSession()->pageTextContains($comment_subject);
    $this->assertSession()->pageTextContains($comment_body);
    $this->assertSession()->pageTextContains('Add new comment');
    // Ensure that the comment form subject field exists.     $this->assertSession()->fieldExists('subject[0][value]');

    $this->drupalGet('book/export/html/' . $book_node->id());

    $this->assertSession()->pageTextContains('Comments');
    $this->assertSession()->pageTextContains($comment_subject);
    $this->assertSession()->pageTextContains($comment_body);

    
'filter_datetime' => [
        'condition' => [
          'path' => 'field_datetime',
          'operator' => '>',
          'value' => date(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $timestamp_greater_than_value),
        ],
      ],
    ];
    $output = Json::decode($this->drupalGet('/jsonapi/node/article', [
      'query' => ['filter' => $filter],
    ]));
    $this->assertSession()->statusCodeEquals(200);
    $output_uuids = array_map(function D$result) {
      return $result['id'];
    }$output['data']);
    $this->assertCount(1, $output_uuids);
    $this->assertSame([
      $node_3->uuid(),
    ]$output_uuids);

    // Checks whether the date is greater than or equal to the given timestamp.     $filter = [
      'filter_datetime' => [
        
'name' => 'Unnamed',
    ]);
    $media->save();

    $user = $this->drupalCreateUser([
      'administer media',
      'access contextual links',
    ]);
    $this->drupalLogin($user);

    $this->drupalGet('media/' . $media->id());
    $this->assertSession()->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'media:media=' . $media->id() . ':');
  }

}
$this->drupalGet('node/' . $this->node->id());
    // Manually calling statistics.php, simulating ajax behavior.     // @see \Drupal\statistics\Tests\StatisticsLoggingTest::testLogging().     global $base_url;
    $stats_path = $base_url . '/' . $this->getModulePath('statistics') . '/statistics.php';
    $client = $this->getHttpClient();
    $client->post($stats_path['form_params' => ['nid' => $this->node->id()]]);
    $this->drupalGet('test_statistics_integration');

    /** @var \Drupal\statistics\StatisticsViewsResult $statistics */
    $statistics = \Drupal::service('statistics.storage.node')->fetchView($this->node->id());
    $this->assertSession()->pageTextContains('Total views: 1');
    $this->assertSession()->pageTextContains('Views today: 1');
    $this->assertSession()->pageTextContains('Most recent view: ' . date('Y', $statistics->getTimestamp()));

    $this->drupalLogout();
    $this->drupalLogin($this->deniedUser);
    $this->drupalGet('test_statistics_integration');
    $this->assertSession()->statusCodeEquals(200);

    $this->assertSession()->pageTextNotContains('Total views:');
    $this->assertSession()->pageTextNotContains('Views today:');
    $this->assertSession()->pageTextNotContains('Most recent view:');
  }


  /** * Tests the role access plugin UI. */
  public function testAccessRoleUI() {
    $entity_type_manager = $this->container->get('entity_type.manager');
    $entity_type_manager->getStorage('user_role')->create(['id' => 'custom_role', 'label' => 'Custom role'])->save();
    $access_url = "admin/structure/views/nojs/display/test_access_role/default/access_options";
    $this->drupalGet($access_url);
    $this->submitForm(['access_options[role][custom_role]' => 1], 'Apply');
    $this->assertSession()->statusCodeEquals(200);

    $this->submitForm([], 'Save');
    $view = $entity_type_manager->getStorage('view')->load('test_access_role');

    $display = $view->getDisplay('default');
    $this->assertEquals(['custom_role' => 'custom_role']$display['display_options']['access']['options']['role']);

    // Test changing access plugin from role to none.     $this->drupalGet('admin/structure/views/nojs/display/test_access_role/default/access');
    $this->submitForm(['access[type]' => 'none'], 'Apply');
    $this->submitForm([], 'Save');
    
// Allow the caller to set a NULL path in case they navigated to the right     // page before calling this method.     if ($bundle_path !== NULL) {
      $bundle_path = "$bundle_path/fields/add-field";
      $this->drupalGet($bundle_path);
    }

    // First step: 'Add field' page.     $session = $this->getSession();

    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $field_new_storage_type = $page->findField('new_storage_type');
    $field_new_storage_type->setValue($field_type);

    $field_label = $page->findField('label');
    $this->assertTrue($field_label->isVisible());
    $field_label->setValue($label);
    $machine_name = $assert_session->waitForElementVisible('css', '[name="label"] + * .machine-name-value');
    $this->assertNotEmpty($machine_name);
    $page->findButton('Edit')->press();

    

  protected function setUpSite() {
    // This step should not appear as we had a failure prior to the settings     // screen.   }

  /** * Verifies that installation failed. */
  public function testError() {
    $this->assertSession()->pageTextContains("An automated attempt to create the directory {$this->configDirectory}/sync failed, possibly due to a permissions problem.");
    $this->assertDirectoryDoesNotExist($this->configDirectory . '/sync');
  }

}


  /** * Tests a workflow with a default moderation state set. */
  public function testPublishedDefaultState() {
    // Set the default moderation state to be "published".     $this->drupalGet('admin/config/workflow/workflows/manage/' . $this->workflow->id());
    $this->submitForm(['type_settings[workflow_settings][default_moderation_state]' => 'published'], 'Save');

    $this->drupalGet('node/add/moderated_content');
    $this->assertEquals('published', $this->assertSession()->selectExists('moderation_state[0][state]')->getValue());
    $this->submitForm([
      'title[0][value]' => 'moderated content',
    ], 'Save');

    $node = $this->getNodeByTitle('moderated content');
    $this->assertEquals('published', $node->moderation_state->value);
  }

  /** * Tests access to deleting the default state. */
  
$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');
    $this->assertSession()->responseContains('<strong>cómmīŦŧęđ</strong>');
    $this->assertSession()->responseContains('<strong>BɆĬŇĜ</strong>');
    
// The media viewer that can view any unpublished content should still be     // able to see all media.     $this->drupalLogin($this->userViewAnyUnpublished);
    $this->drupalGet('admin/content/media');
    $this->assertAllMedia();
  }

  /** * Tests the media library widget only shows published media. */
  public function testWidget() {
    $assert_session = $this->assertSession();

    // All users should only be able to see published media items.     $this->drupalLogin($this->rootUser);
    $this->drupalGet('node/add/article');
    $assert_session->elementExists('css', '.js-media-library-open-button[name^="field_media"]')->click();
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertOnlyPublishedMedia();
    $this->drupalLogin($this->userAdmin);
    $this->drupalGet('node/add/article');
    $assert_session->elementExists('css', '.js-media-library-open-button[name^="field_media"]')->click();
    $assert_session->assertWaitOnAjaxRequest();
    
    'migration_provider_test',
  ];

  /** * Test missing source provider. * * @dataProvider providerSourceProvider */
  public function testSourceProvider($path_to_database) {
    $this->loadFixture($this->getModulePath('migrate_drupal') . $path_to_database);

    $session = $this->assertSession();

    // Start the upgrade process.     $this->submitCredentialForm();

    // Ensure we get errors about missing modules.     $session->pageTextContains('Resolve all issues below to continue the upgrade.');
    $session->pageTextContains('The no_source_module plugin must define the source_module property.');

    // Uninstall the module causing the missing module error messages.     $this->container->get('module_installer')
      ->uninstall(['migration_provider_test'], TRUE);

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