function LinkTest::linkComparisonProvider

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Unit/JsonApiResource/LinkTest.php \Drupal\Tests\jsonapi\Unit\JsonApiResource\LinkTest::linkComparisonProvider()
  2. 8.9.x core/modules/jsonapi/tests/src/Unit/JsonApiResource/LinkTest.php \Drupal\Tests\jsonapi\Unit\JsonApiResource\LinkTest::linkComparisonProvider()
  3. 11.x core/modules/jsonapi/tests/src/Unit/JsonApiResource/LinkTest.php \Drupal\Tests\jsonapi\Unit\JsonApiResource\LinkTest::linkComparisonProvider()

Provides test data for link comparison.

File

core/modules/jsonapi/tests/src/Unit/JsonApiResource/LinkTest.php, line 40

Class

LinkTest
@coversDefaultClass \Drupal\jsonapi\JsonApiResource\Link[[api-linebreak]] @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\JsonApiResource

Code

public static function linkComparisonProvider() : \Generator {
  (yield 'same href and same link relation type' => [
    [
      'https://jsonapi.org/foo',
      'self',
    ],
    [
      'https://jsonapi.org/foo',
      'self',
    ],
    TRUE,
  ]);
  (yield 'different href and same link relation type' => [
    [
      'https://jsonapi.org/foo',
      'self',
    ],
    [
      'https://jsonapi.org/bar',
      'self',
    ],
    FALSE,
  ]);
  (yield 'same href and different link relation type' => [
    [
      'https://jsonapi.org/foo',
      'self',
    ],
    [
      'https://jsonapi.org/foo',
      'related',
    ],
    FALSE,
  ]);
  (yield 'same href and same link relation type and empty target attributes' => [
    [
      'https://jsonapi.org/foo',
      'self',
      [],
    ],
    [
      'https://jsonapi.org/foo',
      'self',
      [],
    ],
    TRUE,
  ]);
  (yield 'same href and same link relation type and same target attributes' => [
    [
      'https://jsonapi.org/foo',
      'self',
      [
        'anchor' => 'https://jsonapi.org',
      ],
    ],
    [
      'https://jsonapi.org/foo',
      'self',
      [
        'anchor' => 'https://jsonapi.org',
      ],
    ],
    TRUE,
  ]);
  // These links are not considered equivalent because it would while the
  // `href` remains the same, the anchor changes the context of the link.
  (yield 'same href and same link relation type and different target attributes' => [
    [
      'https://jsonapi.org/boy',
      'self',
      [
        'title' => 'sue',
      ],
    ],
    [
      'https://jsonapi.org/boy',
      'self',
      [
        'anchor' => '/sob',
        'title' => 'pa',
      ],
    ],
    FALSE,
  ]);
  (yield 'same href and same link relation type and same nested target attributes' => [
    [
      'https://jsonapi.org/foo',
      'self',
      [
        'data' => [
          'foo' => 'bar',
        ],
      ],
    ],
    [
      'https://jsonapi.org/foo',
      'self',
      [
        'data' => [
          'foo' => 'bar',
        ],
      ],
    ],
    TRUE,
  ]);
  (yield 'same href and same link relation type and different nested target attributes' => [
    [
      'https://jsonapi.org/foo',
      'self',
      [
        'data' => [
          'foo' => 'bar',
        ],
      ],
    ],
    [
      'https://jsonapi.org/foo',
      'self',
      [
        'data' => [
          'foo' => 'baz',
        ],
      ],
    ],
    FALSE,
  ]);
  // These links are not considered equivalent because it would be unclear
  // which title corresponds to which link relation type.
  (yield 'same href and different link relation types and different target attributes' => [
    [
      'https://jsonapi.org/boy',
      'self',
      [
        'title' => 'A boy named Sue',
      ],
    ],
    [
      'https://jsonapi.org/boy',
      'edit',
      [
        'title' => 'Change name to Bill or George',
      ],
    ],
    FALSE,
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.