Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php declare(strict_types=1); namespace Drupal\Tests\announcements_feed\FunctionalJavas..

Decoded Output download

<?php

declare(strict_types=1);

namespace Drupal\Testsnnouncements_feed\FunctionalJavascript;

use Drupalnnounce_feed_test\AnnounceTestHttpClientMiddleware;
use Drupallock\BlockInterface;
use Drupal\Core\Access\AccessResultAllowed;
use Drupal\Core\Access\AccessResultNeutral;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

/**
 * Test the announcement block test visibility.
 *
 * @group announcements_feed
 */
class AnnounceBlockTest extends WebDriverTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'announcements_feed',
    'block',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * The announce block instance.
   *
   * @var \Drupallock\BlockInterface
   */
  protected BlockInterface $announceBlock;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    AnnounceTestHttpClientMiddleware::setAnnounceTestEndpoint('/announce-feed-json/community-feeds');
    $this->announceBlock = $this->placeBlock('announce_block', [
      'label' => 'Announcements Feed',
    ]);
  }

  /**
   * Testing announce feed block visibility.
   */
  public function testAnnounceWithoutPermission(): void {
    // User with "access announcements" permission and anonymous session.
    $account = $this->drupalCreateUser([
      'access announcements',
    ]);
    $anonymous_account = new AnonymousUserSession();

    $this->drupalLogin($account);
    $this->drupalGet('<front>');

    $assert_session = $this->assertSession();

    // Block should be visible for the user.
    $assert_session->pageTextContains('Announcements Feed');

    // Block is not accessible without permission.
    $this->drupalLogout();
    $assert_session->pageTextNotContains('Announcements Feed');

    // Test access() method return type.
    $this->assertTrue($this->announceBlock->getPlugin()->access($account));
    $this->assertInstanceOf(AccessResultAllowed::class, $this->announceBlock->getPlugin()->access($account, TRUE));

    $this->assertFalse($this->announceBlock->getPlugin()->access($anonymous_account));
    $this->assertInstanceOf(AccessResultNeutral::class, $this->announceBlock->getPlugin()->access($anonymous_account, TRUE));
  }

}
 ?>

Did this file decode correctly?

Original Code

<?php

declare(strict_types=1);

namespace Drupal\Tests\announcements_feed\FunctionalJavascript;

use Drupal\announce_feed_test\AnnounceTestHttpClientMiddleware;
use Drupal\block\BlockInterface;
use Drupal\Core\Access\AccessResultAllowed;
use Drupal\Core\Access\AccessResultNeutral;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

/**
 * Test the announcement block test visibility.
 *
 * @group announcements_feed
 */
class AnnounceBlockTest extends WebDriverTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'announcements_feed',
    'block',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * The announce block instance.
   *
   * @var \Drupal\block\BlockInterface
   */
  protected BlockInterface $announceBlock;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    AnnounceTestHttpClientMiddleware::setAnnounceTestEndpoint('/announce-feed-json/community-feeds');
    $this->announceBlock = $this->placeBlock('announce_block', [
      'label' => 'Announcements Feed',
    ]);
  }

  /**
   * Testing announce feed block visibility.
   */
  public function testAnnounceWithoutPermission(): void {
    // User with "access announcements" permission and anonymous session.
    $account = $this->drupalCreateUser([
      'access announcements',
    ]);
    $anonymous_account = new AnonymousUserSession();

    $this->drupalLogin($account);
    $this->drupalGet('<front>');

    $assert_session = $this->assertSession();

    // Block should be visible for the user.
    $assert_session->pageTextContains('Announcements Feed');

    // Block is not accessible without permission.
    $this->drupalLogout();
    $assert_session->pageTextNotContains('Announcements Feed');

    // Test access() method return type.
    $this->assertTrue($this->announceBlock->getPlugin()->access($account));
    $this->assertInstanceOf(AccessResultAllowed::class, $this->announceBlock->getPlugin()->access($account, TRUE));

    $this->assertFalse($this->announceBlock->getPlugin()->access($anonymous_account));
    $this->assertInstanceOf(AccessResultNeutral::class, $this->announceBlock->getPlugin()->access($anonymous_account, TRUE));
  }

}

Function Calls

None

Variables

None

Stats

MD5 861541f71a1eda5bfe7fb645e8481a7f
Eval Count 0
Decode Time 95 ms