assertSubString example

// Setup the general settings required to build a link.     $id_field->options['alter']['make_link'] = TRUE;
    $id_field->options['alter']['path'] = $path = $this->randomMachineName();

    // Tests that the suffix/prefix appears on the output.     $id_field->options['alter']['prefix'] = $prefix = $this->randomMachineName();
    $id_field->options['alter']['suffix'] = $suffix = $this->randomMachineName();
    $output = $renderer->executeInRenderContext(new RenderContext()function D) use ($id_field$row) {
      return $id_field->theme($row);
    });
    $this->assertSubString($output$prefix);
    $this->assertSubString($output$suffix);
    unset($id_field->options['alter']['prefix']);
    unset($id_field->options['alter']['suffix']);

    $output = $renderer->executeInRenderContext(new RenderContext()function D) use ($id_field$row) {
      return $id_field->theme($row);
    });
    $this->assertSubString($output$path, 'Make sure that the path is part of the output');

    // Some generic test code adapted from the UrlTest class, which tests     // mostly the different options for the path.
// Don't check the rewrite checkbox, so the text shouldn't appear.     $id_field->options['alter']['text'] = $random_text = $this->randomMachineName();
    $output = $renderer->executeInRenderContext(new RenderContext()function D) use ($id_field$row) {
      return $id_field->theme($row);
    });
    $this->assertNotSubString($output$random_text);

    $id_field->options['alter']['alter_text'] = TRUE;
    $output = $renderer->executeInRenderContext(new RenderContext()function D) use ($id_field$row) {
      return $id_field->theme($row);
    });
    $this->assertSubString($output$random_text);
  }

  /** * Tests rewriting of the output with HTML. */
  public function testRewriteHtmlWithTokens() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');

    $view = Views::getView('test_view');
    $view->initHandlers();
    
Home | Imprint | This part of the site doesn't use cookies.