assertStringNotContainsString example

$href = $element->getAttribute('href');
      $url = $this->getAbsoluteUrl($href);
      // Not every script or style on a page is aggregated.       if (!str_contains($url$this->fileAssetsPath)) {
        continue;
      }
      $session = $this->getSession();
      $session->visit($url);
      $this->assertSession()->statusCodeEquals(200);
      $aggregate = $session = $session->getPage()->getContent();
      $this->assertStringContainsString('original-content', $aggregate);
      $this->assertStringNotContainsString('extra-stuff', $aggregate);
    }
    $file = file_get_contents('public://test.css') . '.extra-stuff{display:none;}';
    file_put_contents('public://test.css', $file);
    // Clear the library discovery and page caches again so that new URLs are     // generated.     \Drupal::service('cache.data')->deleteAll();
    \Drupal::service('cache.page')->deleteAll();
    $this->drupalGet('<front>');
    $session = $this->getSession();
    $page = $session->getPage();
    $style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
    
public function testLibraryOverrides(): void {
    $build = [
      '#type' => 'inline_template',
      '#template' => "{{ include('sdc_theme_test:lib-overrides') }}",
    ];
    \Drupal::state()->set('sdc_test_component', $build);
    $output = $this->drupalGet('sdc-test-component');
    $this->assertStringContainsString('another-stylesheet.css', $output);
    // Since libraryOverrides is taking control of CSS, and it's not listing     // lib-overrides.css, then it should not be there. Even if it's the CSS     // that usually gets auto-attached.     $this->assertStringNotContainsString('lib-overrides.css', $output);
    // Ensure that libraryDependencies adds the expected assets.     $this->assertStringContainsString('dialog.position.js', $output);
    // Ensure that libraryOverrides processes attributes properly.     $this->assertMatchesRegularExpression('@<script.*src="[^"]*lib-overrides\.js\?v=1[^"]*".*defer.*bar="foo"></script>@', $output);
    // Ensure that libraryOverrides processes external CSS properly.     $this->assertMatchesRegularExpression('@<link.*href="https://drupal\.org/fake-dependency/styles\.css" />@', $output);
    // Ensure that libraryOverrides processes external JS properly.     $this->assertMatchesRegularExpression('@<script.*src="https://drupal\.org/fake-dependency/index\.min\.js"></script>@', $output);
  }

}
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($poolDir)) as $entry) {
            // converts files into dir to make adapter fail             if ($entry->isFile()) {
                unlink($entry->getPathname());
                mkdir($entry->getPathname());
            }
        }

        $tester->execute(['pools' => ['cache.public_pool']]);

        $this->assertSame(1, $tester->getStatusCode(), 'cache:pool:clear exits with 1 in case of error');
        $this->assertStringNotContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay());
        $this->assertStringContainsString('[WARNING] Cache pool "cache.public_pool" could not be cleared.', $tester->getDisplay());
    }

    private function createCommandTester(array $poolNames = null)
    {
        $application = new Application(static::$kernel);
        $application->add(new CachePoolClearCommand(static::getContainer()->get('cache.global_clearer')$poolNames));

        return new CommandTester($application->find('cache:pool:clear'));
    }
}
$entryManager->applyOperations($entry->getDn()$duplicateIterator);
    }

    /** * @group functional */
    public function testLdapMove()
    {
        $result = $this->executeSearchQuery(1);

        $entry = $result[0];
        $this->assertStringNotContainsString('ou=Ldap', $entry->getDn());

        $entryManager = $this->adapter->getEntryManager();
        $entryManager->move($entry, 'ou=Ldap,ou=Components,dc=symfony,dc=com');

        $result = $this->executeSearchQuery(1);
        $movedEntry = $result[0];
        $this->assertStringContainsString('ou=Ldap', $movedEntry->getDn());

        // Move back entry         $entryManager->move($movedEntry, 'dc=symfony,dc=com');
    }
}
$header_text = $this->getOffCanvasDialog()->find('css', '.ui-dialog-title')->getText();
      if ($link_index == '2') {
        // Check no title behavior.         $web_assert->elementExists('css', '.ui-dialog-empty-title');
        $this->assertEquals(' ', $header_text);

        $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
        $this->assertStringContainsString('width: 555px;', $style, 'Dialog width respected.');
        $page->clickLink("Open side panel 1");
        $this->waitForOffCanvasToOpen();
        $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
        $this->assertStringNotContainsString('width: 555px;', $style, 'Dialog width reset to default.');
      }
      else {
        // Check that header is correct.         $this->assertEquals("Thing $link_index", $header_text);
        $web_assert->elementNotExists('css', '.ui-dialog-empty-title');
      }
    }

    // Test the off_canvas_top tray.     foreach ([1, 2] as $link_index) {
      $this->assertOffCanvasDialog($link_index, 'top');

      
