Commit 843bfc19 authored by catch's avatar catch
Browse files

Issue #3462264 by alexpott: Skip unsupported methods in rest/jsonapi tests in an efficient way

(cherry picked from commit d3e85883)
parent 9c482363
Loading
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\user\Entity\User;
use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\Attributes\Before;

abstract class CommentResourceTestBase extends EntityResourceTestBase {

@@ -50,6 +51,16 @@ abstract class CommentResourceTestBase extends EntityResourceTestBase {
   */
  protected $entity;

  /**
   * Marks some tests as skipped because XML cannot be deserialized.
   */
  #[Before]
  public function commentResourceTestBaseSkipTests(): void {
    if (static::$format === 'xml' && in_array($this->name(), ['testPostDxWithoutCriticalBaseFields', 'testPostSkipCommentApproval'], TRUE)) {
      $this->markTestSkipped('Deserialization of the XML format is not supported.');
    }
  }

  /**
   * {@inheritdoc}
   */
+0 −16
Original line number Diff line number Diff line
@@ -52,20 +52,4 @@ class CommentXmlAnonTest extends CommentResourceTestBase {
    'field_name',
  ];

  /**
   * {@inheritdoc}
   */
  public function testPostDxWithoutCriticalBaseFields(): void {
    // Deserialization of the XML format is not supported.
    $this->markTestSkipped();
  }

  /**
   * {@inheritdoc}
   */
  public function testPostSkipCommentApproval(): void {
    // Deserialization of the XML format is not supported.
    $this->markTestSkipped();
  }

}
+0 −16
Original line number Diff line number Diff line
@@ -41,20 +41,4 @@ class CommentXmlBasicAuthTest extends CommentResourceTestBase {
   */
  protected static $auth = 'basic_auth';

  /**
   * {@inheritdoc}
   */
  public function testPostDxWithoutCriticalBaseFields(): void {
    // Deserialization of the XML format is not supported.
    $this->markTestSkipped();
  }

  /**
   * {@inheritdoc}
   */
  public function testPostSkipCommentApproval(): void {
    // Deserialization of the XML format is not supported.
    $this->markTestSkipped();
  }

}
+0 −16
Original line number Diff line number Diff line
@@ -36,20 +36,4 @@ class CommentXmlCookieTest extends CommentResourceTestBase {
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  public function testPostDxWithoutCriticalBaseFields(): void {
    // Deserialization of the XML format is not supported.
    $this->markTestSkipped();
  }

  /**
   * {@inheritdoc}
   */
  public function testPostSkipCommentApproval(): void {
    // Deserialization of the XML format is not supported.
    $this->markTestSkipped();
  }

}
+17 −13
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\file\Entity\File;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\user\Entity\User;
use PHPUnit\Framework\Attributes\Before;

abstract class FileResourceTestBase extends EntityResourceTestBase {

@@ -41,6 +42,22 @@ abstract class FileResourceTestBase extends EntityResourceTestBase {
   */
  protected $author;

  /**
   * Marks some tests as skipped because XML cannot be deserialized.
   */
  #[Before]
  public function fileResourceTestBaseSkipTests(): void {
    if ($this->name() === 'testPost') {
      // Drupal does not allow creating file entities independently. It allows
      // you to create file entities that are referenced from another entity
      // (e.g. an image for a node's image field).
      // For that purpose, there is the "file_upload" REST resource plugin.
      // @see \Drupal\file\FileAccessControlHandler::checkCreateAccess()
      // @see \Drupal\file\Plugin\rest\resource\FileUploadResource
      $this->markTestSkipped('Drupal does not allow creating file entities independently.');
    }
  }

  /**
   * {@inheritdoc}
   */
@@ -197,19 +214,6 @@ protected function getExpectedCacheContexts() {
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function testPost(): void {
    // Drupal does not allow creating file entities independently. It allows you
    // to create file entities that are referenced from another entity (e.g. an
    // image for a node's image field).
    // For that purpose, there is the "file_upload" REST resource plugin.
    // @see \Drupal\file\FileAccessControlHandler::checkCreateAccess()
    // @see \Drupal\file\Plugin\rest\resource\FileUploadResource
    $this->markTestSkipped();
  }

  /**
   * {@inheritdoc}
   */
Loading