function LinkTest::linkComparisonProvider

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Unit/JsonApiResource/LinkTest.php \Drupal\Tests\jsonapi\Unit\JsonApiResource\LinkTest::linkComparisonProvider()
  2. 10 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 33

Class

LinkTest
@coversDefaultClass \Drupal\jsonapi\JsonApiResource\Link @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\JsonApiResource

Code

public function linkComparisonProvider() {
    $this->mockUrlAssembler();
    return [
        'same href and same link relation type' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self'),
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self'),
            TRUE,
        ],
        'different href and same link relation type' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self'),
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/bar'), 'self'),
            FALSE,
        ],
        'same href and different link relation type' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self'),
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'related'),
            FALSE,
        ],
        'same href and same link relation type and empty target attributes' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', []),
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', []),
            TRUE,
        ],
        'same href and same link relation type and same target attributes' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', [
                'anchor' => 'https://jsonapi.org',
            ]),
            new Link(new CacheableMetadata(), Url::fromUri('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.
'same href and same link relation type and different target attributes' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/boy'), 'self', [
                'title' => 'sue',
            ]),
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/boy'), 'self', [
                'anchor' => '/sob',
                'title' => 'pa',
            ]),
            FALSE,
        ],
        'same href and same link relation type and same nested target attributes' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', [
                'data' => [
                    'foo' => 'bar',
                ],
            ]),
            new Link(new cacheablemetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', [
                'data' => [
                    'foo' => 'bar',
                ],
            ]),
            TRUE,
        ],
        'same href and same link relation type and different nested target attributes' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', [
                'data' => [
                    'foo' => 'bar',
                ],
            ]),
            new Link(new CacheableMetadata(), Url::fromUri('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.
'same href and different link relation types and different target attributes' => [
            new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/boy'), 'self', [
                'title' => 'A boy named Sue',
            ]),
            new Link(new CacheableMetadata(), Url::fromUri('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.