/**
  * 	test_set_tax
  */
 function test_set_tax()
 {
     //first create a line item
     $txn = $this->new_typical_transaction();
     $line_item = $txn->total_line_item();
     $old_tax_subtotal = EEH_Line_Item::get_nearest_descendant_of_type($line_item, EEM_Line_Item::type_tax_sub_total);
     $this->assertInstanceOf('EE_Line_Item', $old_tax_subtotal);
     $old_tax = EEH_Line_Item::get_nearest_descendant_of_type($old_tax_subtotal, EEM_Line_Item::type_tax);
     $new_tax = EEH_Line_Item::set_total_tax_to($line_item, 1.5, 'Monkey Tax', 'Only monkey must pay');
     $this->assertEquals(1.5, $new_tax->total());
     $this->assertEquals($new_tax->total(), $old_tax_subtotal->total());
     $child_of_tax_subtotal = EEH_Line_Item::get_nearest_descendant_of_type($old_tax_subtotal, EEM_Line_Item::type_tax);
     $this->assertEquals($new_tax, $child_of_tax_subtotal);
     $tax_total_before_recalculation = $old_tax_subtotal->total();
     $tax_before_recalculations = $new_tax->total();
     $line_item->recalculate_taxes_and_tax_total();
     $this->assertEquals($tax_before_recalculations, $new_tax->total());
     $this->assertEquals($tax_total_before_recalculation, $old_tax_subtotal->total());
 }
 /**
  * @group current
  */
 public function test_set_redirection_info__with_paypal_taxes_and_shipping()
 {
     //make sure paypal gateway is included
     $ppm = $this->new_model_obj_with_dependencies('Payment_Method', array('PMD_type' => 'Paypal_Standard'));
     $ppg = $ppm->type_obj()->get_gateway();
     $ppg->set_settings(array('paypal_id' => $this->_paypal_id, 'paypal_taxes' => TRUE, 'paypal_shipping' => TRUE));
     $t = $this->new_typical_transaction(array('ticket_types' => 2, 'taxable_tickets' => 1));
     $original_txn_total = $t->total();
     //pretend we previous used paypal to make a payment.
     EEH_Line_Item::add_unrelated_item($t->total_line_item(), 'Shipping', 8, 'some shipping', 1, false, 'paypal_shipping_' . $t->ID());
     EEH_Line_Item::set_total_tax_to($t->total_line_item(), 4, 'paypal taxes', 'paypal did thi', 'paypal_tax', false);
     $t->total_line_item()->save_this_and_descendants_to_txn($t->ID());
     $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
     $registration_processor->update_registration_final_prices($t);
     $p = $this->new_model_obj_with_dependencies('Payment', array('TXN_ID' => $t->ID(), 'PMD_ID' => $ppm->ID(), 'PAY_amount' => $t->total()));
     $this->assertEmpty($p->redirect_url());
     //set redirection info; we should ignore previously-added paypal tax and shipping
     //(so paypal can add calculate them again when we send them)
     $p = $ppg->set_redirection_info($p, NULL, self::return_url, self::notify_url, self::cancel_url);
     $this->assertNotEmpty($p->redirect_url());
     $this->assertEquals(self::paypal_url, $p->redirect_url());
     $this->assertNotEmpty($p->redirect_args());
     $rargs = $p->redirect_args();
     $items_purchased = $t->items_purchased();
     $first_item = array_shift($items_purchased);
     $second_item = array_shift($items_purchased);
     $this->assertEquals(sprintf('%s for %s', $first_item->ticket()->name(), $first_item->ticket_event_name()), $rargs['item_name_1']);
     $this->assertEquals($first_item->ticket()->price(), $rargs['amount_1']);
     $this->assertEquals(sprintf('%s for %s', $second_item->ticket()->name(), $second_item->ticket_event_name()), $rargs['item_name_2']);
     $this->assertEquals($second_item->ticket()->price(), $rargs['amount_2']);
     $this->assertEquals(1, $rargs['quantity_1']);
     //we shouldn't have told paypal how much tax to add. Let paypal decide.
     $this->assertFalse(isset($rargs['tax_cart']));
     //there should be no 3rd item for shipping
     $this->assertFalse(isset($rargs['amount_3']));
 }