public function test_insert_and_update_and_delete() { $term1 = EE_Term::new_instance(array('name' => 'monkey1', 'slug' => 'monkey1')); $term2 = EE_Term::new_instance(array('name' => 'monkey2', 'slug' => 'monkey2')); $term1->save(); $term2->save(); $tt_1 = EE_Term_Taxonomy::new_instance(array('taxonomy' => 'whatever', 'term_id' => $term1->ID())); $tt_1->save(); $tt_2 = EE_Term_Taxonomy::new_instance(array('taxonomy' => 'whatever', 'term_id' => $term2->ID())); $tt_2->save(); $e = EE_Event::new_instance(array('EVT_name' => 'for_term_1')); $e->save(); //ok done setup //test INSERT $this->assertEquals(0, $tt_1->count()); $new_tr_id = EEM_Term_Relationship::instance()->insert(array('term_taxonomy_id' => $tt_1->ID(), 'object_id' => $e->ID())); $this->assertNotNull($new_tr_id); //refresh out term_taxonomy objects, as the database has changed $tt_1 = EEM_Term_Taxonomy::reset()->get_one_by_ID($tt_1->ID()); $tt_2 = EEM_Term_Taxonomy::instance()->get_one_by_ID($tt_2->ID()); $this->assertEquals(1, $tt_1->count()); $this->assertEquals(0, $tt_2->count()); //test UPDATE... except we can't update term_relationship because there's no Primary Key //on it. This should be fixed at some point //@todo: fix this test // $updated = EEM_Term_Relationship::instance()->update_by_ID(array('term_taxonomy_id'=>$tt_2->ID() ), $new_tr_id ); // //refresh out term_taxonomy objects, as the database has changed // $tt_1 = EEM_Term_Taxonomy::reset()->get_one_by_ID( $tt_1->ID() ); // $tt_2 = EEM_Term_Taxonomy::instance()->get_one_by_ID($tt_2->ID() ); // $this->assertEquals( 0, $tt_1->count() ); // $this->assertEquals(1,$tt_2->count() ); //test DELETE //@todo: fix this test too. see above // $count_deleted = EEM_Term_Relationship::instance()->delete_by_ID($new_tr_id); // $this->assertNotEmpty( $count_deleted ); // //refresh out term_taxonomy objects, as the database has changed // $tt_1 = EEM_Term_Taxonomy::reset()->get_one_by_ID( $tt_1->ID() ); // $tt_2 = EEM_Term_Taxonomy::instance()->get_one_by_ID($tt_2->ID() ); // $this->assertEquals( 0, $tt_1->count() ); // $this->assertEquals(0,$tt_2->count() ); }
/** * test that term relationships are migrated ok if they would conflict with something already in the db */ function test_save_data_array_to_db__from_other_site__no_duplicate_term_relationships() { $event_id_from_other_db = 122; $term_tax_from_other_db = 32; $old_term_r_order = 3; $new_term_r_order = 123; $old_term_r_data = array('object_id' => $event_id_from_other_db, 'term_taxonomy_id' => $term_tax_from_other_db, 'term_order' => $old_term_r_order); $a_real_event = $this->new_model_obj_with_dependencies('Event'); $a_real_term_taxonomy = $this->new_model_obj_with_dependencies('Term_Taxonomy'); $a_real_term_r = $this->new_model_obj_with_dependencies('Term_Relationship', array('object_id' => $a_real_event->ID(), 'term_taxonomy_id' => $a_real_term_taxonomy->ID(), 'term_order' => $new_term_r_order)); $csv_data = array('Term_Relationship' => array($old_term_r_data)); $mapping_data = array('Event' => array($event_id_from_other_db => $a_real_event->ID()), 'Term_Taxonomy' => array($term_tax_from_other_db => $a_real_term_taxonomy->ID())); $old_term_r_count = EEM_Term_Relationship::instance()->count(); $new_mapping = EE_Import::instance()->save_data_rows_to_db($csv_data, true, $mapping_data); $this->_assertNoImportErrors(); //there should be NO new term relationships. it should have just been updated $this->assertEquals($old_term_r_count, EEM_Term_Relationship::instance()->count()); $this->assertEquals(1, count($new_mapping['Term_Relationship'])); $old_term_r_id = EEM_Term_Relationship::instance()->get_index_primary_key_string($old_term_r_data); $new_term_r_id = $new_mapping['Term_Relationship'][$old_term_r_id]; $new_term_r = EEM_Term_Relationship::instance()->get_one_by_ID($new_term_r_id); $this->assertInstanceOf('EE_Term_Relationship', $new_term_r); $this->assertEquals($old_term_r_order, $new_term_r->get('term_order')); }
public function test_get_all__caps__delete__with_assign_event_category() { //log the user in global $current_user; $current_user = $this->user; $current_user->add_cap('ee_edit_events'); $current_user->add_cap('ee_assign_event_category'); //now check they can only see the term relationship for their own event $term_rs = EEM_Term_Relationship::instance()->get_all(array(array('object_id' => array('IN', array($this->my_event->ID(), $this->others_event->ID()))), 'order_by' => array('object_id' => 'ASC'), 'caps' => EEM_Base::caps_delete)); $this->assertEEModelObjectsEquals($this->term_r_for_my_event, reset($term_rs)); $this->assertEquals(1, count($term_rs)); }