/**
   * Tests disabling the 'My account' link.
   */
  function testDisabledAccountLink() {
    // Create an admin user and log in.
    $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu')));

    // Verify that the 'My account' link is enabled.
    $this->drupalGet('admin/structure/menu/manage/account');
    $this->assertFieldChecked('edit-links-mlid2-hidden', "The 'My account' link is enabled by default.");

    // Disable the 'My account' link.
    $edit = array(
      'links[mlid:2][hidden]' => FALSE,
    );
    $this->drupalPost('admin/structure/menu/manage/account', $edit, t('Save'));

    // Get the homepage.
    $this->drupalGet('<front>');

    // Verify that the 'My account' link does not appear when disabled.
    $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
      ':menu_id' => 'secondary-menu',
      ':href' => 'user',
      ':text' => 'My account',
    ));
    $this->assertEqual(count($link), 0, 'My account link is not in the secondary menu.');
  }

It assumes the ID is 2, when it sometimes can be something else in certain environments.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RobLoach’s picture

RobLoach’s picture

Issue tags: +Needs backport to D7
eporama’s picture

Status: Active » Needs review
FileSize
1.12 KB

So, to me, the tricky part is getting the field ID of a field that might have different IDs. But since it is always a consistent <label> element. We should be able to grab that and use the "for" attribute to get the actual <input> element.

So this works on an xpath query:

   $label = $this->xpath('//label[contains(.,:text)]/@for', array(':text' => 'Enable My account menu link'));
   $this->assertFieldChecked((string) $label[0], "The 'My account' link is enabled by default.");

instead of just assuming the field is edit-links-mlid2-hidden.

Status: Needs review » Needs work
Issue tags: -Needs backport to D7

The last submitted patch, autoincrement-agnostic-simpletest-1943282-3.patch, failed testing.

RobLoach’s picture

Status: Needs work » Needs review
Issue tags: +Needs backport to D7
RobLoach’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1005 bytes

Erik with the XPath mastery. Well done, Erik. Thanks for posting that... I'll post issues for the other failing SimpleTests with auto-increment issues and have a look at putting together patches for them.

Thanks again! Attached is the patch for Drupal 7.

xjm’s picture

moshe weitzman’s picture

If someone rerolls, I suggest adding a comment about supporting auto-increment != 1

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.phpundefined
@@ -74,11 +74,13 @@ function testDisabledAccountLink() {
+    $label = $this->xpath('//label[contains(.,:text)]/@for', array(':text' => 'Enable My account menu link'));

The isn't really the label.. perhaps $field_id would be better?

So let's also add a comment as @moshe suggests... something like:

    // Do not assume auto-increment is 1. Use XPath to obtain input element id 
    // and name using the consistent label text.
RobLoach’s picture

Status: Needs work » Needs review
FileSize
1.46 KB

The isn't really the label.. perhaps $field_id would be better?

Maybe $element_ids? It's not really the $field_id either. It's retrieving an array of IDs who's "label" attributes match the given text.

alexpott’s picture

Yeah... no need for a bikeshed :) ... let's leave as is... the important thing is that now the comment is there other people can learn from it :)

So if @robloach (or anyone else) rtbc's this I'm happy to commit :)

RobLoach’s picture

Status: Needs review » Reviewed & tested by the community

Put together a meta issue to track the other failing tests: #1962572: [META] Tests fail when auto-increment is not 1

alexpott’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Active

Committed f3af391 and pushed to 8.x. Thanks!

Set back to active for backport to 7.x

xjm’s picture

Status: Active » Patch (to be ported)

(fixed status)

RobLoach’s picture

Status: Patch (to be ported) » Needs review
FileSize
1005 bytes

From #6.

pdrake’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/ed0d823

I guess we can live without the expanded code comment from the Drupal 8 patch in Drupal 7 :)

Automatically closed -- issue fixed for 2 weeks with no activity.