<?php
 
/**
   * 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.

Files: 
CommentFileSizeAuthor
#15 1943282-d7.patch1005 bytesRobLoach
PASSED: [[SimpleTest]]: [MySQL] 40,303 pass(es).
[ View ]
#10 1943282.patch1.46 KBRobLoach
PASSED: [[SimpleTest]]: [MySQL] 53,898 pass(es).
[ View ]
#6 1943282-d7-do-not-test.patch1005 bytesRobLoach
#3 autoincrement-agnostic-simpletest-1943282-3.patch1.12 KBeporama
PASSED: [[SimpleTest]]: [MySQL] 53,384 pass(es).
[ View ]

Comments

Issue tags:+needs backport to D7

Status:Active» Needs review
StatusFileSize
new1.12 KB
PASSED: [[SimpleTest]]: [MySQL] 53,384 pass(es).
[ View ]

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:

<?php
   $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.

Status:Needs work» Needs review
Issue tags:+needs backport to D7

Status:Needs review» Reviewed & tested by the community
StatusFileSize
new1005 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.

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

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.

Status:Needs work» Needs review
StatusFileSize
new1.46 KB
PASSED: [[SimpleTest]]: [MySQL] 53,898 pass(es).
[ View ]

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.

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 :)

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

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

Status:Active» Patch (to be ported)

(fixed status)

Status:Patch (to be ported)» Needs review
StatusFileSize
new1005 bytes
PASSED: [[SimpleTest]]: [MySQL] 40,303 pass(es).
[ View ]

From #6.

Status:Needs review» Reviewed & tested by the community

Works for me.

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.