Comments

GoZ created an issue. See original summary.

GoZ’s picture

Status: Active » Needs review
FileSize
8.23 KB
dawehner’s picture

+++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
@@ -744,4 +745,52 @@ protected function getRawContent() {
+   * Checks to see whether a block appears on the page.
+   *
+   * @param \Drupal\block\Entity\Block $block
+   *   The block entity to find on the page.
+   *
+   * @deprecated Scheduled for removal in Drupal 9.0.0.
+   *   Use $this->xpath() instead and assert that the result is not empty.
+   */
+  protected function assertBlockAppears(Block $block) {
+    @trigger_error('AssertLegacyTrait::assertBlockAppears() is scheduled for removal in Drupal 9.0.0. Use $this->xpath() instead and assert that the result is not empty.', E_USER_DEPRECATED);
+    $result = $this->findBlockInstance($block);
+    $this->assertTrue(!empty($result), format_string('Ensure the block @id appears on the page', ['@id' => $block->id()]));
+  }
+
+  /**
+   * Checks to see whether a block does not appears on the page.
+   *
+   * @param \Drupal\block\Entity\Block $block
+   *   The block entity to find on the page.
+   *
+   * @deprecated Scheduled for removal in Drupal 9.0.0.
+   *   Use $this->xpath() instead and assert that the result is empty.
+   */
+  protected function assertNoBlockAppears(Block $block) {
+    @trigger_error('AssertLegacyTrait::assertNoBlockAppears() is scheduled for removal in Drupal 9.0.0. Use $this->xpath() instead and assert that the result is empty.', E_USER_DEPRECATED);
+    $result = $this->findBlockInstance($block);
+    $this->assertFalse(!empty($result), format_string('Ensure the block @id does not appear on the page', ['@id' => $block->id()]));
+  }
+
+  /**
+   * Find a block instance on the page.
+   *
+   * @param \Drupal\block\Entity\Block $block
+   *   The block entity to find on the page.
+   *
+   * @return array
+   *   The result from the xpath query.
+   *
+   * @deprecated Scheduled for removal in Drupal 9.0.0.
+   *   Use $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()])
+   *   instead.
+   */
+  protected function findBlockInstance(Block $block) {
+    @trigger_error('AssertLegacyTrait::findBlockInstance() is scheduled for removal in Drupal 9.0.0. Use $this->xpath(\'//div[@id = :id]\', [\':id\' => \'block-\' . $block->id()]) instead.', E_USER_DEPRECATED);
+    return $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]);
+  }
+
 }

This for me sounds like something we maybe should put into a trait. Any thoughts about that?

GoZ’s picture

May be i should move it into a new AssertBlockTrait. Are you ok with that or you thought about another place ?

dawehner’s picture

May be i should move it into a new AssertBlockTrait. Are you ok with that or you thought about another place ?

+1 from me, but please consult others. I personally believe the \Drupal\simpletest\BlockCreationTrait should be merged with those assertions, as you kinda need both for it to be userful.

jibran’s picture

+1 form me too.

GoZ’s picture

In any cases, this issue should not move BlockCreationTrait. We should create a new issue to do this.

So we can:
1/ Add assertions to BlockCreationTrait and then move it in a new issue to avoid conflict with other wtb to btb conversions issues.
2/ Add assertions to AssertBlockTrait and then merge BlockCreationTrait in AssertBlockTrait in a new issue.

any thoughts ?

jibran’s picture

Agreed.

dawehner’s picture

+++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
@@ -744,4 +745,52 @@ protected function getRawContent() {
+    @trigger_error('AssertLegacyTrait::assertBlockAppears() is scheduled for removal in Drupal 9.0.0. Use $this->xpath() instead and assert that the result is not empty.', E_USER_DEPRECATED);
...
+    @trigger_error('AssertLegacyTrait::assertNoBlockAppears() is scheduled for removal in Drupal 9.0.0. Use $this->xpath() instead and assert that the result is empty.', E_USER_DEPRECATED);
...
+    @trigger_error('AssertLegacyTrait::findBlockInstance() is scheduled for removal in Drupal 9.0.0. Use $this->xpath(\'//div[@id = :id]\', [\':id\' => \'block-\' . $block->id()]) instead.', E_USER_DEPRECATED);

Can we point to some change notice?

dawehner’s picture

Status: Needs review » Needs work
michielnugter’s picture

Status: Needs work » Postponed

These methods are added in this issue #2865336: Add \Drupal\simpletest\WebTestBase::assertBlockAppears to \Drupal\FunctionalTests\AssertLegacyTrait.

Shall we postpone on that one and add the methods there?

michielnugter’s picture

michielnugter’s picture

Issue tags: +phpunit initiative
naveenvalecha’s picture

Is there any way to proceed this? Shall we convert the test which requires #2865336: Add \Drupal\simpletest\WebTestBase::assertBlockAppears to \Drupal\FunctionalTests\AssertLegacyTrait in the followup? otherwise, we'll have to wait for long on long chains of blocking issues? Thoughts?

//Naveen

Lendude’s picture

@naveenvalecha it's only postponed on one issue, that just needs tests, so I think leaving it postponed on that and lets see if we can move #2865336: Add \Drupal\simpletest\WebTestBase::assertBlockAppears to \Drupal\FunctionalTests\AssertLegacyTrait forward, because I think more conversions are blocked on that