Tests: Add unit tests for `_cleanup_header_comment()`.

Props pbearne.
Fixes #38101. See #8497.


git-svn-id: https://develop.svn.wordpress.org/trunk@47779 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson 2020-05-10 05:21:48 +00:00
parent 8e3b8c73d5
commit c860753778
1 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,121 @@
<?php
/*
* Test _cleanup_header_comment().
*
* @group functions.php
* @ticket 8497
* @ticket 38101
*/
class Tests_Cleanup_Header_Comment extends WP_UnitTestCase {
/**
* Test cleanup header of header comment.
*
* @covers _cleanup_header_comment
* @dataProvider data_cleanup_header_comment
*
* @param string $test_string
* @param string $expected
*/
public function test_cleanup_header_comment( $test_string, $expected ) {
$this->assertEquals( $expected, _cleanup_header_comment( $test_string ) );
}
/**
* Data provider for test_cleanup_header_comment.
*
* @return array[] Test parameters {
* @type string $test_string Test string.
* @type string $expected Expected return value.
* }
*/
public function data_cleanup_header_comment() {
return array(
// Set 0: A string.
array(
'ffffffffffffff',
'ffffffffffffff',
),
// Set 1: Trim a string.
array(
' ffffffffffffff ',
'ffffffffffffff',
),
// Set 2: Trim a full comment string.
array(
'<?php
/*
Plugin Name: Health Check
Plugin URI: https://wordpress.org/plugins/health-check/
Description: Checks the health of your WordPress install
Version: 0.1.0
Author: The Health Check Team
Author URI: http://health-check-team.example.com
Text Domain: health-check
Domain Path: /languages
*/
',
'<?php
/*
Plugin Name: Health Check
Plugin URI: https://wordpress.org/plugins/health-check/
Description: Checks the health of your WordPress install
Version: 0.1.0
Author: The Health Check Team
Author URI: http://health-check-team.example.com
Text Domain: health-check
Domain Path: /languages',
),
// Set 3: Trim HTML following comment.
array(
'<?php
/*
Plugin Name: Health Check
Plugin URI: https://wordpress.org/plugins/health-check/
Description: Checks the health of your WordPress install
Version: 0.1.0
Author: The Health Check Team
Author URI: http://health-check-team.example.com
Text Domain: health-check
Domain Path: /languages
*/ ?>
dddlddfs
',
'<?php
/*
Plugin Name: Health Check
Plugin URI: https://wordpress.org/plugins/health-check/
Description: Checks the health of your WordPress install
Version: 0.1.0
Author: The Health Check Team
Author URI: http://health-check-team.example.com
Text Domain: health-check
Domain Path: /languages
dddlddfs',
),
// Set 4: Trim a docblock style comment.
array(
'<?php
/**
* Plugin Name: Health Check
* Plugin URI: https://wordpress.org/plugins/health-check/
* Description: Checks the health of your WordPress install
* Version: 0.1.0
* Author: The Health Check Team
* Author URI: http://health-check-team.example.com
* Text Domain: health-check
* Domain Path: /languages
*/',
'<?php
/**
* Plugin Name: Health Check
* Plugin URI: https://wordpress.org/plugins/health-check/
* Description: Checks the health of your WordPress install
* Version: 0.1.0
* Author: The Health Check Team
* Author URI: http://health-check-team.example.com
* Text Domain: health-check
* Domain Path: /languages',
),
);
}
}