statusCodeEquals example

$url = $this->fileUrlGenerator->generateAbsoluteString($file->getFileUri());

    // Set file_test access header to allow the download.     file_test_reset();
    file_test_set_return('download', ['x-foo' => 'Bar']);
    $this->drupalGet($url);
    // Verify that header is set by file_test module on private download.     $this->assertSession()->responseHeaderEquals('x-foo', 'Bar');
    // Verify that page cache is disabled on private file download.     $this->assertSession()->responseHeaderDoesNotExist('x-drupal-cache');
    $this->assertSession()->statusCodeEquals(200);
    // Ensure hook_file_download is fired correctly.     $this->assertEquals($file->getFileUri(), \Drupal::state()->get('file_test.results')['download'][0][0]);

    // Test that the file transferred correctly.     $this->assertSame($contents$this->getSession()->getPage()->getContent(), 'Contents of the file are correct.');
    $http_client = $this->getHttpClient();

    // Try non-existent file.     file_test_reset();
    $not_found_url = $this->fileUrlGenerator->generateAbsoluteString('private://' . $this->randomMachineName() . '.txt');
    $response = $http_client->head($not_found_url['http_errors' => FALSE]);
    
'user_list',
        'http_response',
        'rendered',
        // FinishResponseSubscriber adds this cache tag to responses that have         // the 'user.permissions' cache context for anonymous users.         'config:user.role.anonymous',
      ]
    );

    // Check the actual page response.     $this->drupalGet($url);
    $this->assertSession()->statusCodeEquals(200);
    foreach ($nodes_per_char as $char => $count) {
      $href = Url::fromRoute('view.glossary.page_1', ['arg_0' => $char])->toString();
      $label = mb_strtoupper($char);
      // Get the summary link for a certain character. Filter by label and href       // to ensure that both of them are correct.       $result = $this->assertSession()->elementExists('xpath', "//a[contains(@href, '{$href}') and normalize-space(text())='{$label}']/..");
      // The rendered output looks like "<a href=''>X</a> | (count)" so let's       // figure out the int.       $result_count = explode(' ', trim(str_replace(['|', '(', ')'], '', $result->getText())))[1];
      $this->assertEquals($count$result_count, 'The expected number got rendered.');
    }
  }
$settings[$this->testDriverName] = $settings[$driver];
    unset($settings[$driver]);
    $edit = $this->translatePostValues($settings);
    $this->submitForm($edit$this->translations['Save and continue']);
  }

  /** * Confirms that the installation succeeded. */
  public function testInstalled() {
    $this->assertSession()->addressEquals('user/1');
    $this->assertSession()->statusCodeEquals(200);

    // Assert that in the settings.php the database connection array has the     // correct values set.     $contents = file_get_contents($this->container->getParameter('app.root') . '/' . $this->siteDirectory . '/settings.php');
    $this->assertStringContainsString("'namespace' => 'Drupal\\\\driver_test\\\\Driver\\\\Database\\\\{$this->testDriverName}',", $contents);
    $this->assertStringContainsString("'driver' => '{$this->testDriverName}',", $contents);
    $this->assertStringContainsString("'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/{$this->testDriverName}/',", $contents);

    // Assert that the module "driver_test" has been installed.     $this->assertEquals(\Drupal::service('module_handler')->getModule('driver_test')new Extension($this->root, 'module', 'core/modules/system/tests/modules/driver_test/driver_test.info.yml'));

    

  protected function createNodeThroughUi($label$bundle$publish = TRUE) {
    $this->drupalGet('/node/add/' . $bundle);

    /** @var \Behat\Mink\Session $session */
    $session = $this->getSession();
    $this->assertSession()->statusCodeEquals(200);

    /** @var \Behat\Mink\Element\DocumentElement $page */
    $page = $session->getPage();
    $page->fillField('Title', $label);
    if ($publish) {
      $page->findButton('Save')->click();
    }
    else {
      $page->uncheckField('Published');
      $page->findButton('Save')->click();
    }

    
$this->submitForm($edit, 'Save settings');

    // Check that the English alias still works.     $this->drupalGet($english_alias);
    $this->assertSession()->pageTextContains($english_node_french_translation->body->value);

    // Check that the French alias is not available. We check the unprefixed     // alias because we disabled URL language negotiation above. In this     // situation only aliases in the default language and language neutral ones     // should keep working.     $this->drupalGet($french_alias);
    $this->assertSession()->statusCodeEquals(404);

    // The alias manager has an internal path lookup cache. Check to see that     // it has the appropriate contents at this point.     $this->container->get('path_alias.manager')->cacheClear();
    $french_node_path = $this->container->get('path_alias.manager')->getPathByAlias('/' . $french_alias, 'fr');
    $this->assertEquals('/node/' . $english_node_french_translation->id()$french_node_path, 'Normal path works.');
    // Second call should return the same path.     $french_node_path = $this->container->get('path_alias.manager')->getPathByAlias('/' . $french_alias, 'fr');
    $this->assertEquals('/node/' . $english_node_french_translation->id()$french_node_path, 'Normal path is the same.');

    // Confirm that the alias works.
    $view1['label'] = $this->randomMachineName(16);
    $view1['id'] = strtolower($this->randomMachineName(16));
    $view1['description'] = $this->randomMachineName(16);
    $view1['show[tagged_with]'] = 'tag1';
    $view1['page[create]'] = 1;
    $view1['page[title]'] = $this->randomMachineName(16);
    $view1['page[path]'] = $this->randomMachineName(16);
    $this->submitForm($view1, 'Save and edit');
    // Visit the page and check that the nodes we expect are present and the     // ones we don't expect are absent.     $this->drupalGet($view1['page[path]']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains($node_tag1_title);
    $this->assertSession()->pageTextContains($node_tag1_tag2_title);
    $this->assertSession()->pageTextNotContains($node_no_tags_title);

    // Create a view that filters by taxonomy term "tag2". It should show only     // the one node from above that is tagged with "tag2".     $view2 = [];
    $view2['show[type]'] = $this->nodeTypeWithTags->id();
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view2, 'Update "of type" choice');
    $this->assertSession()->statusCodeEquals(200);
    
// Save a path.     $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
    $this->submitForm(['path' => $random_string], 'Apply');
    $this->drupalGet('admin/structure/views/view/test_view');

    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/menu');
    $this->submitForm([
      'menu[type]' => 'default tab',
      'menu[title]' => 'Test tab title',
    ], 'Apply');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->addressEquals('admin/structure/views/nojs/display/test_view/page_1/tab_options');

    $this->submitForm(['tab_options[type]' => 'tab', 'tab_options[title]' => $this->randomString()], 'Apply');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->addressEquals('admin/structure/views/view/test_view/edit/page_1');

    $this->drupalGet('admin/structure/views/view/test_view');
    $this->assertSession()->linkExists('Tab: Test tab title');
    // If it's a default tab, it should also have an additional settings link.     $this->assertSession()->linkByHrefExists('admin/structure/views/nojs/display/test_view/page_1/tab_options');

    
    $this->assertSession()->responseContains('core/themes/claro/css/base/elements.css');

    // Turn off admin theme for editing, assert inheritance to translations.     $edit['use_admin_theme'] = FALSE;
    $this->drupalGet('admin/appearance');
    $this->submitForm($edit, 'Save configuration');
    $this->drupalGet('node/' . $article->id() . '/translations');
    // Verify that translation uses the frontend theme if edit is frontend.     $this->assertSession()->responseNotContains('core/themes/claro/css/base/elements.css');

    // Assert presence of translation page itself (vs. DisabledBundle below).     $this->assertSession()->statusCodeEquals(200);
  }

  /** * Tests that no metadata is stored for a disabled bundle. */
  public function testDisabledBundle() {
    // Create a bundle that does not have translation enabled.     $disabledBundle = $this->randomMachineName();
    $this->drupalCreateContentType(['type' => $disabledBundle, 'name' => $disabledBundle]);

    // Create a node for each bundle.
$this->submitForm($edit, 'Save field settings');
  }

  /** * Tests deleting a field from the field edit form. */
  protected function deleteField() {
    // Delete the field.     $field_id = 'node.' . $this->contentType . '.' . $this->fieldName;
    $this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field_id);
    $this->clickLink('Delete');
    $this->assertSession()->statusCodeEquals(200);
  }

  /** * Tests that persistent field storage appears in the field UI. */
  protected function addPersistentFieldStorage() {
    $field_storage = FieldStorageConfig::loadByName('node', $this->fieldName);
    // Persist the field storage even if there are no fields.     $field_storage->set('persist_with_no_fields', TRUE)->save();
    // Delete all instances of the field.     foreach ($field_storage->getBundles() as $node_type) {
      
$this->assertSession()->assertEscaped('<em>' . date("Y") . '</em>');
  }

  /** * Tests handling case with invalid data in selectors (like February, 31st). */
  public function testEnteringDateTimeViaSelectors() {

    $this->drupalCreateContentType(['type' => 'page_with_date', 'name' => 'Page with date']);

    $this->drupalGet('admin/structure/types/manage/page_with_date');
    $this->assertSession()->statusCodeEquals(200);

    $this->drupalGet('admin/structure/types/manage/page_with_date/fields/add-field');
    $edit = [
      'new_storage_type' => 'datetime',
      'label' => 'dt',
      'field_name' => 'dt',
    ];
    $this->drupalGet('admin/structure/types/manage/page_with_date/fields/add-field');
    $this->submitForm($edit, 'Save and continue');
    // Check that the new datetime field was created, and process is now set     // to continue for configuration.
'weight' => mt_rand(0, 10),
    ]);
    $untranslatable_vocabulary->save();

    $values = [
      'name' => $this->randomMachineName(),
    ];
    $untranslatable_tid = $this->createEntity($values$this->langcodes[0]$untranslatable_vocabulary->id());

    // Verify translation links.     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkByHrefExists('term/' . $translatable_tid . '/translations', 0, 'The translations link exists for a translatable vocabulary.');
    $this->assertSession()->linkByHrefExists('term/' . $translatable_tid . '/edit', 0, 'The edit link exists for a translatable vocabulary.');

    $this->drupalGet('admin/structure/taxonomy/manage/' . $untranslatable_vocabulary->id() . '/overview');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkByHrefExists('term/' . $untranslatable_tid . '/edit');
    $this->assertSession()->linkByHrefNotExists('term/' . $untranslatable_tid . '/translations');
  }

  /** * {@inheritdoc} */
$types[] = $type;

      for ($j = 0; $j < 5; $j++) {
        // Ensure the right order of the nodes.         $node = $this->drupalCreateNode(['type' => $type->id(), 'created' => REQUEST_TIME - ($i * 5 + $j)]);
        $nodes[$type->id()][$node->id()] = $node;
        $all_nids[] = $node->id();
      }
    }

    $this->drupalGet('test-node-view');
    $this->assertSession()->statusCodeEquals(404);

    $this->drupalGet('test-node-view/all');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertNids($all_nids);

    foreach ($types as $type) {
      $this->drupalGet("test-node-view/{$type->id()}");
      $this->assertSession()->assertEscaped($type->label());
      $this->assertNids(array_keys($nodes[$type->id()]));
    }
  }

  
/** * Tests the review page when content_translation is enabled. */
  public function testMigrateUpgradeReviewPage() {
    $this->prepare();
    // Start the upgrade process.     $this->submitCredentialForm();

    $session = $this->assertSession();
    $this->submitForm([], 'I acknowledge I may lose data. Continue anyway.');
    $session->statusCodeEquals(200);

    // Test the upgrade paths.     $this->assertReviewForm();
  }

}
$this->drupalGet('node/' . $this->book->id());
    $this->clickLink('Printer-friendly version');

    // Make sure each part of the book is there.     foreach ($nodes as $node) {
      $this->assertSession()->pageTextContains($node->label());
      $this->assertSession()->responseContains($node->body->processed);
    }

    // Make sure we can't export an unsupported format.     $this->drupalGet('book/export/foobar/' . $this->book->id());
    $this->assertSession()->statusCodeEquals(404);

    // Make sure we get a 404 on a non-existent book node.     $this->drupalGet('book/export/html/123');
    $this->assertSession()->statusCodeEquals(404);

    // Make sure an anonymous user cannot view printer-friendly version.     $this->drupalLogout();

    // Load the book and verify there is no printer-friendly version link.     $this->drupalGet('node/' . $this->book->id());
    $this->assertSession()->linkNotExists('Printer-friendly version', 'Anonymous user is not shown link to printer-friendly version.');

    
/** * Iterates over protected files and calls assertNoFileAccess(). */
  public function testFileAccess() {
    foreach ($this->getProtectedFiles() as $file => $response_code) {
      $this->assertFileAccess($file$response_code);
    }

    // Test that adding "/1" to a .php URL does not make it accessible.     $this->drupalGet('core/lib/Drupal.php/1');
    $this->assertSession()->statusCodeEquals(403);

    // Test that it is possible to have path aliases containing .php.     $type = $this->drupalCreateContentType();

    // Create a node aliased to test.php.     $node = $this->drupalCreateNode([
      'title' => 'This is a node',
      'type' => $type->id(),
      'path' => '/test.php',
    ]);
    $node->save();
    
Home | Imprint | This part of the site doesn't use cookies.