-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test to validate the bug is fixed
- Loading branch information
1 parent
ac74b38
commit eaff86b
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Tests for the Summary_Generator. | ||
* | ||
* @package Accessibility_Checker | ||
*/ | ||
|
||
use EDAC\Inc\Summary_Generator; | ||
|
||
/** | ||
* Testing that the summary generator outputs what is expected when invoked. | ||
*/ | ||
class SummaryGeneratorTest extends WP_UnitTestCase { | ||
/** | ||
* Validates that a bug was fixed where the summary density would cause | ||
* a fatal error when the density_data had a string instead of an array. | ||
* | ||
* @throws ReflectionException If the method does not exist this is thrown. | ||
*/ | ||
public function test_summary_density_wont_error_when_density_array_does_not_have_array_inside() { | ||
$post_id = self::factory()->post->create(); | ||
update_post_meta( $post_id, '_edac_density_data', '0,0' ); | ||
|
||
$simplified_summary = new Summary_Generator( $post_id ); | ||
|
||
// Reflection means that the method was hard to test in isolation and | ||
// likely warrants a refactor so that the method is more testable. | ||
$method = ( new ReflectionClass( get_class( $simplified_summary ) ) ) | ||
->getMethod( 'update_issue_density' ); | ||
$method->setAccessible( true ); | ||
|
||
$method->invoke( $simplified_summary, array() ); | ||
|
||
// We are really testing here that the method does not throw an error, | ||
// but we may as well check that the meta didn't change as well since | ||
// we are here and by this point already know the method did not fatal. | ||
$this->assertEquals( | ||
'0,0', | ||
get_post_meta( $post_id, '_edac_density_data', true ) | ||
); | ||
} | ||
} |