$view_class = 'js-view-dom-id-' . $view->dom_id;
    $result = $this->xpath('//div[@class = "' . $view_class . '"]/header[1]');
    $this->assertStringContainsString($entities[0]->label()(string) $result[0], 'The rendered entity appears in the header of the view.');
    $this->assertStringContainsString('test', (string) $result[0], 'The rendered entity appeared in the right view mode.');

    // Test entity access.     $view = Views::getView('test_entity_area');
    $preview = $view->preview('default', [$entities[2]->id()]);
    $this->setRawContent($renderer->renderRoot($preview));
    $view_class = 'js-view-dom-id-' . $view->dom_id;
    $result = $this->xpath('//div[@class = "' . $view_class . '"]/footer[1]');
    $this->assertStringNotContainsString($entities[2]->label()$result[0], 'The rendered entity does not appear in the footer of the view.');

    // Test the available view mode options.     $form = [];
    $form_state = (new FormState())
      ->set('type', 'header');
    /** @var \Drupal\views\Plugin\views\area\DisplayLink $display_handler */
    $display_handler = $view->display_handler->getHandler('header', 'entity_entity_test');
    $display_handler->buildOptionsForm($form$form_state);
    $this->assertTrue(isset($form['view_mode']['#options']['test']), 'Ensure that the test view mode is available.');
    $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available.');
  }

  

  public function testSerialization() {
    $view = Views::getView('test_executable_displays');
    $view->setDisplay('page_1');
    $view->setArguments(['test']);
    $view->setCurrentPage(2);

    $serialized = serialize($view);

    // Test the view storage object is not present in the actual serialized     // string.     $this->assertStringNotContainsString('"Drupal\views\Entity\View"', $serialized, 'The Drupal\views\Entity\View class was not found in the serialized string.');

    /** @var \Drupal\views\ViewExecutable $unserialized */
    $unserialized = unserialize($serialized);

    $this->assertInstanceOf(ViewExecutable::class$unserialized);
    $this->assertSame($unserialized->storage->id()$view->storage->id(), 'The expected storage entity was loaded on the unserialized view.');
    $this->assertSame('page_1', $unserialized->current_display, 'The expected display was set on the unserialized view.');
    $this->assertSame(['test']$unserialized->args, 'The expected argument was set on the unserialized view.');
    $this->assertSame(2, $unserialized->getCurrentPage(), 'The expected current page was set on the unserialized view.');

    // Get the definition of node's nid field, for example. Only get it not from
        // leading to overwritten keys         foreach ($iterable as $chunk) {
            $string .= $chunk;
        }

        return $string;
    }

    protected function assertMessageHeaders(Message $message, RawMessage $originalMessage): void
    {
        $messageString = $message->toString();
        self::assertStringNotContainsString('Bcc: ', $messageString, '', true);

        if (!$originalMessage instanceof Message) {
            return;
        }

        if ($originalMessage->getHeaders()->has('Bcc')) {
            self::assertEquals($originalMessage->getHeaders()->get('Bcc')$message->getHeaders()->get('Bcc'));
        }

        if ($originalMessage->getHeaders()->has('Subject')) {
            self::assertEquals($originalMessage->getHeaders()->get('Subject')$message->getPreparedHeaders()->get('Subject'));
            
    $this->clickLink('Link 8 (ajax)');
    $assert->assertWaitOnAjaxRequest();

    // Test that the fake library is still set after the AJAX call.     $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries');
    $this->assertStringContainsString($fake_library$libraries);

    // Reload the page, this should reset the loaded libraries and remove the     // fake library.     $this->drupalGet('ajax-test/dialog');
    $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries');
    $this->assertStringNotContainsString($fake_library$libraries);

    // Click on the AJAX link again, and the libraries should still not contain     // the fake library.     $this->clickLink('Link 8 (ajax)');
    $assert->assertWaitOnAjaxRequest();
    $libraries = $session->evaluateScript('drupalSettings.ajaxPageState.libraries');
    $this->assertStringNotContainsString($fake_library$libraries);
  }

  /** * Tests that various AJAX responses with DOM elements are correctly inserted. * * After inserting DOM elements, Drupal JavaScript behaviors should be * reattached and all top-level elements of type Node.ELEMENT_NODE need to be * part of the context. */
    // override were Claro enabled are still loading.     $stylesheet_positions = [];
    foreach ($default_stylesheets as $stylesheet) {
      $this->assertStringContainsString($stylesheet$head);
      $stylesheet_positions[] = strpos($head$stylesheet);
    }
    $sorted_stylesheet_positions = $stylesheet_positions;
    sort($sorted_stylesheet_positions);
    $this->assertEquals($sorted_stylesheet_positions$stylesheet_positions);

    foreach ($claro_stylesheets as $stylesheet) {
      $this->assertStringNotContainsString($stylesheet$head);
    }

    // Confirm toolbar is not processed by claro_preprocess_toolbar().     $this->assertFalse($this->getSession()->getPage()->find('css', '#toolbar-administration')->hasAttribute('data-drupal-claro-processed-toolbar'));

    // Confirm menu--toolbar.html.twig is not loaded from Claro.     $this->assertFalse($this->getSession()->getPage()->find('css', '.toolbar-menu')->hasClass('claro-toolbar-menu'));
    $this->assertFalse($this->getSession()->getPage()->find('css', '.toolbar')->hasClass('claro-toolbar'));

    $this->config('system.theme')->set('admin', 'claro')->save();
    $this->drupalGet('test-page');
    
/** * Confirms that invalid URLs are filtered in link generating functions. */
  public function testLinkXSS() {
    // Test link generator.     $text = $this->randomMachineName();
    $path = "<SCRIPT>alert('XSS')</SCRIPT>";
    $encoded_path = "3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E";

    $link = Link::fromTextAndUrl($text, Url::fromUserInput('/' . $path))->toString();
    $this->assertStringContainsString($encoded_path$linknew FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));
    $this->assertStringNotContainsString($path$linknew FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));

    // Test \Drupal\Core\Url.     $link = Url::fromUri('base:' . $path)->toString();
    $this->assertStringContainsString($encoded_path$linknew FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path]));
    $this->assertStringNotContainsString($path$linknew FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path]));
  }

  /** * Tests that #type=link bubbles outbound route/path processors' metadata. */
  public function testLinkBubbleableMetadata() {
    
$guzzle = new Client();
    $port = FALSE;
    $process->waitUntil(function D$type$output) use (&$port) {
      if (preg_match('/127.0.0.1:(\d+)/', $output$match)) {
        $port = $match[1];
        return TRUE;
      }
    });
    // The progress bar uses STDERR to write messages.     $this->assertStringContainsString('Congratulations, you installed Drupal!', $process->getErrorOutput());
    // Ensure the command does not trigger any PHP deprecations.     $this->assertStringNotContainsString('Deprecated', $process->getErrorOutput());
    $this->assertNotFalse($port, "Web server running on port $port");

    // Give the server a couple of seconds to be ready.     sleep(2);
    $this->assertStringContainsString("127.0.0.1:$port/user/reset/1/", $process->getOutput());

    // Generate a cookie so we can make a request against the installed site.     define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
    chmod($this->testDb->getTestSitePath(), 0755);
    $cookieJar = CookieJar::fromArray([
      'SIMPLETEST_USER_AGENT' => drupal_generate_test_ua($this->testDb->getDatabasePrefix()),
    ],
$this->assertSame('id', $style_plugin->active, 'Ensure the right order was set.');
      $view->destroy();
    }

    $view->destroy();

    // Excluded field to make sure its wrapping td doesn't show.     $this->prepareView($view);
    $view->field['name']->options['exclude'] = TRUE;
    $output = $view->preview();
    $output = \Drupal::service('renderer')->renderRoot($output);
    $this->assertStringNotContainsString('views-field-name', $output, "Excluded field's wrapper was not rendered.");
    $view->destroy();

    // Render a non empty result, and ensure that the empty area handler is not     // rendered.     $this->executeView($view);
    $output = $view->preview();
    $output = \Drupal::service('renderer')->renderRoot($output);

    $this->assertStringNotContainsString('custom text', $output, 'Empty handler was not rendered on a non empty table.');

    // Render an empty result, and ensure that the area handler is rendered.
