mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
The `assertRegExp()` and `assertNotRegExp()` methods were hard deprecated in PHPUnit 9.1 and the functionality will be removed in PHPUnit 10.0. The `assertMatchesRegularExpression()` and `assertDoesNotMatchRegularExpression()` methods were introduced as a replacement in PHPUnit 9.1. These new PHPUnit methods are polyfilled by the PHPUnit Polyfills and switching to them will future-proof the tests some more. References: * https://github.com/sebastianbergmann/phpunit/blob/9.1.5/ChangeLog-9.1.md#910---2020-04-03 * https://github.com/sebastianbergmann/phpunit/issues/4085 * https://github.com/sebastianbergmann/phpunit/issues/4088 Follow-up to [51559-51564]. Props jrf. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51565 602fd350-edb4-49c9-b593-d223f7449a82
127 lines
4.0 KiB
PHP
127 lines
4.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group comment
|
|
*/
|
|
class Tests_Comment_CommentForm extends WP_UnitTestCase {
|
|
public function test_default_markup_for_submit_button_and_wrapper() {
|
|
$p = self::factory()->post->create();
|
|
|
|
$args = array(
|
|
'name_submit' => 'foo-name',
|
|
'id_submit' => 'foo-id',
|
|
'class_submit' => 'foo-class',
|
|
'label_submit' => 'foo-label',
|
|
);
|
|
|
|
$form = get_echo( 'comment_form', array( $args, $p ) );
|
|
|
|
$button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
|
|
$hidden = get_comment_id_fields( $p );
|
|
$this->assertMatchesRegularExpression( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
|
|
}
|
|
|
|
public function test_custom_submit_button() {
|
|
$p = self::factory()->post->create();
|
|
|
|
$args = array(
|
|
'name_submit' => 'foo-name',
|
|
'id_submit' => 'foo-id',
|
|
'class_submit' => 'foo-class',
|
|
'label_submit' => 'foo-label',
|
|
'submit_button' => '<input name="custom-%1$s" type="submit" id="custom-%2$s" class="custom-%3$s" value="custom-%4$s" />',
|
|
);
|
|
|
|
$form = get_echo( 'comment_form', array( $args, $p ) );
|
|
|
|
$button = '<input name="custom-foo-name" type="submit" id="custom-foo-id" class="custom-foo-class" value="custom-foo-label" />';
|
|
$this->assertStringContainsString( $button, $form );
|
|
}
|
|
|
|
public function test_custom_submit_field() {
|
|
$p = self::factory()->post->create();
|
|
|
|
$args = array(
|
|
'name_submit' => 'foo-name',
|
|
'id_submit' => 'foo-id',
|
|
'class_submit' => 'foo-class',
|
|
'label_submit' => 'foo-label',
|
|
'submit_field' => '<p class="my-custom-submit-field">%1$s %2$s</p>',
|
|
);
|
|
|
|
$form = get_echo( 'comment_form', array( $args, $p ) );
|
|
|
|
$button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
|
|
$hidden = get_comment_id_fields( $p );
|
|
$this->assertMatchesRegularExpression( '|<p class="my\-custom\-submit\-field">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
|
|
}
|
|
|
|
/**
|
|
* @ticket 32312
|
|
*/
|
|
public function test_submit_button_and_submit_field_should_fall_back_on_defaults_when_filtered_defaults_do_not_contain_the_keys() {
|
|
$p = self::factory()->post->create();
|
|
|
|
$args = array(
|
|
'name_submit' => 'foo-name',
|
|
'id_submit' => 'foo-id',
|
|
'class_submit' => 'foo-class',
|
|
'label_submit' => 'foo-label',
|
|
);
|
|
|
|
add_filter( 'comment_form_defaults', array( $this, 'filter_comment_form_defaults' ) );
|
|
$form = get_echo( 'comment_form', array( $args, $p ) );
|
|
remove_filter( 'comment_form_defaults', array( $this, 'filter_comment_form_defaults' ) );
|
|
|
|
$button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
|
|
$hidden = get_comment_id_fields( $p );
|
|
$this->assertMatchesRegularExpression( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
|
|
}
|
|
|
|
public function filter_comment_form_defaults( $defaults ) {
|
|
unset( $defaults['submit_field'] );
|
|
unset( $defaults['submit_button'] );
|
|
return $defaults;
|
|
}
|
|
|
|
/**
|
|
* @ticket 44126
|
|
*/
|
|
public function test_fields_should_include_cookies_consent() {
|
|
$p = self::factory()->post->create();
|
|
|
|
add_filter( 'option_show_comments_cookies_opt_in', '__return_true' );
|
|
|
|
$args = array(
|
|
'fields' => array(
|
|
'author' => 'Hello World!',
|
|
),
|
|
);
|
|
|
|
$form = get_echo( 'comment_form', array( $args, $p ) );
|
|
|
|
remove_filter( 'option_show_comments_cookies_opt_in', '__return_true' );
|
|
|
|
$this->assertMatchesRegularExpression( '|<p class="comment\-form\-cookies\-consent">.*?</p>|', $form );
|
|
}
|
|
|
|
/**
|
|
* @ticket 47975
|
|
*/
|
|
public function test_aria_describedby_email_notes_should_not_be_added_if_no_email_notes() {
|
|
$p = self::factory()->post->create();
|
|
|
|
$form_with_aria = get_echo( 'comment_form', array( array(), $p ) );
|
|
|
|
$this->assertStringContainsString( 'aria-describedby="email-notes"', $form_with_aria );
|
|
|
|
$args = array(
|
|
'comment_notes_before' => '',
|
|
);
|
|
|
|
$form_without_aria = get_echo( 'comment_form', array( $args, $p ) );
|
|
|
|
$this->assertStringNotContainsString( 'aria-describedby="email-notes"', $form_without_aria );
|
|
}
|
|
}
|