/**
* 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.
Comments
Comment #1
robloachhttps://www.acquia.com/blog/module-authors-sql-dont-assume-increment1-2
Comment #2
robloachComment #3
eporama commentedSo, 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:
instead of just assuming the field is
edit-links-mlid2-hidden.Comment #5
robloach#3: autoincrement-agnostic-simpletest-1943282-3.patch queued for re-testing.
Comment #6
robloachErik 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.
Comment #7
xjm#3: autoincrement-agnostic-simpletest-1943282-3.patch queued for re-testing.
Comment #8
moshe weitzman commentedIf someone rerolls, I suggest adding a comment about supporting auto-increment != 1
Comment #9
alexpottThe isn't really the label.. perhaps $field_id would be better?
So let's also add a comment as @moshe suggests... something like:
Comment #10
robloachMaybe
$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.Comment #11
alexpottYeah... 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 :)
Comment #12
robloachPut together a meta issue to track the other failing tests: #1962572: [META] Tests fail when auto-increment is not 1
Comment #13
alexpottCommitted f3af391 and pushed to 8.x. Thanks!
Set back to active for backport to 7.x
Comment #14
xjm(fixed status)
Comment #15
robloachFrom #6.
Comment #16
pdrake commentedWorks for me.
Comment #17
David_Rothstein commentedCommitted 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 :)