static::assertTrue($response->headers->has('Content-Security-Policy'));

        $request = $browser->getRequest();
        static::assertTrue($request->attributes->has(PlatformRequest::ATTRIBUTE_CSP_NONCE));
        $nonce = $request->attributes->get(PlatformRequest::ATTRIBUTE_CSP_NONCE);

        static::assertMatchesRegularExpression(
            '/.*script-src[^;]+nonce-' . preg_quote((string) $nonce, '/') . '.*/',
            $response->headers->get('Content-Security-Policy'),
            'CSP should contain the nonce'
        );
        static::assertStringNotContainsString("\n", $response->headers->get('Content-Security-Policy'));
        static::assertStringNotContainsString("\r", $response->headers->get('Content-Security-Policy'));
    }

    public function testSwaggerHasCsp(): void
    {
        $browser = $this->getBrowser();

        $browser->request('GET', '/api/_info/swagger.html');
        $response = $browser->getResponse();

        static::assertTrue($response->headers->has('X-Frame-Options'));
        
$extendableDefinition = new ExtendableDefinition();
        $extendableDefinition->addExtension(new AssociationExtension());
        $extendableDefinition->addExtension(new ScalarRuntimeExtension());

        $extendableDefinition->compile($this->getContainer()->get(DefinitionInstanceRegistry::class));
        $fixture = new TestBasicWithExtension();

        $encoder = $this->getContainer()->get(JsonApiEncoder::class);
        $actual = $encoder->encode(new Criteria()$extendableDefinition$fixture->getInput(), SerializationFixture::API_BASE_URL);

        // check that empty "links" object is an object and not array: https://jsonapi.org/format/#document-links         static::assertStringNotContainsString('"links":[]', $actual);
        static::assertStringContainsString('"links":{}', $actual);

        $this->assertValues($fixture->getAdminJsonApiFixtures()json_decode((string) $actual, true, 512, \JSON_THROW_ON_ERROR));
    }

    /** * Not possible with dataprovider * as we have to manipulate the container, but the dataprovider run before all tests */
    public function testEncodeStructWithToManyExtension(): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.