- <?php
-
- * @file
- * Contains EntityReferenceHandlersTestCase
- */
-
- * Test for Entity Reference admin UI.
- */
- class EntityReferenceAdminTestCase extends BackdropWebTestCase {
- public $admin_user;
- public $type;
- public $hyphen_type;
-
- public function setUp() {
- parent::setUp(array('field_ui', 'entity', 'entityreference'));
-
-
- $this->admin_user = $this->backdropCreateUser(array('access content', 'administer content types', 'administer fields'));
- $this->backdropLogin($this->admin_user);
-
-
- $type_name = strtolower($this->randomName(8)) . '_test';
- $type = $this->backdropCreateContentType(array('name' => $type_name, 'type' => $type_name));
- $this->type = $type->type;
-
- $this->hyphen_type = str_replace('_', '-', $this->type);
- }
-
- protected function assertFieldSelectOptions($name, $expected_options) {
- $xpath = $this->buildXPathQuery('//select[@name=:name]', array(':name' => $name));
- $fields = $this->xpath($xpath);
- if ($fields) {
- $field = $fields[0];
- $options = $this->getAllOptionsList($field);
- return $this->assertIdentical($options, $expected_options);
- }
- else {
- return $this->fail(t('Unable to find field @name', array('@name' => $name)));
- }
- }
-
-
- * Extract all the options of a select element.
- */
- protected function getAllOptionsList($element) {
- $options = array();
-
- foreach ($element->option as $option) {
- $options[] = (string) $option['value'];
- }
-
- return $options;
- }
-
- public function testFieldAdminHandler() {
- $bundle_path = 'admin/structure/types/manage/' . $this->hyphen_type;
-
-
- $this->backdropPost($bundle_path . '/fields', array(
- 'fields[_add_new_field][label]' => 'Test label',
- 'fields[_add_new_field][field_name]' => 'test',
- 'fields[_add_new_field][type]' => 'entityreference',
- 'fields[_add_new_field][widget_type]' => 'entityreference_autocomplete',
- ), t('Save'));
-
-
- $this->assertFieldByName('field[settings][target_type]', 'node');
-
- $this->assertFieldByName('field[settings][handler]', 'base');
-
-
- $entity_type = 'node';
- $entity_info = entity_get_info($entity_type);
- foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
- $this->assertFieldByName('field[settings][handler_settings][target_bundles][' . $bundle_name . ']');
- }
-
-
- $options = array('none', 'property', 'field');
- $this->assertFieldSelectOptions('field[settings][handler_settings][sort][type]', $options);
-
- $this->assertFieldByName('field[settings][handler_settings][sort][type]', 'none');
- $this->assertNoFieldByName('field[settings][handler_settings][sort][property]');
- $this->assertNoFieldByName('field[settings][handler_settings][sort][field]');
- $this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
-
- $this->backdropPostAJAX(NULL, array('field[settings][handler_settings][sort][type]' => 'property'), 'field[settings][handler_settings][sort][type]');
- $this->assertFieldByName('field[settings][handler_settings][sort][property]', '');
- $this->assertNoFieldByName('field[settings][handler_settings][sort][field]');
- $this->assertFieldByName('field[settings][handler_settings][sort][direction]', 'ASC');
-
- $this->backdropPostAJAX(NULL, array('field[settings][handler_settings][sort][type]' => 'field'), 'field[settings][handler_settings][sort][type]');
- $this->assertNoFieldByName('field[settings][handler_settings][sort][property]');
- $this->assertFieldByName('field[settings][handler_settings][sort][field]', '');
- $this->assertFieldByName('field[settings][handler_settings][sort][direction]', 'ASC');
-
- $this->backdropPostAJAX(NULL, array('field[settings][handler_settings][sort][type]' => 'none'), 'field[settings][handler_settings][sort][type]');
-
-
- $this->backdropPost(NULL, array(), t('Save field settings'));
-
-
- $this->backdropPost(NULL, array(), t('Save settings'));
-
-
- $this->assertFieldByXPath('//input[@name="fields[field_test][parent_wrapper][hidden_name]"]', 'field_test', 'Field was created and appears in the overview page.');
- }
- }