Skip to content
Snippets Groups Projects
Verified Commit 4616376f authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2031223 by acbramley, Spokje, Berdir, ravi.shankar, smustgrave,...

Issue #2031223 by acbramley, Spokje, Berdir, ravi.shankar, smustgrave, larowlan, mondrake, a_c_m: Add linkByHrefExistsExact and linkByHrefNotExistsExact for matching links by href exactly

(cherry picked from commit 78a3d4a1)
parent 532841c6
Branches
Tags
14 merge requests!11628Update file MediaLibraryWidget.php,!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!5427Issue #3338518: send credentials in ajax if configured in CORS settings.,!5395Issue #3387916 by fjgarlin, Spokje: Each GitLab job exposes user email,!5217Issue #3386607 by alexpott: Improve spell checking in commit-code-check.sh,!5064Issue #3379522 by finnsky, Gauravvvv, kostyashupenko, smustgrave, Chi: Revert...,!5040SDC ComponentElement: Transform slots scalar values to #plain_text instead of throwing an exception,!4958Issue #3392147: Whitelist IP for a Ban module.,!4894Issue #3280279: Add API to allow sites to opt in to upload SVG images in CKEditor 5,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->),!925Issue #2339235: Remove taxonomy hard dependency on node module,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links
Pipeline #26044 passed
Pipeline: drupal

#26049

    Pipeline: drupal

    #26048

      Pipeline: drupal

      #26047

        +1
        ......@@ -75,14 +75,8 @@ public function testVersionHistoryTranslations(): void {
        $this->assertSession()->linkByHrefNotExists($firstRevision->getTranslation('es')->toUrl('revision-delete-form')->toString());
        $this->drupalGet($entity->getTranslation('es')->toUrl('version-history'));
        // We can't use linkByHrefNotExists here because it does a "contains" match
        // and the translated URLs contain the non translated ones.
        // i.e /es/entity_test_mul_revlog/1/revision/1/revert contains
        // /entity_test_mul_revlog/1/revision/1/revert.
        $xpath = $this->assertSession()->buildXPathQuery('//a[@href=:href]', [':href' => $firstRevision->toUrl('revision-revert-form')->toString()]);
        $this->assertEmpty($this->getSession()->getPage()->findAll('xpath', $xpath));
        $xpath = $this->assertSession()->buildXPathQuery('//a[@href=:href]', [':href' => $firstRevision->toUrl('revision-delete-form')->toString()]);
        $this->assertEmpty($this->getSession()->getPage()->findAll('xpath', $xpath));
        $this->assertSession()->linkByHrefNotExistsExact($firstRevision->toUrl('revision-revert-form')->toString());
        $this->assertSession()->linkByHrefNotExistsExact($firstRevision->toUrl('revision-delete-form')->toString());
        $this->assertSession()->linkByHrefExists($firstRevision->getTranslation('es')->toUrl('revision-revert-form')->toString());
        $this->assertSession()->linkByHrefExists($firstRevision->getTranslation('es')->toUrl('revision-delete-form')->toString());
        }
        ......
        ......@@ -188,6 +188,104 @@ public function testInvalidLinkNotExistsExact() {
        $this->assertSession()->linkNotExistsExact('foo|bar|baz');
        }
        /**
        * Tests linkExistsByHref() functionality.
        *
        * @covers ::linkByHrefExists
        */
        public function testLinkByHrefExists(): void {
        $this->drupalGet('test-page');
        // Partial matching.
        $this->assertSession()->linkByHrefExists('/user');
        // Full matching.
        $this->assertSession()->linkByHrefExists('/user/login');
        }
        /**
        * Tests linkExistsByHref() functionality fail.
        *
        * @covers ::linkByHrefExists
        */
        public function testInvalidLinkByHrefExists(): void {
        $this->drupalGet('test-page');
        $this->expectException(ExpectationException::class);
        $this->assertSession()->linkByHrefExists('/foo');
        }
        /**
        * Tests linkByHrefNotExists() functionality.
        *
        * @covers ::linkByHrefNotExists
        */
        public function testLinkByHrefNotExists(): void {
        $this->drupalGet('test-page');
        $this->assertSession()->linkByHrefNotExists('/foo');
        }
        /**
        * Tests LinkByHrefNotExists() functionality fail partial match.
        *
        * @covers ::linkByHrefNotExists
        */
        public function testInvalidLinkByHrefNotExistsPartial(): void {
        $this->drupalGet('test-page');
        $this->expectException(ExpectationException::class);
        $this->assertSession()->linkByHrefNotExists('/user');
        }
        /**
        * Tests LinkByHrefNotExists() functionality fail full match.
        *
        * @covers ::linkByHrefNotExists
        */
        public function testInvalidLinkByHrefNotExistsFull(): void {
        $this->drupalGet('test-page');
        $this->expectException(ExpectationException::class);
        $this->assertSession()->linkByHrefNotExists('/user/login');
        }
        /**
        * Tests linkExistsByHref() functionality.
        *
        * @covers ::linkByHrefExistsExact
        */
        public function testLinkByHrefExistsExact(): void {
        $this->drupalGet('test-page');
        $this->assertSession()->linkByHrefExistsExact('/user/login');
        }
        /**
        * Tests linkByHrefExistsExact() functionality fail.
        *
        * @covers ::linkByHrefExistsExact
        */
        public function testInvalidLinkByHrefExistsExact(): void {
        $this->drupalGet('test-page');
        $this->expectException(ExpectationException::class);
        $this->assertSession()->linkByHrefExistsExact('/foo');
        }
        /**
        * Tests linkByHrefNotExistsExact() functionality.
        *
        * @covers ::linkByHrefNotExistsExact
        */
        public function testLinkByHrefNotExistsExact(): void {
        $this->drupalGet('test-page');
        $this->assertSession()->linkByHrefNotExistsExact('/foo');
        }
        /**
        * Tests linkByHrefNotExistsExact() functionality fail.
        *
        * @covers ::linkByHrefNotExistsExact
        */
        public function testInvalidLinkByHrefNotExistsExact(): void {
        $this->drupalGet('test-page');
        $this->expectException(ExpectationException::class);
        $this->assertSession()->linkByHrefNotExistsExact('/user/login');
        }
        /**
        * Tests legacy text asserts.
        *
        ......
        ......@@ -387,6 +387,29 @@ public function linkByHrefExists($href, $index = 0, $message = '') {
        $this->assert(!empty($links[$index]), $message);
        }
        /**
        * Passes if a link with a given href is found.
        *
        * @param string $href
        * The full value of the 'href' attribute of the anchor tag.
        * @param int $index
        * Link position counting from zero.
        * @param string $message
        * (optional) A message to display with the assertion. Do not translate
        * messages: use \Drupal\Component\Render\FormattableMarkup to embed
        * variables in the message text, not t(). If left blank, a default message
        * will be displayed.
        *
        * @throws \Behat\Mink\Exception\ExpectationException
        * Thrown when element doesn't exist, or the link label is a different one.
        */
        public function linkByHrefExistsExact(string $href, int $index = 0, string $message = ''): void {
        $xpath = $this->buildXPathQuery('//a[@href=:href]', [':href' => $href]);
        $message = ($message ?: strtr('No link with href %href found.', ['%href' => $href]));
        $links = $this->session->getPage()->findAll('xpath', $xpath);
        $this->assert(!empty($links[$index]), $message);
        }
        /**
        * Passes if a link containing a given href (part) is not found.
        *
        ......@@ -408,6 +431,27 @@ public function linkByHrefNotExists($href, $message = '') {
        $this->assert(empty($links), $message);
        }
        /**
        * Passes if a link with a given href is not found.
        *
        * @param string $href
        * The full value of the 'href' attribute of the anchor tag.
        * @param string $message
        * (optional) A message to display with the assertion. Do not translate
        * messages: use \Drupal\Component\Render\FormattableMarkup to embed
        * variables in the message text, not t(). If left blank, a default message
        * will be displayed.
        *
        * @throws \Behat\Mink\Exception\ExpectationException
        * Thrown when element doesn't exist, or the link label is a different one.
        */
        public function linkByHrefNotExistsExact(string $href, string $message = ''): void {
        $xpath = $this->buildXPathQuery('//a[@href=:href]', [':href' => $href]);
        $message = ($message ?: strtr('Link with href %href found.', ['%href' => $href]));
        $links = $this->session->getPage()->findAll('xpath', $xpath);
        $this->assert(empty($links), $message);
        }
        /**
        * Builds an XPath query.
        *
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment