/**
  * checks that when we reset a model, that it does so properly and
  * also returns the NEW model
  */
 public function test_reset_model()
 {
     $model_a = EE_Registry::instance()->load_model('Event');
     $model_a2 = EE_Registry::instance()->load_model('Event');
     $model_a3 = EEM_Event::instance();
     $this->assertEquals($model_a, $model_a2);
     $this->assertEquals($model_a2, $model_a3);
     $model_b1 = EEM_Event::reset();
     $this->assertNotSame($model_a, $model_b1);
     $model_b2 = EE_Registry::instance()->reset_model('Event');
     $this->assertNotSame($model_a, $model_b2);
 }
 /**
  * Tests that when we get rows from the database and a secondary table has no row,
  * but the primary one does, that the fields for the secondary table are given
  * DEFAULT values instead of NULLs
  * @group 7634
  */
 public function test_if_no_meta_row_use_defaults_not_nulls()
 {
     $e = $this->new_model_obj_with_dependencies('Event');
     //now use wpdb to directly delete its meta row
     global $wpdb;
     $deletions = $wpdb->delete(EEM_Event::instance()->second_table(), array('EVT_ID' => $e->ID()), array('%d'));
     $this->assertEquals(1, $deletions);
     //now forget about the old event object we had, we want to see what happens when we fetch it again
     EEM_Event::reset();
     $incomplete_e = EEM_Event::instance()->get_one_by_ID($e->ID());
     $actual_row = EEM_Event::instance()->get_all_wpdb_results(array(array('EVT_ID' => $e->ID())));
     $a_field_from_meta_table = EEM_Event::instance()->field_settings_for('EVT_display_ticket_selector');
     $another_field_from_meta_table = EEM_Event::instance()->field_settings_for('EVT_additional_limit');
     $this->assertEquals($a_field_from_meta_table->get_default_value(), $incomplete_e->get('EVT_display_ticket_selector'));
     $this->assertTrue(NULL !== $incomplete_e->get('EVT_display_ticket_selector'));
     $this->assertEquals($another_field_from_meta_table->get_default_value(), $incomplete_e->get('EVT_additional_limit'));
 }
 /**
  * @see https://events.codebasehq.com/projects/event-espresso/tickets/8799
  * @group 8799
  * @since 4.8.8.rc.019
  */
 public function test_default_reg_status()
 {
     //first verify the default reg status on config is pending payment
     $this->assertEquals(EEM_Registration::status_id_pending_payment, EE_Registry::instance()->CFG->registration->default_STS_ID);
     //verify creating default event from the model has that default reg status
     /** @type EE_Event $event */
     $event = EEM_Event::instance()->create_default_object();
     $this->assertEquals(EEM_Registration::status_id_pending_payment, $event->default_registration_status());
     //let's update config in the db to have default reg status of approved
     EE_Registry::instance()->CFG->registration->default_STS_ID = EEM_Registration::status_id_approved;
     EE_Registry::instance()->CFG->update_espresso_config();
     //let's reset for new test
     EEM_Event::reset();
     EE_Registry::reset();
     //k NOW the default reg status in config should be approved
     $this->assertEquals(EEM_Registration::status_id_approved, EE_Registry::instance()->CFG->registration->default_STS_ID);
     //new default event should have approved as the default reg status
     $event = EEM_Event::instance()->create_default_object();
     $this->assertEquals(EEM_Registration::status_id_approved, $event->default_registration_status());
 }