public function testDelete()
 {
     $va_objects = array();
     $this->assertGreaterThan(0, $va_objects[] = $this->addTestRecord('ca_objects', array('intrinsic_fields' => array('type_id' => 'dataset'), 'preferred_labels' => array(array("locale" => "en_US", "name" => "My test dataset")))));
     $this->assertGreaterThan(0, $va_objects[] = $this->addTestRecord('ca_objects', array('intrinsic_fields' => array('type_id' => 'physical_object'), 'preferred_labels' => array(array("locale" => "en_US", "name" => "Test physical object")))));
     foreach ($va_objects as $vn_object_id) {
         $t_object = new ca_objects($vn_object_id);
         $t_object->setMode(ACCESS_WRITE);
         $t_object->delete(true, array('hard' => true));
     }
     $o_search = caGetSearchInstance('ca_objects');
     $o_result = $o_search->search('dataset');
     $this->assertEquals(0, $o_result->numHits(), 'dataset should not be indexed anymore');
     $o_result = $o_search->search('physical');
     $this->assertEquals(0, $o_result->numHits(), 'physical object should not be indexed anymore');
 }
 public function testInsertLoadAndDeleteCycleWithCaObjectsModel()
 {
     $t_list = new ca_lists();
     $va_object_types = $t_list->getItemsForList('object_types');
     $this->assertGreaterThan(0, sizeof($va_object_types), "No object types available");
     $va_object_types = caExtractValuesByUserLocale($va_object_types);
     $this->assertGreaterThan(0, sizeof($va_object_types), "No locale-filtered object types available");
     $vn_locale_id = 1;
     $t_object = new ca_objects();
     $t_object->setMode(ACCESS_WRITE);
     $vn_item_id = 0;
     foreach ($va_object_types as $va_object_type) {
         if (intval($va_object_type['is_enabled']) === 1) {
             $vn_item_id = $va_object_type['item_id'];
         }
     }
     $this->assertGreaterThan(0, $vn_item_id, 'No enabled object type found');
     $t_object->set('type_id', $vn_item_id);
     $t_object->set('locale_id', $vn_locale_id);
     $t_object->set('idno', time());
     $t_object->addAttribute(array('description' => 'Test description', 'locale_id' => $vn_locale_id), 'description');
     $vb_res = $t_object->insert();
     $this->assertTrue($vb_res !== false, 'Insert returned non-true value');
     // insert() returns false OR the primary key, therefore simply asserting $vb_res being true doesn't cut it
     $this->assertEquals($t_object->numErrors(), 0, "Errors on insert: " . join('; ', $t_object->getErrors()));
     $this->opa_test_record_ids['ca_objects'][] = $t_object->getPrimaryKey();
     $vb_res = $t_object->addLabel(array('name' => 'Unit test object'), $vn_locale_id, null, true);
     $this->assertGreaterThan(0, $vb_res, 'AddLabel returned zero value but should return non-zero label_id: ' . join('; ', $t_object->getErrors()));
     $t_object2 = new ca_objects();
     $vb_res = $t_object2->load($t_object->getPrimaryKey());
     $this->assertTrue($vb_res, 'Load of newly created record failed [record does not seem to exist or return row id was invalid?]');
     $this->assertEquals($t_object2->getLabelForDisplay(), 'Unit test object', 'Retrieved row label does not match');
     $this->assertEquals($t_object2->getAttributesForDisplay('description'), 'Test description', 'Retrieved value for attribute "description" does not match expected value');
     // try to search for it
     $o_search = new ObjectSearch();
     $qr_hits = $o_search->search("Unit test object");
     $this->assertGreaterThan(0, $qr_hits->numHits(), 'Search for ca_object by label found no results');
     $vb_found_object = false;
     while ($qr_hits->nextHit()) {
         if ($qr_hits->get('object_id') == $t_object->getPrimaryKey()) {
             $vb_found_object = true;
             break;
         }
     }
     $this->assertTrue($vb_found_object, 'ca_object was not in returned search results for ca_object by label');
     // try delete
     $t_object->delete(true, array('hard' => true));
     $this->assertEquals($t_object->numErrors(), 0, "Errors on delete: " . join('; ', $t_object->getErrors()));
 }
 public function tearDown()
 {
     // clean up test records
     $t_object = new ca_objects($this->opn_object_id);
     $t_object->setMode(ACCESS_WRITE);
     $vb_del = $t_object->delete(true, array('hard' => true));
     $this->assertTrue($vb_del, 'Deleting the test record shouldnt fail');
     $t_set = new ca_sets($this->opn_set_id);
     $t_set->setMode(ACCESS_WRITE);
     $vb_del = $t_set->delete(true, array('hard' => true));
     $this->assertTrue($vb_del, 'Deleting the test record shouldnt fail');
 }