Unverified Commit 9e8f44f8 authored by Klaus Purer's avatar Klaus Purer Committed by GitHub
Browse files

test(github): Test in PHP development mode and fix deprecation warnings (#1362)

parent fa8b191d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ jobs:
          php-version: ${{ matrix.php-versions }}
          # Disable Xdebug for better performance.
          coverage: none
          ini-file: development
          extensions: ${{ env.extensions }}

      - name: Get composer cache directory
+36 −8
Original line number Diff line number Diff line
@@ -20,22 +20,50 @@ class ImageDerivativeTest extends GraphQLTestBase {
   */
  protected static $modules = ['image', 'file'];

  /**
   * The file system URI under test.
   *
   * @var string
   */
  protected $fileUri;

  /**
   * The file entity mock.
   *
   * @var \Drupal\file\FileInterface
   */
  protected $file;

  /**
   * The image style for testing.
   *
   * @var \Drupal\image\Entity\ImageStyle
   */
  protected $style;

  /**
   * A file entity mock that returns FALSE on access checking.
   *
   * @var \Drupal\file\FileInterface
   */
  protected $fileNotAccessible;

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

    $this->file_uri = 'public://test.jpg';
    $this->fileUri = 'public://test.jpg';

    $this->file = $this->getMockBuilder(FileInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $this->file->method('getFileUri')->willReturn($this->file_uri);
    $this->file->method('getFileUri')->willReturn($this->fileUri);
    $this->file->method('access')->willReturn((new AccessResultAllowed())->addCacheTags(['test_tag']));
    $this->file->width = 600;
    $this->file->height = 400;
    @$this->file->width = 600;
    @$this->file->height = 400;

    $this->style = ImageStyle::create(['name' => 'test_style']);
    $effect = [
@@ -49,11 +77,11 @@ class ImageDerivativeTest extends GraphQLTestBase {
    $this->style->addImageEffect($effect);
    $this->style->save();

    $this->file_not_accessible = $this->getMockBuilder(FileInterface::class)
    $this->fileNotAccessible = $this->getMockBuilder(FileInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $this->file_not_accessible->method('access')->willReturn((new AccessResultForbidden())->addCacheTags(['test_tag_forbidden']));
    $this->fileNotAccessible->method('access')->willReturn((new AccessResultForbidden())->addCacheTags(['test_tag_forbidden']));
  }

  /**
@@ -69,7 +97,7 @@ class ImageDerivativeTest extends GraphQLTestBase {

    $this->assertEquals(
      [
        'url' => $this->style->buildUrl($this->file_uri),
        'url' => $this->style->buildUrl($this->fileUri),
        'width' => 300,
        'height' => 200,
      ],
@@ -83,7 +111,7 @@ class ImageDerivativeTest extends GraphQLTestBase {
    // Test that we don't get the derivative if we don't have access to the
    // original file, but we still get the access result cache tags.
    $result = $this->executeDataProducer('image_derivative', [
      'entity' => $this->file_not_accessible,
      'entity' => $this->fileNotAccessible,
      'style' => 'test_style',
    ]);

+24 −4
Original line number Diff line number Diff line
@@ -14,12 +14,32 @@ use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
 */
class ImageUrlTest extends GraphQLTestBase {

  /**
   * The file entity mock.
   *
   * @var \Drupal\file\FileInterface
   */
  protected $file;

  /**
   * A file entity mock that returns FALSE on access checking.
   *
   * @var \Drupal\file\FileInterface
   */
  protected $fileNotAccessible;

  /**
   * The generated file URI.
   *
   * @var string
   */
  protected $fileUri;

  /**
   * {@inheritdoc}
   */
  public function setUp(): void {
    parent::setUp();
    $this->dataProducerManager = $this->container->get('plugin.manager.graphql.data_producer');

    $this->fileUri = \Drupal::service('file_url_generator')->generateAbsoluteString('public://test.jpg');

@@ -30,11 +50,11 @@ class ImageUrlTest extends GraphQLTestBase {
    $this->file->method('getFileUri')->willReturn($this->fileUri);
    $this->file->method('access')->willReturn((new AccessResultAllowed())->addCacheTags(['test_tag']));

    $this->file_not_accessible = $this->getMockBuilder(FileInterface::class)
    $this->fileNotAccessible = $this->getMockBuilder(FileInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $this->file_not_accessible->method('access')->willReturn((new AccessResultForbidden())->addCacheTags(['test_tag_forbidden']));
    $this->fileNotAccessible->method('access')->willReturn((new AccessResultForbidden())->addCacheTags(['test_tag_forbidden']));
  }

  /**
@@ -53,7 +73,7 @@ class ImageUrlTest extends GraphQLTestBase {
    // Test that we do not get a file we don't have access to, but the cache
    // tags are still added.
    $result = $this->executeDataProducer('image_url', [
      'entity' => $this->file_not_accessible,
      'entity' => $this->fileNotAccessible,
    ]);

    $this->assertNull($result);
+0 −14
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@ namespace Drupal\Tests\graphql\Kernel\DataProducer;

use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
use Drupal\node\NodeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\UserInterface;
use Drupal\node\Entity\NodeType;
use Drupal\node\Entity\Node;

@@ -42,18 +40,6 @@ class EntityMultipleTest extends GraphQLTestBase {
  public function setUp(): void {
    parent::setUp();

    $this->entity = $this->getMockBuilder(NodeInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $this->entity_interface = $this->getMockBuilder(EntityInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $this->user = $this->getMockBuilder(UserInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $content_type = NodeType::create([
      'type' => 'lorem',
      'name' => 'ipsum',
+20 −21
Original line number Diff line number Diff line
@@ -5,11 +5,8 @@ namespace Drupal\Tests\graphql\Kernel\DataProducer;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\node\NodeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\NodeType;
use Drupal\node\Entity\Node;
use Drupal\user\UserInterface;

/**
 * Tests the entity_reference data producers.
@@ -19,24 +16,26 @@ use Drupal\user\UserInterface;
class EntityReferenceTest extends GraphQLTestBase {
  use EntityReferenceTestTrait;

  /**
   * Test node that will be referenced.
   *
   * @var \Drupal\node\Entity\Node
   */
  protected $referencedNode;

  /**
   * Test node.
   *
   * @var \Drupal\node\Entity\Node
   */
  protected $node;

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

    $this->entity = $this->getMockBuilder(NodeInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $this->entity_interface = $this->getMockBuilder(EntityInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $this->user = $this->getMockBuilder(UserInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    $content_type1 = NodeType::create([
      'type' => 'test1',
      'name' => 'ipsum1',
@@ -51,19 +50,19 @@ class EntityReferenceTest extends GraphQLTestBase {

    $this->createEntityReferenceField('node', 'test1', 'field_test1_to_test2', 'test1 lable', 'node', 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

    $this->referenced_node = Node::create([
    $this->referencedNode = Node::create([
      'title' => 'Dolor2',
      'type' => 'test2',
    ]);
    $this->referenced_node->save();
    $this->referenced_node
    $this->referencedNode->save();
    $this->referencedNode
      ->addTranslation('fr', ['title' => 'Dolor2 French'])
      ->save();

    $this->node = Node::create([
      'title' => 'Dolor',
      'type' => 'test1',
      'field_test1_to_test2' => $this->referenced_node->id(),
      'field_test1_to_test2' => $this->referencedNode->id(),
    ]);
    $this->node->save();
  }
@@ -78,7 +77,7 @@ class EntityReferenceTest extends GraphQLTestBase {
      'access' => TRUE,
      'access_operation' => 'view',
    ]);
    $this->assertEquals($this->referenced_node->id(), reset($result)->id());
    $this->assertEquals($this->referencedNode->id(), reset($result)->id());
    $this->assertEquals('Dolor2', reset($result)->label());

    $result = $this->executeDataProducer('entity_reference', [
@@ -88,7 +87,7 @@ class EntityReferenceTest extends GraphQLTestBase {
      'access_operation' => 'view',
      'language' => 'fr',
    ]);
    $this->assertEquals($this->referenced_node->id(), reset($result)->id());
    $this->assertEquals($this->referencedNode->id(), reset($result)->id());
    $this->assertEquals('Dolor2 French', reset($result)->label());
  }

Loading