Skip to content

Commit

Permalink
Merge pull request #1792 from WordImpress/mehul0810-issue/1423
Browse files Browse the repository at this point in the history
issue/1423 - With Code Updates from Devin Walker
  • Loading branch information
Devin Walker committed Jun 26, 2017
2 parents 6a270ad + 64ea346 commit da99265
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
10 changes: 10 additions & 0 deletions includes/api/class-give-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,16 @@ private function get_form_data( $form_info ) {
$form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' );
}

// Check whether any goal is to be achieved for the donation form.
$goal_option = give_get_meta( $form_info->ID, '_give_goal_option', true );
$goal_amount = give_get_meta( $form_info->ID, '_give_set_goal', true );
if ( give_is_setting_enabled( $goal_option ) && $goal_amount ) {
$total_income = give_get_form_earnings_stats( $form_info->ID );
$goal_percentage_completed = ( $total_income < $goal_amount ) ? round( ( $total_income / $goal_amount ) * 100, 2 ) : 100;
$form['goal']['amount'] = isset( $goal_amount ) ? $goal_amount : '';
$form['goal']['percentage_completed'] = isset( $goal_percentage_completed ) ? $goal_percentage_completed : '';
}

if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) {
$form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID );
$form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID );
Expand Down
31 changes: 22 additions & 9 deletions tests/unit-tests/tests-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public function setUp() {
'post_status' => 'publish',
) );


$_multi_level_donations = array(
array(
'_give_id' => array(
Expand Down Expand Up @@ -114,6 +113,8 @@ public function setUp() {
'_give_donation_levels' => array_values( $_multi_level_donations ),
'_give_form_earnings' => 120,
'_give_form_sales' => 59,
'_give_goal_option' => 'enabled',
'_give_set_goal' => 2000,
);
foreach ( $meta as $key => $value ) {
give_update_meta( $post_id, $key, $value );
Expand All @@ -135,7 +136,7 @@ public function setUp() {

give_update_meta( $post_id, '_give_form_content', 'Post content 1' );

// Add a payment
// Add a payment.
$donation_data = array(
'price' => number_format( (float) $total, 2 ),
'give_form_title' => get_the_title( $post_id ),
Expand Down Expand Up @@ -245,9 +246,8 @@ public function test_get_default_version() {

$this->assertEquals( 'v1', $this->_api->get_default_version() );

// define( 'GIVE_API_VERSION', 'v2' );
// $this->assertEquals( 'v2', $this->_api->get_default_version() );

// define( 'GIVE_API_VERSION', 'v2' );
// $this->assertEquals( 'v2', $this->_api->get_default_version() );
}

/**
Expand All @@ -269,9 +269,8 @@ public function test_get_queried_version() {
$this->assertEquals( 'v1', $this->_api->get_queried_version() );

// There's no v2 of the API currently.
// $this->_api->process_query();
// $this->assertEquals( 'v2', $this->_api->get_queried_version() );

// $this->_api->process_query();
// $this->assertEquals( 'v2', $this->_api->get_queried_version() );
}

/**
Expand Down Expand Up @@ -317,6 +316,21 @@ public function test_get_form_stats() {
$this->assertEquals( '140', $out['forms'][0]['stats']['monthly_average']['earnings'] );
}

/**
* Test Get Form Goal
*/
public function test_get_form_goal() {
$out = $this->_api_output;

$this->assertArrayHasKey( 'goal', $out['forms'][0] );
$this->assertArrayHasKey( 'amount', $out['forms'][0]['goal'] );
$this->assertArrayHasKey( 'percentage_completed', $out['forms'][0]['goal'] );

$this->assertEquals( '2000', $out['forms'][0]['goal']['amount'] );
$this->assertEquals( '7.0', $out['forms'][0]['goal']['percentage_completed'] );

}

/**
* Test Get Forms Pricing
*/
Expand Down Expand Up @@ -470,7 +484,6 @@ public function test_invalid_key() {
$this->assertArrayHasKey( 'error', $out );
$this->assertEquals( 'Invalid API key.', $out['error'] );


}

/**
Expand Down

0 comments on commit da99265

Please sign in to comment.