reviewer-1.2.x-dev/modules/reviewer_test_kit/tests/src/Kernel/Entity/Display/TaskExceptionsTest.php

modules/reviewer_test_kit/tests/src/Kernel/Entity/Display/TaskExceptionsTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\reviewer_test_kit\Kernel\Entity\Display;

use Drupal\reviewer\Reviewer\Action;
use Drupal\reviewer_test_kit\Plugin\reviewer\Task\Entity\Display\DisplayFieldsTaskBase;
use Drupal\reviewer_test_kit\Plugin\reviewer\Task\Entity\Display\DisplayTaskBase;
use Drupal\reviewer_test_kit\Plugin\reviewer\Task\Entity\Display\FieldPluginsTaskBase;
use Drupal\reviewer_test_kit\Plugin\reviewer\Task\Entity\Display\FieldSettingsTaskBase;
use Drupal\Tests\reviewer_test_kit\Kernel\Entity\EntityTaskBaseTestBase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;

/**
 * Test that the correct exceptions are thrown when properties are missing.
 */
#[Group('reviewer')]
#[CoversClass(DisplayTaskBase::class)]
#[CoversClass(DisplayFieldsTaskBase::class)]
#[CoversClass(FieldSettingsTaskBase::class)]
#[CoversClass(FieldPluginsTaskBase::class)]
final class TaskExceptionsTest extends EntityTaskBaseTestBase {

  /**
   * Test that the correct exceptions are thrown on missing properties.
   *
   * @throws \Exception
   * @throws \PHPUnit\Framework\ExpectationFailedException
   * @throws \PHPUnit\Framework\UnknownClassOrInterfaceException
   */
  public function testExceptions(): void {
    $expected_exceptions = [
      'Property Drupal\reviewer_test_kit_test\Plugin\reviewer\Task\Entity\Display\Exceptions\TestNoAllowedPluginsTask::displayType cannot be empty.',
      'Property Drupal\reviewer_test_kit_test\Plugin\reviewer\Task\Entity\Display\Exceptions\TestNoExpectedSettingsTask::expectedValues cannot be empty.',
      'Property Drupal\reviewer_test_kit_test\Plugin\reviewer\Task\Entity\Display\Exceptions\TestNoDisplayTypeTask::displayType cannot be empty.',
      'Both Drupal\reviewer_test_kit_test\Plugin\reviewer\Task\Entity\Display\Exceptions\TestNoFieldTypesNorNamesTask::fieldTypes and Drupal\reviewer_test_kit_test\Plugin\reviewer\Task\Entity\Display\Exceptions\TestNoFieldTypesNorNamesTask::fieldNames properties cannot be empty.',
    ];

    // Check that the check method throws exceptions.
    $review = $this->runOneTaskReview(Action::Check, 'test_exceptions_review');
    $results = $review->getResults()->getIndividualResults();
    // Check that there are errors.
    self::assertNotCount(0, $results);
    // Check that each exception is reported correctly.
    foreach (array_values($results) as $index => $result) {
      // If the message is not in the expected list, then we are testing if a
      // task with either field types or field names, but not both, do not throw
      // exceptions. The tasks are malformed and report garbage errors, we just
      // need to check that the common part of the exception messages is not
      // preset.
      if (isset($expected_exceptions[$index])) {
        self::assertSame($expected_exceptions[$index], $result->getMessage());
      }
      else {
        self::assertStringNotContainsString('cannot be empty.', $result->getMessage());
      }
    }

    // Check that the fix method throws exceptions.
    $review = $this->runOneTaskReview(Action::Fix, 'test_exceptions_review');
    $results = $review->getResults()->getIndividualResults();
    // Check that there are errors.
    self::assertNotCount(0, $results);
    // Check that each exception is reported correctly.
    foreach (array_values($results) as $index => $result) {
      // If the message is not in the expected list, then we are testing if a
      // task with either field types or field names, but not both, do not throw
      // exceptions. The tasks are malformed and report garbage errors, we just
      // need to check that the common part of the exception messages is not
      // preset.
      if (isset($expected_exceptions[$index])) {
        self::assertSame($expected_exceptions[$index], $result->getMessage());
      }
      else {
        self::assertStringNotContainsString('cannot be empty.', $result->getMessage());
      }
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc