assertNoRaw example

'#header' => $header,
      '#rows' => $rows,
      '#attributes' => $attributes,
      '#caption' => $caption,
      '#colgroups' => $colgroups,
      '#sticky' => FALSE,
    ];
    $this->render($table);
    // Make sure tableheader.js was not attached.     $tableheader = $this->xpath("//script[contains(@src, 'tableheader.js')]");
    $this->assertCount(0, $tableheader);
    $this->assertNoRaw('sticky-enabled');
  }

  /** * Tests the display of the table header. * * Tests are performed when the there are no rows and that the empty text is * displayed correctly. */
  public function testThemeTableWithEmptyMessage() {
    $header = [
      'Header 1',
      [
/** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */
    $kernel = \Drupal::getContainer()->get('http_kernel');
    $response = $kernel->handle($request)->prepare($request);
    $this->assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());
    $this->assertEquals('text/html; charset=UTF-8', $response->headers->get('Content-type'));

    // Test message is properly escaped, and that the unescaped string is not     // output at all.     $this->setRawContent($response->getContent());
    $this->assertRaw(Html::escape('Escaped content: <p> <br> <h3>'));
    $this->assertNoRaw('<p> <br> <h3>');

    $string = '<script>alert(123);</script>';
    $request = Request::create('/router_test/test2?_format=json' . urlencode($string), 'GET');

    $kernel = \Drupal::getContainer()->get('http_kernel');
    $response = $kernel->handle($request)->prepare($request);
    // As the Content-type is text/plain the fact that the raw string is     // contained in the output would not matter, but because it is output by the     // final exception subscriber, it is printed as partial HTML, and hence     // escaped.     $this->assertEquals('text/plain; charset=UTF-8', $response->headers->get('Content-type'));
    
public function testRenderChildren() {
    // Ensure that #prefix and #suffix is only being printed once since that is     // the behavior the caller code expects.     $build = [
      '#type' => 'container',
      '#theme' => 'theme_test_render_element_children',
      '#prefix' => 'kangaroo',
      '#suffix' => 'kitten',
    ];
    $this->render($build);
    $this->removeWhiteSpace();
    $this->assertNoRaw('<div>kangarookitten</div>');
  }

  /** * Tests that we get an exception when we try to attach an illegal type. */
  public function testProcessAttached() {
    // Specify invalid attachments in a render array.     $build['#attached']['library'][] = 'core/drupal.states';
    $build['#attached']['drupal_process_states'][] = [];
    $renderer = $this->container->get('bare_html_page_renderer');
    $this->expectException(\LogicException::class);
    

  public function testResult() {
    $view = Views::getView('test_area_result');
    $view->setDisplay('default');
    $this->executeView($view);
    $output = $view->render();
    $output = \Drupal::service('renderer')->renderRoot($output);
    $this->setRawContent($output);
    $this->assertText('start: 1 | end: 5 | total: 5 | label: test_area_result | per page: 0 | current page: 1 | current record count: 5 | page count: 1');

    // Make sure that potentially dangerous content was stripped.     $this->assertNoRaw('<script />');
  }

  /** * Tests the results area handler. */
  public function testResultEmpty() {
    $view = Views::getView('test_area_result');

    // Test that the area is displayed if we have checked the empty checkbox.     $view->setDisplay('default');

    
$this->assertRaw($this->fieldTestData->field_2->getLabel(), "Second field's label is displayed.");
    foreach ($values_2 as $delta => $value) {
      $this->assertRaw("$formatter_setting_2|{$value['value']}", "Value $delta is displayed, formatter settings are applied.");
    }

    // Label hidden.     $entity = clone($entity_init);
    $display_options['label'] = 'hidden';
    $display->setComponent($this->fieldTestData->field_name, $display_options);
    $content = $display->build($entity);
    $this->render($content);
    $this->assertNoRaw($this->fieldTestData->field->getLabel(), "Hidden label: label is not displayed.");

    // Field hidden.     $entity = clone($entity_init);
    $display->removeComponent($this->fieldTestData->field_name);
    $content = $display->build($entity);
    $this->render($content);
    $this->assertNoRaw($this->fieldTestData->field->getLabel(), "Hidden field: label is not displayed.");
    foreach ($values as $delta => $value) {
      $this->assertNoRaw("$formatter_setting|{$value['value']}", "Hidden field: value $delta is not displayed.");
    }

    
$display_options = $display->getComponent('body');
    $display_options['settings']['trim_length'] = 200;
    $display->setComponent('body', $display_options)
      ->save();

    // Render the node as a teaser again and check that the summary is now only     // 200 characters in length and so does not include 'What is a Drupalism?'.     $content = $this->drupalBuildEntityView($node, 'teaser');
    $this->assertLessThan(200, strlen($content['body'][0]['#markup']));
    $this->setRawContent($renderer->renderRoot($content));
    $this->assertText($node->label());
    $this->assertNoRaw($expected);
  }

}

  public function testStringFormatter() {
    $value = $this->randomString();
    $value .= "\n\n<strong>" . $this->randomString() . '</strong>';
    $value .= "\n\n" . $this->randomString();

    $entity = EntityTest::create([]);
    $entity->{$this->fieldName}->value = $value;

    // Verify that all HTML is escaped and newlines are retained.     $this->renderEntityFields($entity$this->display);
    $this->assertNoRaw($value);
    $this->assertRaw(nl2br(Html::escape($value)));

    // Verify the cache tags.     $build = $entity->{$this->fieldName}->view();
    $this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');
  }

}

  public function testStringFormatter() {
    $value = $this->randomString();
    $value .= "\n\n<strong>" . $this->randomString() . '</strong>';
    $value .= "\n\n" . $this->randomString();

    $entity = EntityTestRev::create([]);
    $entity->{$this->fieldName}->value = $value;

    // Verify that all HTML is escaped and newlines are retained.     $this->renderEntityFields($entity$this->display);
    $this->assertNoRaw($value);
    $this->assertRaw(nl2br(Html::escape($value)));

    // Verify the cache tags.     $build = $entity->{$this->fieldName}->view();
    $this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');

    $value = $this->randomMachineName();
    $entity->{$this->fieldName}->value = $value;
    $entity->save();

    // Set the formatter to link to the entity.
$rendered_view = $view->render('page_1');
      $output = \Drupal::service('renderer')->renderRoot($rendered_view);
      $this->setRawContent($output);
      foreach ($expected_values as $expected_entity_values) {
        if ($expected_entity_values[$entity_keys['published']] === TRUE && $expected_entity_values['default_revision'] === TRUE) {
          $this->assertRaw($expected_entity_values[$entity_keys['label']]);
        }
        // Node 4 will always appear in the 'stage' workspace because it has         // both an unpublished revision as well as a published one.         elseif ($workspace_id != 'stage' && $expected_entity_values[$entity_keys['id']] != 4) {
          $this->assertNoRaw($expected_entity_values[$entity_keys['label']]);
        }
      }

      // Add a filter on a field that is stored in a dedicated table in order to       // test field joins with extra conditions (e.g. 'deleted' and 'langcode').       $view->destroy();
      $view->setDisplay('page_1');
      $filters = $view->displayHandlers->get('page_1')->getOption('filters');
      $view->displayHandlers->get('page_1')->overrideOption('filters', $filters + [
        'body_value' => [
          'id' => 'body_value',
          
Home | Imprint | This part of the site doesn't use cookies.