function TaxonomyTermArgumentDepthTest::testTermWithDepthFilter

Same name in other branches
  1. 10 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTermArgumentDepthTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTermArgumentDepthTest::testTermWithDepthFilter()
  2. 11.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTermArgumentDepthTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTermArgumentDepthTest::testTermWithDepthFilter()

Tests the terms with depth filter.

File

core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTermArgumentDepthTest.php, line 93

Class

TaxonomyTermArgumentDepthTest
Test the taxonomy term with depth argument.

Namespace

Drupal\Tests\taxonomy\Kernel\Views

Code

public function testTermWithDepthFilter() : void {
    // Default view has an empty value for this filter, so all nodes should be
    // returned.
    $expected = [
        [
            'nid' => 1,
        ],
        [
            'nid' => 2,
        ],
        [
            'nid' => 3,
        ],
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
        [
            'nid' => 6,
        ],
    ];
    $this->executeView($this->view);
    $this->assertIdenticalResultsetHelper($this->view, $expected, [
        'nid' => 'nid',
    ], 'assertIdentical');
    // Set filter to search on top-level term, with depth 0.
    $expected = [
        [
            'nid' => 4,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[0]
        ->id(), 0);
    // Top-level term, depth 1.
    $expected = [
        [
            'nid' => 4,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[0]
        ->id(), 1);
    // Top-level term, depth 2.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[0]
        ->id(), 2);
    // Top-level term, depth 9.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
        [
            'nid' => 6,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[0]
        ->id(), 9);
    // Second-level term, depth 1.
    $expected = [
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[1]
        ->id(), 1);
    // Third-level term, depth 0.
    $expected = [
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[2]
        ->id(), 0);
    // Third-level term, depth 1.
    $expected = [
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[2]
        ->id(), 1);
    // Third-level term, depth -2.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[2]
        ->id(), -2);
    // Third-level term, depth -9.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[2]
        ->id(), -9);
    // Fifth-level term, depth -9.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
        [
            'nid' => 6,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[4]
        ->id(), -9);
    // Third-level term, depth -1.
    $expected = [
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[2]
        ->id(), -1);
    // Third-level and second-level term, depth -1, using a plus sign.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[2]
        ->id() . '+' . $this->terms[1]
        ->id(), -1, TRUE);
    // Third-level and second-level term, depth -1, using a comma. Note that due
    // to performance the "and" meaning of comma is not supported.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[2]
        ->id() . ',' . $this->terms[1]
        ->id(), -1, TRUE);
    // Top-level term and second level term, depth 1, using a plus sign.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[0]
        ->id() . '+' . $this->terms[1]
        ->id(), 1, TRUE);
    // Top-level term and second level term, depth 1, using a comma. Note that
    // due to performance the "and" meaning of comma is not supported.
    $expected = [
        [
            'nid' => 4,
        ],
        [
            'nid' => 5,
        ],
    ];
    $this->assertTermWithDepthResult($expected, $this->terms[0]
        ->id() . ',' . $this->terms[1]
        ->id(), 1, TRUE);
}

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