Welcome To Our Shell

Mister Spy & Souheyl Bypass Shell

Current Path : /var/www/html/rocksensor1/web/core/modules/workspaces/tests/src/Kernel/

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/rocksensor1/web/core/modules/workspaces/tests/src/Kernel/WorkspacePublishFormTest.php

<?php

declare(strict_types=1);

namespace Drupal\Tests\workspaces\Kernel;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\workspaces\Entity\Workspace;
use Drupal\workspaces\Form\WorkspacePublishForm;
use Drupal\workspaces\WorkspaceOperationFactory;
use Drupal\workspaces\WorkspacePublisherInterface;
use Psr\Log\LoggerInterface;

/**
 * @coversDefaultClass \Drupal\workspaces\Form\WorkspacePublishForm
 * @group workspaces
 */
class WorkspacePublishFormTest extends KernelTestBase {

  /**
   * @covers ::submitForm
   */
  public function testSubmitFormWithException(): void {
    /** @var \Drupal\Core\Messenger\MessengerInterface $messenger */
    $messenger = \Drupal::service('messenger');

    $workspaceOperationFactory = $this->createMock(WorkspaceOperationFactory::class);
    $entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $logger = $this->createMock(LoggerInterface::class);
    /** @var \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory */
    $loggerFactory = \Drupal::service('logger.factory');
    $loggerFactory->addLogger($logger);

    $workspace = $this->createMock(Workspace::class);
    $workspacePublisher = $this->createMock(WorkspacePublisherInterface::class);

    $workspace
      ->expects($this->any())
      ->method('label');

    $workspace
      ->expects($this->once())
      ->method('publish')
      ->willThrowException(new \Exception('Unexpected error'));

    $workspaceOperationFactory
      ->expects($this->once())
      ->method('getPublisher')
      ->willReturn($workspacePublisher);

    $workspacePublisher
      ->expects($this->once())
      ->method('getTargetLabel');

    $publishForm = new WorkspacePublishForm(
      $workspaceOperationFactory,
      $entityTypeManager
    );

    $form = [];
    $formState = new FormState();

    $publishForm->buildForm($form, $formState, $workspace);

    $logger
      ->expects($this->once())
      ->method('log')
      ->with(RfcLogLevel::ERROR, 'Unexpected error');

    $publishForm->submitForm($form, $formState);

    $messages = $messenger->messagesByType(MessengerInterface::TYPE_ERROR);
    $this->assertCount(1, $messages);
    $this->assertEquals('Publication failed. All errors have been logged.', $messages[0]);
  }

}

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