Skip to content

Conversation

@rgadon107
Copy link
Owner

@rgadon107 rgadon107 commented May 19, 2020

PR Summary

This PR adds a unit and integration test for the function render_featured_image_id_field() in the extend-give-wp plugin. The callback is registered to WordPress from within the plugin function initialize_option_settings(). The function renders an HTML view file as part of the Featured Image ID settings field. It returns void.

The relative file path within the plugin to the function under test is:

extend-give-wp/src/admin/option-settings-admin.php.

============================================

@hellofromtonya

Issues - Unit

The test method runs 2 test scenarios.

Scenario 1: ‘featured-image-id’ => 0, and ‘expected_view’ => ‘’.
Scenario 2: ‘featured-image-id’ => 144, and ‘expected_view’ => <<<HMTL_VIEW.

The source code gets the option value, assigns it to a variable, and then conditionally checks that the variable is set. If no, then return 0.

I added a guardrail condition to the source code that if the variable is falsey ( 0 ), return early.

In the second test scenario, the actual HTML view file is falsey (returns empty string).

function render_featured_image_id_field() {
$options = get_option( 'extend-give-wp', [] );
$attachment_id = isset( $options['featured-image-id'] ) ? (int) $options['featured-image-id'] : 0;

Inside the unit test, I ran the following test assertion (which I did not commit).

// The parameter originates from the test method's dataProvider.
`$this->assertTrue( isset( $option['featured-image-id'] ) ); // passes.

This is a similar issue to PR#11.

Issues - Integration

Same as the unit test above.

rgadon107 added 4 commits May 18, 2020 15:46
- Add early return if $attachment_id is empty.
- Change control structure 'require_once' to 'require'. This allows multiple tests to run. 
- Uptick function number in docblock.
- Note: test assertion fails with 2nd data set ( 'non-empty data set' ). Function under test returns falsey (empty string) from output buffer. 
- The ternary statement evaluates to false, and $attachment_id is assigned 0. 
- The view file does not render.
- Add test method and dataProvider. 
- Note: Test assertion fails with second data set 'non-empty data set'. 
- The var $option['featured-image-id'] isset and $attachment_id is assigned a non-zero value. 
- Yet, $attachment_id evaluates to empty ( 0 ), and the actual view is not rendered.
@rgadon107 rgadon107 self-assigned this May 19, 2020
@rgadon107 rgadon107 added [WIP]code review Request CR for work in progress would like to discuss Requesting discussion on one or more items in PR labels May 19, 2020
@rgadon107 rgadon107 requested a review from hellofromtonya May 19, 2020 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[WIP]code review Request CR for work in progress would like to discuss Requesting discussion on one or more items in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants