Problem/Motivation
Discovered whilst working on #2980750: [random test failure] Random failure in CommentStatisticsTest:
There are quite a few tests in the comment module that call \Drupal\Tests\comment\Functional\CommentTestBase::setCommentAnonymous passing integers as the argument.
Let's use the already defined CONSTANTs in \Drupal\comment\CommentInterface:
/**
* Anonymous posters cannot enter their contact information.
*/
const ANONYMOUS_MAYNOT_CONTACT = 0;
/**
* Anonymous posters may leave their contact information.
*/
const ANONYMOUS_MAY_CONTACT = 1;
/**
* Anonymous posters are required to leave their contact information.
*/
const ANONYMOUS_MUST_CONTACT = 2;
Steps to reproduce
Do a search/grep on $this->setCommentAnonymous( and see (quite) a being called with integers as argument.
NOTE: There's one occurence of $this->setCommentAnonymous(TRUE); in \Drupal\Tests\comment\Functional\CommentLinksTest::testCommentLinks, which would "translate" to $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAY_CONTACT);.
As it turns out this isn't needed in that test that line is removed in this issue.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3368145
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3368145-use-constants-when
changes, plain diff MR !4217
Comments
Comment #3
spokjeComment #4
smustgrave commentedSeems like a simple change that didn't break anything.
Comment #7
longwaveBackported to 10.1.x as a tests-only fix.
Committed and pushed b9d2e85583 to 11.x and 83da1db419 to 10.1.x. Thanks!