Issue #3469824 by catch, smustgrave: CommentTestBase/CommentTestTrait methods should be protected

merge-requests/6570/merge
nod_ 2024-08-27 11:10:44 +02:00
parent 6d66158e05
commit 5d98794158
No known key found for this signature in database
GPG Key ID: 76624892606FA197
2 changed files with 13 additions and 13 deletions

View File

@ -33,7 +33,7 @@ trait CommentTestTrait {
* (optional) The comment view mode to be used in comment field formatter. * (optional) The comment view mode to be used in comment field formatter.
* Defaults to 'full'. * Defaults to 'full'.
*/ */
public function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment', $comment_view_mode = 'full') { protected function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment', $comment_view_mode = 'full') {
$entity_type_manager = \Drupal::entityTypeManager(); $entity_type_manager = \Drupal::entityTypeManager();
$entity_display_repository = \Drupal::service('entity_display.repository'); $entity_display_repository = \Drupal::service('entity_display.repository');
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */ /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */

View File

@ -120,7 +120,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @return \Drupal\comment\CommentInterface|null * @return \Drupal\comment\CommentInterface|null
* The posted comment or NULL when posted comment was not found. * The posted comment or NULL when posted comment was not found.
*/ */
public function postComment($entity, $comment, $subject = '', $contact = NULL, $field_name = 'comment') { protected function postComment($entity, $comment, $subject = '', $contact = NULL, $field_name = 'comment') {
$edit = []; $edit = [];
$edit['comment_body[0][value]'] = $comment; $edit['comment_body[0][value]'] = $comment;
@ -201,7 +201,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @return bool * @return bool
* Boolean indicating whether the comment was found. * Boolean indicating whether the comment was found.
*/ */
public function commentExists(?CommentInterface $comment = NULL, $reply = FALSE) { protected function commentExists(?CommentInterface $comment = NULL, $reply = FALSE) {
if ($comment) { if ($comment) {
$comment_element = $this->cssSelect(($reply ? '.indented ' : '') . 'article#comment-' . $comment->id()); $comment_element = $this->cssSelect(($reply ? '.indented ' : '') . 'article#comment-' . $comment->id());
if (empty($comment_element)) { if (empty($comment_element)) {
@ -231,7 +231,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @param \Drupal\comment\CommentInterface $comment * @param \Drupal\comment\CommentInterface $comment
* Comment to delete. * Comment to delete.
*/ */
public function deleteComment(CommentInterface $comment) { protected function deleteComment(CommentInterface $comment) {
$this->drupalGet('comment/' . $comment->id() . '/delete'); $this->drupalGet('comment/' . $comment->id() . '/delete');
$this->submitForm([], 'Delete'); $this->submitForm([], 'Delete');
$this->assertSession()->pageTextContains('The comment and all its replies have been deleted.'); $this->assertSession()->pageTextContains('The comment and all its replies have been deleted.');
@ -243,7 +243,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @param bool $enabled * @param bool $enabled
* Boolean specifying whether the subject field should be enabled. * Boolean specifying whether the subject field should be enabled.
*/ */
public function setCommentSubject($enabled) { protected function setCommentSubject($enabled) {
$form_display = $this->container->get('entity_display.repository') $form_display = $this->container->get('entity_display.repository')
->getFormDisplay('comment', 'comment'); ->getFormDisplay('comment', 'comment');
@ -267,7 +267,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* (optional) Field name through which the comment should be posted. * (optional) Field name through which the comment should be posted.
* Defaults to 'comment'. * Defaults to 'comment'.
*/ */
public function setCommentPreview($mode, $field_name = 'comment') { protected function setCommentPreview($mode, $field_name = 'comment') {
switch ($mode) { switch ($mode) {
case DRUPAL_DISABLED: case DRUPAL_DISABLED:
$mode_text = 'disabled'; $mode_text = 'disabled';
@ -294,7 +294,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* (optional) Field name through which the comment should be posted. * (optional) Field name through which the comment should be posted.
* Defaults to 'comment'. * Defaults to 'comment'.
*/ */
public function setCommentForm($enabled, $field_name = 'comment') { protected function setCommentForm($enabled, $field_name = 'comment') {
$this->setCommentSettings('form_location', ($enabled ? CommentItemInterface::FORM_BELOW : CommentItemInterface::FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.', $field_name); $this->setCommentSettings('form_location', ($enabled ? CommentItemInterface::FORM_BELOW : CommentItemInterface::FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.', $field_name);
} }
@ -307,7 +307,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* - 1: Contact information allowed but not required. * - 1: Contact information allowed but not required.
* - 2: Contact information required. * - 2: Contact information required.
*/ */
public function setCommentAnonymous($level) { protected function setCommentAnonymous($level) {
$this->setCommentSettings('anonymous', $level, new FormattableMarkup('Anonymous commenting set to level @level.', ['@level' => $level])); $this->setCommentSettings('anonymous', $level, new FormattableMarkup('Anonymous commenting set to level @level.', ['@level' => $level]));
} }
@ -320,7 +320,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* (optional) Field name through which the comment should be posted. * (optional) Field name through which the comment should be posted.
* Defaults to 'comment'. * Defaults to 'comment'.
*/ */
public function setCommentsPerPage($number, $field_name = 'comment') { protected function setCommentsPerPage($number, $field_name = 'comment') {
$this->setCommentSettings('per_page', $number, new FormattableMarkup('Number of comments per page set to @number.', ['@number' => $number]), $field_name); $this->setCommentSettings('per_page', $number, new FormattableMarkup('Number of comments per page set to @number.', ['@number' => $number]), $field_name);
} }
@ -337,7 +337,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* (optional) Field name through which the comment should be posted. * (optional) Field name through which the comment should be posted.
* Defaults to 'comment'. * Defaults to 'comment'.
*/ */
public function setCommentSettings($name, $value, $message, $field_name = 'comment') { protected function setCommentSettings($name, $value, $message, $field_name = 'comment') {
$field = FieldConfig::loadByName('node', 'article', $field_name); $field = FieldConfig::loadByName('node', 'article', $field_name);
$field->setSetting($name, $value); $field->setSetting($name, $value);
$field->save(); $field->save();
@ -349,7 +349,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @return bool * @return bool
* Contact info is available. * Contact info is available.
*/ */
public function commentContactInfoAvailable() { protected function commentContactInfoAvailable() {
return (bool) preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getSession()->getPage()->getContent()); return (bool) preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getSession()->getPage()->getContent());
} }
@ -363,7 +363,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @param bool $approval * @param bool $approval
* Operation is found on approval page. * Operation is found on approval page.
*/ */
public function performCommentOperation(CommentInterface $comment, $operation, $approval = FALSE) { protected function performCommentOperation(CommentInterface $comment, $operation, $approval = FALSE) {
$edit = []; $edit = [];
$edit['operation'] = $operation; $edit['operation'] = $operation;
$edit['comments[' . $comment->id() . ']'] = TRUE; $edit['comments[' . $comment->id() . ']'] = TRUE;
@ -388,7 +388,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @return int * @return int
* Comment id. * Comment id.
*/ */
public function getUnapprovedComment($subject) { protected function getUnapprovedComment($subject) {
$this->drupalGet('admin/content/comment/approval'); $this->drupalGet('admin/content/comment/approval');
preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->getSession()->getPage()->getContent(), $match); preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->getSession()->getPage()->getContent(), $match);