danielebarchiesi@4: 'OG-context integration', danielebarchiesi@4: 'description' => 'Test the OG-context integration, which allows prepopulating by the group context.', danielebarchiesi@4: 'group' => 'Entity reference prepopulate', danielebarchiesi@4: 'dependencies' => array('og'), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: function setUp() { danielebarchiesi@4: parent::setUp('og_context', 'entityreference_prepopulate_test'); danielebarchiesi@4: danielebarchiesi@4: $this->user1 = $this->drupalCreateUser(); danielebarchiesi@4: $this->user2 = $this->drupalCreateUser(array('bypass node access', 'administer group')); danielebarchiesi@4: danielebarchiesi@4: $type = $this->drupalCreateContentType(); danielebarchiesi@4: $this->group_type = $type->type; danielebarchiesi@4: og_create_field(OG_GROUP_FIELD, 'node', $this->group_type); danielebarchiesi@4: danielebarchiesi@4: $type = $this->drupalCreateContentType(); danielebarchiesi@4: $this->group_content_type = $type->type; danielebarchiesi@4: danielebarchiesi@4: $og_field = og_fields_info(OG_AUDIENCE_FIELD); danielebarchiesi@4: // Enable the prepopulate behavior. danielebarchiesi@4: $og_field['instance']['settings']['behaviors']['prepopulate'] = array( danielebarchiesi@4: 'status' => TRUE, danielebarchiesi@4: 'action' => 'none', danielebarchiesi@4: 'fallback' => 'none', danielebarchiesi@4: 'skip_perm' => FALSE, danielebarchiesi@4: 'og_context' => TRUE, danielebarchiesi@4: ); danielebarchiesi@4: og_create_field(OG_AUDIENCE_FIELD, 'node', $this->group_content_type, $og_field); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Test the OG-context integration. danielebarchiesi@4: */ danielebarchiesi@4: function testPrepopulate() { danielebarchiesi@4: $settings = array( danielebarchiesi@4: 'type' => $this->group_type, danielebarchiesi@4: 'uid' => $this->user1->uid, danielebarchiesi@4: ); danielebarchiesi@4: $settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1; danielebarchiesi@4: $group1 = $this->drupalCreateNode($settings); danielebarchiesi@4: danielebarchiesi@4: og_group('node', $group1, array('entity_type' => 'user', 'entity' => $this->user2)); danielebarchiesi@4: danielebarchiesi@4: $this->drupalLogin($this->user2); danielebarchiesi@4: $this->drupalGet('node/add/' . str_replace('_', '-', $this->group_content_type)); danielebarchiesi@4: $this->assertNoOptionSelected('edit-og-group-ref-und-0-default', 1, 'Group-audience fields is not selected.'); danielebarchiesi@4: danielebarchiesi@4: // Set the OG-context(); danielebarchiesi@4: // See entityreference_prepopulate_init(). danielebarchiesi@4: $options = array( danielebarchiesi@4: 'query' => array( danielebarchiesi@4: 'gid' => $group1->nid, danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: danielebarchiesi@4: $this->drupalGet('node/add/' . str_replace('_', '-', $this->group_content_type), $options); danielebarchiesi@4: $this->assertOptionSelected('edit-og-group-ref-und-0-default', 1, 'Group-audience fields is selected.'); danielebarchiesi@4: } danielebarchiesi@4: }