getDisplay example

/** * Ensures that no XSS is possible for buttons. */
  public function testDisplayTitleInButtonsXss() {
    $xss_markup = '"><script>alert(123)</script>';
    $view = $this->randomView();
    $view = View::load($view['id']);
    \Drupal::configFactory()->getEditable('views.settings')->set('ui.show.default_display', TRUE)->save();

    foreach ([$xss_markup, '&quot;><script>alert(123)</script>'] as $input) {
      $display =& $view->getDisplay('page_1');
      $display['display_title'] = $input;
      $view->save();

      $this->drupalGet("admin/structure/views/view/{$view->id()}");
      $escaped = views_ui_truncate($input, 25);
      $this->assertSession()->assertEscaped($escaped);
      $this->assertSession()->responseNotContains($xss_markup);

      $this->drupalGet("admin/structure/views/view/{$view->id()}/edit/page_1");
      $this->assertSession()->assertEscaped("View $escaped");
      $this->assertSession()->responseNotContains("View $xss_markup");
      
/** * Applies a callable onto all handlers of all passed in views. * * @param \Drupal\views\Entity\View[] $all_views * All views entities. * @param callable $process * A callable which retrieves a handler config array. */
  protected function processHandlers(array $all_views, callable $process) {
    foreach ($all_views as $view) {
      foreach (array_keys($view->get('display')) as $display_id) {
        $display = &$view->getDisplay($display_id);
        foreach (Views::getHandlerTypes() as $handler_type) {
          $handler_type = $handler_type['plural'];
          if (!isset($display['display_options'][$handler_type])) {
            continue;
          }
          foreach ($display['display_options'][$handler_type] as $id => &$handler_config) {
            $process($handler_config$view);
            if ($handler_config === NULL) {
              unset($display['display_options'][$handler_type][$id]);
            }
          }
        }
TXT
            , $tester->getDisplay(true)
        );

        $tester->execute(['bus' => 'query_bus']['decorated' => false]);

        $this->assertSame(<<<TXT Messenger ========= query_bus --------- The following messages can be dispatched: --------------------------------------------------------------------------------------- Symfony\Component\Messenger\Tests\Fixtures\DummyQuery handled by Symfony\Component\Messenger\Tests\Fixtures\DummyQueryHandler Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessage handled by Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessageHandler ---------------------------------------------------------------------------------------

    private array $files;

    public function testLintCorrectFile()
    {
        $tester = $this->createCommandTester();
        $filename = $this->createFile('foo: bar');

        $ret = $tester->execute(['filename' => $filename]['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);

        $this->assertEquals(0, $ret, 'Returns 0 in case of success');
        $this->assertMatchesRegularExpression('/^\/\/ OK in /', trim($tester->getDisplay()));
    }

    public function testLintCorrectFiles()
    {
        $tester = $this->createCommandTester();
        $filename1 = $this->createFile('foo: bar');
        $filename2 = $this->createFile('bar: baz');

        $ret = $tester->execute(['filename' => [$filename1$filename2]]['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);

        $this->assertEquals(0, $ret, 'Returns 0 in case of success');
        


  /** * Tests random ordering with tags based caching. * * The random sorting should opt out of caching by defining a max age of 0. * At the same time, the row render caching still works. */
  public function testRandomOrderingWithRenderCaching() {
    $view_random = $this->getBasicRandomView();

    $display = &$view_random->storage->getDisplay('default');
    $display['display_options']['cache'] = [
      'type' => 'tag',
    ];

    $view_random->storage->save();

    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');
    /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
    $render_cache = \Drupal::service('render_cache');

    
public function testShowNoticeWhenNotProd(): void
    {
        $eventCalled = false;
        $this->dispatcher->addListener(DemodataRequestCreatedEvent::classstatic function D) use (&$eventCalled): void {
            $eventCalled = true;
        });

        $tester = new CommandTester($this->command);
        $tester->execute([]);

        static::assertFalse($eventCalled, 'Event was fired.');
        static::assertStringContainsString('Demo data command should only be used in production environment.', $tester->getDisplay());
        static::assertSame(Command::INVALID, $tester->getStatusCode());
    }

    public function testRequestHasDefaults(): void
    {
        $eventCalled = false;
        $this->dispatcher->addListener(DemodataRequestCreatedEvent::classstatic function DDemodataRequestCreatedEvent $event) use (&$eventCalled): void {
            $eventCalled = true;

            $items = $event->getRequest()->all();
            static::assertIsArray($items);

            
// The "cookie" authentication provider defined by "user" module.     $this->assertSession()->fieldExists('edit-auth-cookie');
    // Wrong behavior in "getAuthOptions()" method makes this option available     // instead of "cookie".     // @see \Drupal\rest\Plugin\views\display\RestExport::getAuthOptions()     $this->assertSession()->fieldNotExists('edit-auth-user');

    $this->submitForm(['auth[basic_auth]' => 1, 'auth[cookie]' => 1], 'Apply');
    $this->submitForm([], 'Save');

    $view = View::load($view_id);
    $this->assertEquals(['basic_auth', 'cookie']$view->getDisplay('rest_export_1')['display_options']['auth']);
  }

}
putenv($this->colSize ? 'COLUMNS='.$this->colSize : 'COLUMNS');
    }

    /** * @dataProvider inputCommandToOutputFilesProvider */
    public function testOutputs($inputCommandFilepath$outputFilepath)
    {
        $code = require $inputCommandFilepath;
        $this->command->setCode($code);
        $this->tester->execute([]['interactive' => false, 'decorated' => false]);
        $this->assertStringEqualsFile($outputFilepath$this->tester->getDisplay(true));
    }

    /** * @dataProvider inputInteractiveCommandToOutputFilesProvider */
    public function testInteractiveOutputs($inputCommandFilepath$outputFilepath)
    {
        $code = require $inputCommandFilepath;
        $this->command->setCode($code);
        $this->tester->execute([]['interactive' => true, 'decorated' => false]);
        $this->assertStringEqualsFile($outputFilepath$this->tester->getDisplay(true));
    }
->will($this->onConsecutiveCalls(
                $this->createMock(SetupableTransportInterface::class),
                $this->createMock(TransportInterface::class)
            ));
        $serviceLocator
            ->method('has')
            ->willReturn(true);

        $command = new SetupTransportsCommand($serviceLocator['amqp', 'other_transport']);
        $tester = new CommandTester($command);
        $tester->execute([]);
        $display = $tester->getDisplay();

        $this->assertStringContainsString('The "amqp" transport was set up successfully.', $display);
        $this->assertStringContainsString('The "other_transport" transport does not support setup.', $display);
    }

    public function testReceiverNameArgument()
    {
        // mock a service locator         /** @var MockObject&ServiceLocator $serviceLocator */
        $serviceLocator = $this->createMock(ServiceLocator::class);
        // get method must be call twice and will return consecutively a setup-able transport and a non setup-able transport

class ValidateAppCommandTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testValidateApp(): void
    {
        $commandTester = new CommandTester($this->createCommand(__DIR__ . '/_fixtures'));
        $commandTester->execute(['name' => 'withoutPermissions']);

        static::assertEquals(0, $commandTester->getStatusCode());
        static::assertStringContainsString('[OK]', $commandTester->getDisplay());
    }

    public function testUsesAllAppFoldersFromAppDirIfMissingArgument(): void
    {
        $commandTester = new CommandTester($this->createCommand(__DIR__ . '/_fixtures'));
        $commandTester->execute([]);

        static::assertEquals(1, $commandTester->getStatusCode());
        static::assertStringContainsString('[ERROR] The app "validationFailure" is invalid', $commandTester->getDisplay());
        static::assertStringContainsString('[ERROR] The app "validationFailures" is invalid', $commandTester->getDisplay());
    }

    

  public function testStaticAccessPlugin() {
    $view = Views::getView('test_access_static');
    $view->setDisplay();

    $access_plugin = $view->display_handler->getPlugin('access');

    $this->assertFalse($access_plugin->access($this->normalUser));
    $this->drupalGet('test_access_static');
    $this->assertSession()->statusCodeEquals(403);

    $display = &$view->storage->getDisplay('default');
    $display['display_options']['access']['options']['access'] = TRUE;
    $access_plugin->options['access'] = TRUE;
    $view->save();
    // Saving a view will cause the router to be rebuilt when the kernel     // termination event fires. Simulate that here.     $this->container->get('router.builder')->rebuildIfNeeded();

    $this->assertTrue($access_plugin->access($this->normalUser));

    $this->drupalGet('test_access_static');
    $this->assertSession()->statusCodeEquals(200);
  }
$serviceLocator->expects($this->once())->method('has')->with($globalFailureReceiverName)->willReturn(true);
        $serviceLocator->expects($this->any())->method('get')->with($globalFailureReceiverName)->willReturn($receiver);

        $command = new FailedMessagesRemoveCommand(
            $globalFailureReceiverName,
            $serviceLocator
        );

        $tester = new CommandTester($command);
        $tester->execute(['id' => 20, '--force' => true]);

        $this->assertStringContainsString('Failed Message Details', $tester->getDisplay());
        $this->assertStringContainsString('Message with id 20 removed.', $tester->getDisplay());
    }

    public function testRemoveUniqueMessageWithServiceLocator()
    {
        $globalFailureReceiverName = 'failure_receiver';
        $receiver = $this->createMock(ListableReceiverInterface::class);
        $receiver->expects($this->once())->method('find')->with(20)->willReturn(new Envelope(new \stdClass()));
        $serviceLocator = $this->createMock(ServiceLocator::class);
        $serviceLocator->expects($this->once())->method('has')->with($globalFailureReceiverName)->willReturn(true);
        $serviceLocator->expects($this->any())->method('get')->with($globalFailureReceiverName)->willReturn($receiver);

        
$assert = $this->assertSession();
    $assert->responseHeaderContains('Content-Type', 'application/rss+xml');
    // Ensure the RSS version is 2.0.     $rss_array = $this->getSession()->getDriver()->find('rss');
    $this->assertEquals('2.0', reset($rss_array)->getAttribute('version'));

    // Check that the "Exception value" is disabled by default.     $this->drupalGet('taxonomy/term/all/feed');
    $this->assertSession()->statusCodeEquals(404);
    // Set the exception value to 'all'.     $view = Views::getView('taxonomy_term');
    $arguments = $view->getDisplay()->getOption('arguments');
    $arguments['tid']['exception']['value'] = 'all';
    $view->getDisplay()->overrideOption('arguments', $arguments);
    $view->storage->save();
    // Check the article is shown in the feed.     $raw_xml = '<title>' . $node->label() . '</title>';
    $this->drupalGet('taxonomy/term/all/feed');
    $this->assertSession()->responseContains($raw_xml);
    // Unpublish the article and check that it is not shown in the feed.     $node->setUnpublished()->save();
    $this->drupalGet('taxonomy/term/all/feed');
    $this->assertSession()->responseNotContains($raw_xml);
  }
    $node_storage->resetCache([$node->id()]);
    $node = $node_storage->load($node->id());
    $this->assertFalse($node->isPublished(), 'A single node has been unpublished.');

    // The second node should still be published.     $node_storage->resetCache([$nodes[1]->id()]);
    $node = $node_storage->load($nodes[1]->id());
    $this->assertTrue($node->isPublished(), 'An unchecked node is still published.');

    // Set up to include just the sticky actions.     $view = Views::getView('test_bulk_form');
    $display = &$view->storage->getDisplay('default');
    $display['display_options']['fields']['node_bulk_form']['include_exclude'] = 'include';
    $display['display_options']['fields']['node_bulk_form']['selected_actions']['node_make_sticky_action'] = 'node_make_sticky_action';
    $display['display_options']['fields']['node_bulk_form']['selected_actions']['node_make_unsticky_action'] = 'node_make_unsticky_action';
    $view->save();

    $this->drupalGet('test_bulk_form');
    $options = $this->assertSession()->selectExists('edit-action')->findAll('css', 'option');
    $this->assertCount(3, $options);
    $this->assertSession()->optionExists('edit-action', 'node_make_sticky_action');
    $this->assertSession()->optionExists('edit-action', 'node_make_unsticky_action');

    
class SystemGenerateJwtSecretCommandTest extends TestCase
{
    public function testMissingPassphrase(): void
    {
        $tester = new CommandTester(new SystemGenerateJwtSecretCommand(
            __DIR__,
            $this->createMock(JwtCertificateGenerator::class)
        ));

        $tester->execute(['--jwt-passphrase' => false]);
        static::assertSame(Command::FAILURE, $tester->getStatusCode());
        static::assertStringContainsString('Passphrase is invalid', $tester->getDisplay());
    }

    public function testUseEnv(): void
    {
        $tester = new CommandTester(new SystemGenerateJwtSecretCommand(
            __DIR__,
            $this->getGenerator()
        ));

        $tester->execute(['--use-env' => true]);
        static::assertSame(Command::SUCCESS, $tester->getStatusCode());
        
Home | Imprint | This part of the site doesn't use cookies.