/** * Tests custom data types integration. */ public function testCustomDataTypes() { $original_value = $this->entities[1]->get('name')->value; $original_type = $this->index->getFields()['entity:entity_test/name']->getType(); $item = $this->index->loadItem('entity:entity_test/1:en'); $item = Utility::createItemFromObject($this->index, $item, 'entity:entity_test/1:en'); $name_field = $item->getField('entity:entity_test/name'); $processed_value = $name_field->getValues()[0]; $processed_type = $name_field->getType(); $this->assertEqual($processed_value, $original_value, 'The processed value matches the original value'); $this->assertEqual($processed_type, $original_type, 'The processed type matches the original type.'); // Reset the fields on the item and change to the supported data type. $item->setFieldsExtracted(FALSE); $item->setFields(array()); $this->index->getFields()['entity:entity_test/name']->setType('search_api_test_data_type'); $name_field = $item->getField('entity:entity_test/name'); $processed_value = $name_field->getValues()[0]; $processed_type = $name_field->getType(); $this->assertEqual($processed_value, $original_value, 'The processed value matches the original value'); $this->assertEqual($processed_type, 'search_api_test_data_type', 'The processed type matches the new type.'); // Reset the fields on the item and change to the non-supported data type. $item->setFieldsExtracted(FALSE); $item->setFields(array()); $this->index->getFields()['entity:entity_test/name']->setType('search_api_unsupported_test_data_type'); $name_field = $item->getField('entity:entity_test/name'); $processed_value = $name_field->getValues()[0]; $processed_type = $name_field->getType(); $this->assertEqual($processed_value, $original_value, 'The processed value matches the original value'); $this->assertEqual($processed_type, 'integer', 'The processed type matches the fallback type.'); // Reset the fields on the item and change to the data altering data type. $item->setFieldsExtracted(FALSE); $item->setFields(array()); $this->index->getFields()['entity:entity_test/name']->setType('search_api_altering_test_data_type'); $name_field = $item->getField('entity:entity_test/name'); $processed_value = $name_field->getValues()[0]; $processed_type = $name_field->getType(); $this->assertEqual($processed_value, strlen($original_value), 'The processed value matches the altered original value'); $this->assertEqual($processed_type, 'search_api_altering_test_data_type', 'The processed type matches the defined type.'); }
/** * {@inheritdoc} */ public function getOriginalObject($load = TRUE) { if (!isset($this->originalObject) && $load) { $this->originalObject = $this->index->loadItem($this->id); if (!$this->originalObject) { throw new SearchApiException('Failed to load original object ' . $this->id); } } return $this->originalObject; }
/** * {@inheritdoc} */ public function loadItem($item_id) { return $this->entity->loadItem($item_id); }