|
@@ -11,169 +11,208 @@ class ChadoFieldGetValuesListTest extends TripalTestCase {
|
|
// Uncomment to auto start and rollback db transactions per test method.
|
|
// Uncomment to auto start and rollback db transactions per test method.
|
|
use DBTransaction;
|
|
use DBTransaction;
|
|
|
|
|
|
- // Stores a list of fields to be tested including their storage method and instance info.
|
|
|
|
|
|
+ // Stores a list of field instances to be tested including their storage method and instance info.
|
|
private $field_list = NULL;
|
|
private $field_list = NULL;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Test for fields based on columns in the base table.
|
|
|
|
|
|
+ * Test getValueList for fields based on columns in the base table.
|
|
|
|
+ *
|
|
|
|
+ * @dataProvider getBaseFields
|
|
*
|
|
*
|
|
* @group fields
|
|
* @group fields
|
|
* @group getValueList
|
|
* @group getValueList
|
|
*/
|
|
*/
|
|
- public function testBaseTableColumns() {
|
|
|
|
|
|
+ public function testBaseTableColumns($field_name, $bundle_name, $info) {
|
|
include_once(drupal_get_path('tripal_chado', 'module') . '/includes/TripalFields/ChadoField.inc');
|
|
include_once(drupal_get_path('tripal_chado', 'module') . '/includes/TripalFields/ChadoField.inc');
|
|
|
|
|
|
|
|
+ // Construct the Field instance we want the values for.
|
|
|
|
+ // Specifying "ChadoField" here ensures we are only testing our
|
|
|
|
+ // implementation of getValueList() and not the custom version for any
|
|
|
|
+ // given field.
|
|
|
|
+ // YOU SHOULD TEST CUSTOM FIELD IMPLEMENTATIONS SEPARATELY.
|
|
|
|
+ $instance = new \ChadoField($info['field_info'], $info['instance_info']);
|
|
|
|
+
|
|
|
|
+ // Retrieve the values.
|
|
|
|
+ // $values will be an array containing the distinct set of values for this field instance.
|
|
|
|
+ $values = $instance->getValueList(array('limit' => 5));
|
|
|
|
+
|
|
|
|
+ // Ensure we have values returned!
|
|
|
|
+ $this->assertTrue(
|
|
|
|
+ is_array($values),
|
|
|
|
+ t(
|
|
|
|
+ 'No values returned for @field_name (bundle: @bundle_name, bundle base table: @bundle_base_table, chado table: @chado_table, chado column: @chado_column).',
|
|
|
|
+ array(
|
|
|
|
+ '@field_name' => $field_name,
|
|
|
|
+ '@bundle_name' => $bundle_name,
|
|
|
|
+ '@bundle_base_table' => $info['bundle_base_table'],
|
|
|
|
+ '@chado_table' => $info['instance_info']['settings']['chado_table'],
|
|
|
|
+ '@chado_column' => $info['instance_info']['settings']['chado_column'],
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // Ensure there are no more then 5 as specified in the limit above.
|
|
|
|
+ $this->assertLessThanOrEqual(5, sizeof($values),
|
|
|
|
+ t('Returned too many results for @field_name.', array('@field_name' => $field_name)));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * DataProvider: a list of fields who store their data in the base table of a bundle.
|
|
|
|
+ *
|
|
|
|
+ * Each element describes a field instance and consists of:
|
|
|
|
+ * - the machine name of the field (e.g. obi__organism).
|
|
|
|
+ * - the machine name of the bundle (e.g. bio_data_17).
|
|
|
|
+ * - an array of additional information including:
|
|
|
|
+ * - instance_info: information about the field instance.
|
|
|
|
+ * - field_info: information about the field.
|
|
|
|
+ * - bundle: the TripalBundle object.
|
|
|
|
+ * - bundle_base_table: if applicable, the chado base table the bundle stores it's data in.
|
|
|
|
+ * - base_schema: the Tripal Schema array for the bundle_base_table.
|
|
|
|
+ */
|
|
|
|
+ public function getBaseFields() {
|
|
|
|
+
|
|
// Retrieve a list of fields to test.
|
|
// Retrieve a list of fields to test.
|
|
// Note: this list is cached to improve performance.
|
|
// Note: this list is cached to improve performance.
|
|
$fields = $this->retrieveFieldList();
|
|
$fields = $this->retrieveFieldList();
|
|
|
|
|
|
- // Only iterate through fields that store their data in chado and
|
|
|
|
- // specifically, where the field stores it's data in the base table of the bundle
|
|
|
|
- // and is not a foreign key.
|
|
|
|
- foreach ($fields['field_chado_storage']['base'] as $key => $info) {
|
|
|
|
- $field_name = $info['field_name'];
|
|
|
|
-
|
|
|
|
- // Construct the Field instance we want the values for.
|
|
|
|
- // Specifying "ChadoField" here ensures we are only testing our
|
|
|
|
- // implementation of getValueList() and not the custom version for any
|
|
|
|
- // given field.
|
|
|
|
- // YOU SHOULD TEST CUSTOM FIELD IMPLEMENTATIONS SEPARATELY.
|
|
|
|
- $instance = new \ChadoField($info['field_info'], $info['instance_info']);
|
|
|
|
-
|
|
|
|
- // Retrieve the values.
|
|
|
|
- // $values will be an array containing the distinct set of values for this field instance.
|
|
|
|
- $values = $instance->getValueList(array('limit' => 5));
|
|
|
|
-
|
|
|
|
- // Ensure we have values returned!
|
|
|
|
- $this->assertTrue(
|
|
|
|
- is_array($values),
|
|
|
|
- t(
|
|
|
|
- 'No values returned for @field_name (bundle: @bundle_name, bundle base table: @bundle_base_table, chado table: @chado_table, chado column: @chado_column).',
|
|
|
|
- array(
|
|
|
|
- '@field_name' => $field_name,
|
|
|
|
- '@bundle_name' => $info['bundle_name'],
|
|
|
|
- '@bundle_base_table' => $info['bundle_base_table'],
|
|
|
|
- '@chado_table' => $info['instance_info']['settings']['chado_table'],
|
|
|
|
- '@chado_column' => $info['instance_info']['settings']['chado_column'],
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- // Ensure there are no more then 5 as specified in the limit above.
|
|
|
|
- $this->assertLessThanOrEqual(5, sizeof($values),
|
|
|
|
- t('Returned too many results for @field_name.', array('@field_name' => $field_name)));
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ return $fields['field_chado_storage']['base'];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Test for fields based on columns in the base table that are also foreign keys.
|
|
* Test for fields based on columns in the base table that are also foreign keys.
|
|
*
|
|
*
|
|
|
|
+ * @dataProvider getBaseFkFields
|
|
|
|
+ *
|
|
* @group fields
|
|
* @group fields
|
|
* @group getValueList
|
|
* @group getValueList
|
|
*/
|
|
*/
|
|
- public function testBaseTableForeignKey() {
|
|
|
|
|
|
+ public function testBaseTableForeignKey($field_name, $bundle_name, $info) {
|
|
include_once(drupal_get_path('tripal_chado', 'module') . '/includes/TripalFields/ChadoField.inc');
|
|
include_once(drupal_get_path('tripal_chado', 'module') . '/includes/TripalFields/ChadoField.inc');
|
|
|
|
|
|
|
|
+ // Construct the Field instance we want the values for.
|
|
|
|
+ // Specifying "ChadoField" here ensures we are only testing our
|
|
|
|
+ // implementation of getValueList() and not the custom version for any
|
|
|
|
+ // given field.
|
|
|
|
+ // YOU SHOULD TEST CUSTOM FIELD IMPLEMENTATIONS SEPARATELY.
|
|
|
|
+ $instance = new \ChadoField($info['field_info'], $info['instance_info']);
|
|
|
|
+
|
|
|
|
+ // Retrieve the values using defaults.
|
|
|
|
+ // $values will be an array containing the distinct set of values for this field instance.
|
|
|
|
+ $values = $instance->getValueList(array('limit' => 5));
|
|
|
|
+
|
|
|
|
+ // Ensure we have values returned!
|
|
|
|
+ $this->assertTrue(
|
|
|
|
+ is_array($values),
|
|
|
|
+ t(
|
|
|
|
+ 'No values returned for @field_name with no label string set (bundle: @bundle_name, bundle base table: @bundle_base_table, chado table: @chado_table, chado column: @chado_column).',
|
|
|
|
+ array(
|
|
|
|
+ '@field_name' => $field_name,
|
|
|
|
+ '@bundle_name' => $bundle_name,
|
|
|
|
+ '@bundle_base_table' => $info['bundle_base_table'],
|
|
|
|
+ '@chado_table' => $info['instance_info']['settings']['chado_table'],
|
|
|
|
+ '@chado_column' => $info['instance_info']['settings']['chado_column'],
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // Ensure there are no more then 5 as specified in the limit above.
|
|
|
|
+ $this->assertLessThanOrEqual(5, sizeof($values),
|
|
|
|
+ t('Returned too many results for @field_name.', array('@field_name' => $field_name)));
|
|
|
|
+
|
|
|
|
+ // @todo Ensure it works with a label string set.
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * DataProvider: a list of fields who store their data in the base table of a bundle.
|
|
|
|
+ *
|
|
|
|
+ * Each element describes a field instance and consists of:
|
|
|
|
+ * - the machine name of the field (e.g. obi__organism).
|
|
|
|
+ * - the machine name of the bundle (e.g. bio_data_17).
|
|
|
|
+ * - an array of additional information including:
|
|
|
|
+ * - instance_info: information about the field instance.
|
|
|
|
+ * - field_info: information about the field.
|
|
|
|
+ * - bundle: the TripalBundle object.
|
|
|
|
+ * - bundle_base_table: if applicable, the chado base table the bundle stores it's data in.
|
|
|
|
+ * - base_schema: the Tripal Schema array for the bundle_base_table.
|
|
|
|
+ */
|
|
|
|
+ public function getBaseFkFields() {
|
|
|
|
+
|
|
// Retrieve a list of fields to test.
|
|
// Retrieve a list of fields to test.
|
|
// Note: this list is cached to improve performance.
|
|
// Note: this list is cached to improve performance.
|
|
$fields = $this->retrieveFieldList();
|
|
$fields = $this->retrieveFieldList();
|
|
|
|
|
|
- // Only iterate through fields that store their data in chado and
|
|
|
|
- // specifically, where the field stores it's data in the base table of the bundle
|
|
|
|
- // and IS a foreign key.
|
|
|
|
- foreach ($fields['field_chado_storage']['foreign key'] as $key => $info) {
|
|
|
|
- $field_name = $info['field_name'];
|
|
|
|
-
|
|
|
|
- // Construct the Field instance we want the values for.
|
|
|
|
- // Specifying "ChadoField" here ensures we are only testing our
|
|
|
|
- // implementation of getValueList() and not the custom version for any
|
|
|
|
- // given field.
|
|
|
|
- // YOU SHOULD TEST CUSTOM FIELD IMPLEMENTATIONS SEPARATELY.
|
|
|
|
- $instance = new \ChadoField($info['field_info'], $info['instance_info']);
|
|
|
|
-
|
|
|
|
- // Retrieve the values using defaults.
|
|
|
|
- // $values will be an array containing the distinct set of values for this field instance.
|
|
|
|
- $values = $instance->getValueList(array('limit' => 5));
|
|
|
|
-
|
|
|
|
- // Ensure we have values returned!
|
|
|
|
- $this->assertTrue(
|
|
|
|
- is_array($values),
|
|
|
|
- t(
|
|
|
|
- 'No values returned for @field_name with no label string set (bundle: @bundle_name, bundle base table: @bundle_base_table, chado table: @chado_table, chado column: @chado_column).',
|
|
|
|
- array(
|
|
|
|
- '@field_name' => $field_name,
|
|
|
|
- '@bundle_name' => $info['bundle_name'],
|
|
|
|
- '@bundle_base_table' => $info['bundle_base_table'],
|
|
|
|
- '@chado_table' => $info['instance_info']['settings']['chado_table'],
|
|
|
|
- '@chado_column' => $info['instance_info']['settings']['chado_column'],
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- // Ensure there are no more then 5 as specified in the limit above.
|
|
|
|
- $this->assertLessThanOrEqual(5, sizeof($values),
|
|
|
|
- t('Returned too many results for @field_name.', array('@field_name' => $field_name)));
|
|
|
|
-
|
|
|
|
- // @todo Ensure it works with a label string set.
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ return $fields['field_chado_storage']['foreign key'];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Test for fields based on tables besides the base one for the bundle.
|
|
* Test for fields based on tables besides the base one for the bundle.
|
|
- *
|
|
|
|
* CURRENTLY RETRIEVING VALUES FOR THESE TABLES IS NOT SUPPORTED.
|
|
* CURRENTLY RETRIEVING VALUES FOR THESE TABLES IS NOT SUPPORTED.
|
|
*
|
|
*
|
|
|
|
+ * @dataProvider getNonBaseFields
|
|
|
|
+ *
|
|
* @group fields
|
|
* @group fields
|
|
* @group getValueList
|
|
* @group getValueList
|
|
*/
|
|
*/
|
|
- public function testNonBaseTable() {
|
|
|
|
|
|
+ public function testNonBaseTable($field_name, $bundle_name, $info) {
|
|
include_once(drupal_get_path('tripal_chado', 'module') . '/includes/TripalFields/ChadoField.inc');
|
|
include_once(drupal_get_path('tripal_chado', 'module') . '/includes/TripalFields/ChadoField.inc');
|
|
|
|
|
|
- // Retrieve a list of fields to test.
|
|
|
|
- // Note: this list is cached to improve performance.
|
|
|
|
- $fields = $this->retrieveFieldList();
|
|
|
|
|
|
+ // Construct the Field instance we want the values for.
|
|
|
|
+ // Specifying "ChadoField" here ensures we are only testing our
|
|
|
|
+ // implementation of getValueList() and not the custom version for any
|
|
|
|
+ // given field.
|
|
|
|
+ // YOU SHOULD TEST CUSTOM FIELD IMPLEMENTATIONS SEPARATELY.
|
|
|
|
+ $instance = new \ChadoField($info['field_info'], $info['instance_info']);
|
|
|
|
|
|
- // Only iterate through fields that store their data in chado and
|
|
|
|
- // specifically, where the field stores it's data in the base table of the bundle
|
|
|
|
- // and is not a foreign key.
|
|
|
|
- foreach ($fields['field_chado_storage']['referring'] as $key => $info) {
|
|
|
|
- $field_name = $info['field_name'];
|
|
|
|
|
|
+ // Supress tripal errors
|
|
|
|
+ putenv("TRIPAL_SUPPRESS_ERRORS=TRUE");
|
|
|
|
+ ob_start();
|
|
|
|
|
|
- // Construct the Field instance we want the values for.
|
|
|
|
- // Specifying "ChadoField" here ensures we are only testing our
|
|
|
|
- // implementation of getValueList() and not the custom version for any
|
|
|
|
- // given field.
|
|
|
|
- // YOU SHOULD TEST CUSTOM FIELD IMPLEMENTATIONS SEPARATELY.
|
|
|
|
- $instance = new \ChadoField($info['field_info'], $info['instance_info']);
|
|
|
|
|
|
+ try {
|
|
|
|
|
|
- // Supress tripal errors
|
|
|
|
- putenv("TRIPAL_SUPPRESS_ERRORS=TRUE");
|
|
|
|
- ob_start();
|
|
|
|
|
|
+ // Retrieve the values.
|
|
|
|
+ // $values will be an array containing the distinct set of values for this field instance.
|
|
|
|
+ $values = $instance->getValueList(array('limit' => 5));
|
|
|
|
|
|
- try {
|
|
|
|
|
|
+ // @todo Check that we got the correct warning message.
|
|
|
|
+ // Currently we can't check this because we need to supress the error in order to keep it from printing
|
|
|
|
+ // but once we do, we can't access it ;-P
|
|
|
|
|
|
- // Retrieve the values.
|
|
|
|
- // $values will be an array containing the distinct set of values for this field instance.
|
|
|
|
- $values = $instance->getValueList(array('limit' => 5));
|
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
+ $this->fail("Although we don't support values lists for $field_name, it still shouldn't produce an exception!");
|
|
|
|
+ }
|
|
|
|
|
|
- // @todo Check that we got the correct warning message.
|
|
|
|
- // Currently we can't check this because we need to supress the error in order to keep it from printing
|
|
|
|
- // but once we do, we can't access it ;-P
|
|
|
|
|
|
+ // Clean the buffer and unset tripal errors suppression
|
|
|
|
+ ob_end_clean();
|
|
|
|
+ putenv("TRIPAL_SUPPRESS_ERRORS");
|
|
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
- $this->fail("Although we don't support values lists for $field_name, it still shouldn't produce an exception!");
|
|
|
|
- }
|
|
|
|
|
|
+ $this->assertFalse($values, "We don't support retrieving values for $field_name since it doesn't store data in the base table.");
|
|
|
|
|
|
- // Clean the buffer and unset tripal errors suppression
|
|
|
|
- ob_end_clean();
|
|
|
|
- putenv("TRIPAL_SUPPRESS_ERRORS");
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- $this->assertFalse($values, "We don't support retrieving values for $field_name since it doesn't store data in the base table.");
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * DataProvider: a list of fields who store their data in the base table of a bundle.
|
|
|
|
+ *
|
|
|
|
+ * Each element describes a field instance and consists of:
|
|
|
|
+ * - the machine name of the field (e.g. obi__organism).
|
|
|
|
+ * - the machine name of the bundle (e.g. bio_data_17).
|
|
|
|
+ * - an array of additional information including:
|
|
|
|
+ * - instance_info: information about the field instance.
|
|
|
|
+ * - field_info: information about the field.
|
|
|
|
+ * - bundle: the TripalBundle object.
|
|
|
|
+ * - bundle_base_table: if applicable, the chado base table the bundle stores it's data in.
|
|
|
|
+ * - base_schema: the Tripal Schema array for the bundle_base_table.
|
|
|
|
+ */
|
|
|
|
+ public function getNonBaseFields() {
|
|
|
|
+
|
|
|
|
+ // Retrieve a list of fields to test.
|
|
|
|
+ // Note: this list is cached to improve performance.
|
|
|
|
+ $fields = $this->retrieveFieldList();
|
|
|
|
+
|
|
|
|
+ return $fields['field_chado_storage']['referring'];
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns a list of Fields sorted by their backend, etc. for use in tests.
|
|
* Returns a list of Fields sorted by their backend, etc. for use in tests.
|
|
*/
|
|
*/
|
|
@@ -189,7 +228,7 @@ class ChadoFieldGetValuesListTest extends TripalTestCase {
|
|
|
|
|
|
foreach ($fields as $field_name => $instance_info) {
|
|
foreach ($fields as $field_name => $instance_info) {
|
|
$bundle_base_table = $base_schema = NULL;
|
|
$bundle_base_table = $base_schema = NULL;
|
|
-
|
|
|
|
|
|
+
|
|
// Load the field info.
|
|
// Load the field info.
|
|
$field_info = field_info_field($field_name);
|
|
$field_info = field_info_field($field_name);
|
|
|
|
|
|
@@ -223,7 +262,7 @@ class ChadoFieldGetValuesListTest extends TripalTestCase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$info = array(
|
|
$info = array(
|
|
'field_name' => $field_name,
|
|
'field_name' => $field_name,
|
|
'bundle_name' => $bundle_name,
|
|
'bundle_name' => $bundle_name,
|
|
@@ -237,10 +276,18 @@ class ChadoFieldGetValuesListTest extends TripalTestCase {
|
|
$key = $bundle_name . '--' . $field_name;
|
|
$key = $bundle_name . '--' . $field_name;
|
|
|
|
|
|
if ($rel) {
|
|
if ($rel) {
|
|
- $this->field_list[$storage][$rel][$key] = $info;
|
|
|
|
|
|
+ $this->field_list[$storage][$rel][$key] = array(
|
|
|
|
+ $field_name,
|
|
|
|
+ $bundle_name,
|
|
|
|
+ $info
|
|
|
|
+ );
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- $this->field_list[$storage][$key] = $info;
|
|
|
|
|
|
+ $this->field_list[$storage][$key] = array(
|
|
|
|
+ $field_name,
|
|
|
|
+ $bundle_name,
|
|
|
|
+ $info
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|