Hello, just rolled an information architecture link patch and noticed there were a number of broken "documentation" links in HEAD. I'm working with Boombatower on a test that will confirm that at all core links do in fact exist.

I will post my patch, whether it works or not, to keep the ball rolling. Though, according to Dries, tests are always welcome :)

Josh

Comments

joshmiller’s picture

Status: Active » Postponed

Boombatower was able to write a simple test that regexed all the urls from the code and checked it against the database table called something like menu_router -- we turned up some interesting links, but nothing profoundly wrong.

In the end, we were unable to find a decent way to test the links that wasn't physically limiting.

Marking postponed until further work can be done.

joshmiller’s picture

Title: Test for existance of all admin/foo links » Need test to confirm there are no dead links in code

Clarified title.

David_Rothstein’s picture

Status: Postponed » Active

This sounds pretty useful - is there any code that can be posted here as inspiration?

Regex-ing the codebase and comparing it to the menu router paths is a pretty neat idea, but I was thinking that a simpler way to search for broken links might be to enable all modules and then "spider" the site, just like a search engine would.

This would not be as comprehensive (since there are certain links you won't see on a fresh site until after you have done things - e.g., create content), but it might be good enough for starters. Having some kind of broken link detector in the tests definitely seems like a good idea.

David_Rothstein’s picture

If spidering the site, one might also want to visit each page as two separate users:

  1. A user like user/1 who has permission to do anything (to make sure every link that can possibly be output on the page actually gets checked)
  2. A user who has the minimum permissions necessary to view the page in question (to make sure that there are no links that are displayed without proper permission checking and therefore give "access denied" when such a user clicks on them - a lot of the core implementation of hook_help() are guilty of this, I think)
joshmiller’s picture

What if it was more blatant... link a verify function and we require or insist that every link be checked by that function...


function assert_link_exists($url,$optional_permission=null,$check_anonymous=true) {
  // check for user 1

  // check for someone with permission

  // check for anonymous
}

The first set of tests would be daunting (we would have to build a test for every potential link), but we could include all links that we know should be there, and insist that all new code that invokes a new menu path be declared as working for each role.

This sounds more doable than a spider technology.

Josh

sun’s picture

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.