Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port OgComplexWidgetTest #140

Open
wants to merge 31 commits into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e02160c
Split OgComplexWidgetTest into a separate class.
jhedstrom Nov 26, 2015
1955734
Remove the original D7 test.
pfrenssen Jan 21, 2016
b1c34b9
Put the test in a new folder dedicated to web tests.
pfrenssen Jan 21, 2016
e08f839
Use shorthand array syntax.
pfrenssen Jan 21, 2016
c5a3d1b
Start porting.
pfrenssen Jan 21, 2016
972489b
Add missing schema for the complex widget.
pfrenssen Jan 21, 2016
b0bebf6
Merge remote-tracking branch 'origin/8.x-1.x' into port-og-complex-wi…
pfrenssen Jan 22, 2016
a1acba0
Enable functional tests on Travis.
pfrenssen Jan 22, 2016
a3d5f56
Attempt to fix endless loop on Travis CI.
pfrenssen Jan 22, 2016
bfc6bd8
The group audience field will be visible in the future.
pfrenssen Jan 22, 2016
911a496
Let's make it a BrowserTest.
pfrenssen Jan 22, 2016
62f79ad
Use various traits to import test helper methods.
pfrenssen Jan 22, 2016
13ce2b2
Porting in progress.
pfrenssen Jan 22, 2016
b5f7a3f
Merge remote-tracking branch 'origin/8.x-1.x' into port-og-complex-wi…
pfrenssen Jan 25, 2016
feb1e15
Merge remote-tracking branch 'origin/8.x-1.x' into port-og-complex-wi…
pfrenssen Jan 25, 2016
decc588
Merge branch 'target-all-bundles' into port-og-complex-widget-test
pfrenssen Jan 25, 2016
323a730
Porting in progress.
pfrenssen Jan 25, 2016
9a18fb2
The 'Other Groups' field was looking at the wrong key and letting emp…
pfrenssen Jan 26, 2016
e3da2b7
Add reminder for my future self.
pfrenssen Jan 26, 2016
e4cfdc8
Finish OgComplexWidgetTest::testOtherGroups().
pfrenssen Jan 27, 2016
af0856f
Merge branch 'other-groups-no-references' into port-og-complex-widget…
pfrenssen Jan 27, 2016
eae12e3
Porting in progress.
pfrenssen Jan 27, 2016
ee8a2fd
Small code style fixes in Og.
pfrenssen Jan 27, 2016
70166da
Finish porting of ::testHiddenGroupIds(). This functionality has regr…
pfrenssen Jan 27, 2016
e0ea1cc
Merge remote-tracking branch 'origin/8.x-1.x' into port-og-complex-wi…
pfrenssen Feb 10, 2016
afba489
Merge branch 'reference-string-ids' into port-og-complex-widget-test
pfrenssen Feb 12, 2016
4e9ba03
Merge remote-tracking branch 'origin/8.x-1.x' into port-og-complex-wi…
pfrenssen Mar 8, 2016
25b6bf3
Fix MissingGroupException when loading ReferenceStringIdTest.
pfrenssen Mar 8, 2016
6c50c46
Use a random field name for the group audience field.
pfrenssen Mar 8, 2016
ac1eadc
Content is now referenced solely through the ER field. OgMembership i…
pfrenssen Mar 9, 2016
20634bd
Use the default field name again, the complex field was disappearing.
pfrenssen Mar 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Og.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Drupal\og;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
Expand Down Expand Up @@ -119,9 +118,9 @@ public static function createField($plugin_id, $entity_type, $bundle, array $set
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to get groups for.
* @param $states
* @param array $states
* (optional) Array with the state to return. Defaults to active.
* @param $field_name
* @param string $field_name
* (optional) The field name associated with the group.
*
* @return array
Expand Down Expand Up @@ -395,10 +394,10 @@ public static function permissionHandler() {
* @param $group_ids
* Array with group IDs that their cache should be invalidated.
*/
public static function invalidateCache($group_ids = array()) {
public static function invalidateCache($group_ids = []) {
// @todo We should not be using drupal_static() review and remove.
// Reset static cache.
$caches = array(
$caches = [
'og_user_access',
'og_user_access_alter',
'og_role_permissions',
Expand All @@ -408,7 +407,7 @@ public static function invalidateCache($group_ids = array()) {
'og_get_membership',
'og_get_field_og_membership_properties',
'og_get_user_roles',
);
];

foreach ($caches as $cache) {
drupal_static_reset($cache);
Expand Down
169 changes: 0 additions & 169 deletions tests/og.test
Original file line number Diff line number Diff line change
Expand Up @@ -1022,175 +1022,6 @@ class OgMigrate7000TestCase extends UpgradePathTestCase {
}
}


/**
* Test the complex widget.
*/
class OgComplexWidgetTestCase extends DrupalWebTestCase {

public static function getInfo() {
return array(
'name' => 'OG reference widget',
'description' => 'Test the OG reference widget behavior.',
'group' => 'Organic groups',
);
}

function setUp() {
parent::setUp('og');

// Add OG group field to a the node's "group" bundle.
$this->drupalCreateContentType(array('type' => 'group'));
og_create_field(OG_GROUP_FIELD, 'node', 'group');

// Add OG audience field to the node's "post" bundle.
$this->drupalCreateContentType(array('type' => 'post'));
$og_field = og_fields_info(OgGroupAudienceHelper::DEFAULT_FIELD);
$og_field['instance']['required'] = TRUE;
og_create_field(OgGroupAudienceHelper::DEFAULT_FIELD, 'node', 'post', $og_field);
}

/**
* Test "field modes" of the OG reference widget.
*/
function testFieldModes() {
$user1 = $this->drupalCreateUser(array('administer group', 'access content', 'create post content'));
$user2 = $this->drupalCreateUser(array('access content', 'create post content'));

// Create group nodes.
$settings = array(
'type' => 'group',
OG_GROUP_FIELD . '[und][0][value]' => 1,
);
$settings['uid'] = $user1->uid;
$group1 = $this->drupalCreateNode($settings);

$settings['uid'] = $user2->uid;
$group2 = $this->drupalCreateNode($settings);

$settings = array(
'type' => 'post',
);
$settings['uid'] = $user1->uid;
$post1 = $this->drupalCreateNode($settings);
og_group('node', $group1->nid, array('entity_type' => 'node', 'entity' => $post1));

$settings['uid'] = $user2->uid;
$post2 = $this->drupalCreateNode($settings);
og_group('node', $group2->nid, array('entity_type' => 'node', 'entity' => $post2));

$this->drupalLogin($user1);
$this->drupalGet("node/$post1->nid/edit");

$fields = $this->xpath('//*[@id="edit-og-group-ref-und-0-default"]');
$this->assertEqual($fields[0]->option['value'], '_none', '"Default" field mode is not required for administrator.');

$fields = $this->xpath('//*[@id="edit-og-group-ref-und-0-admin-0-target-id"]');
$this->assertTrue(strpos($fields[0]->attributes()->class[0], 'form-autocomplete'), '"Administrator field more is an autocomplete widget type."');

$this->drupalLogin($user2);
$this->drupalGet("node/$post2->nid/edit");

$fields = $this->xpath('//*[@id="edit-og-group-ref-und-0-default"]');
$this->assertEqual($fields[0]->option['value'], $group2->nid, '"Default" field mode is required.');
}

/**
* Test non-accessible group IDs are saved, upon form submit.
*/
function testHiddenGroupIds() {
$user1 = $this->drupalCreateUser(array('administer group', 'access content', 'create post content'));
$user2 = $this->drupalCreateUser(array('access content', 'create post content'));

// Create group nodes.
$settings = array(
'type' => 'group',
OG_GROUP_FIELD . '[und][0][value]' => 1,
);
$settings['uid'] = $user1->uid;
$group1 = $this->drupalCreateNode($settings);

$settings['uid'] = $user2->uid;
$group2 = $this->drupalCreateNode($settings);

$settings = array(
'type' => 'post',
);
$settings['uid'] = $user1->uid;
$post1 = $this->drupalCreateNode($settings);
og_group('node', $group1->nid, array('entity_type' => 'node', 'entity' => $post1));
og_group('node', $group2->nid, array('entity_type' => 'node', 'entity' => $post1));

$this->drupalLogin($user2);
$this->drupalPost("node/$post1->nid/edit", array(), 'Save');

// Assert post still belongs to both groups, although user was able
// to select only one.
$gids = og_get_entity_groups('node', $post1);
$this->assertEqual(count($gids['node']), 2, 'Hidden groups remained.');
}

/**
* Test a non "administer group" user with pending membership, re-saving
* user edit.
*/
function testUserEdit() {
$user1 = $this->drupalCreateUser();
$user2 = $this->drupalCreateUser();

$settings = array(
'type' => 'group',
OG_GROUP_FIELD . '[und][0][value]' => 1,
);
$settings['uid'] = $user1->uid;
$group1 = $this->drupalCreateNode($settings);

og_group('node', $group1->nid, array('entity' => $user2, 'state' => OG_STATE_PENDING));

$this->drupalLogin($user2);
$this->drupalPost("user/$user2->uid/edit", array(), 'Save');

$this->assertTrue(og_get_entity_groups('user', $user2, array(OG_STATE_PENDING)), 'User membership was retained after user save.');
}

/**
* Test multiple group-audience fields.
*/
function testMultipleFields() {
// Add another group-audience field.
$og_field = og_fields_info(OgGroupAudienceHelper::DEFAULT_FIELD);
og_create_field('another_field', 'node', 'post', $og_field);

$user1 = $this->drupalCreateUser();

// Create a group.
$settings = array(
'type' => 'group',
OG_GROUP_FIELD . '[und][0][value]' => 1,
'uid' => $user1->uid,
);
$group1 = $this->drupalCreateNode($settings);
$group2 = $this->drupalCreateNode($settings);

// Create group content.
$settings = array(
'type' => 'post',
'uid' => $user1->uid,
);
$post1 = $this->drupalCreateNode($settings);

og_group('node', $group1->nid, array('entity_type' => 'node', 'entity' => $post1, 'field_name' => OgGroupAudienceHelper::DEFAULT_FIELD));
og_group('node', $group2->nid, array('entity_type' => 'node', 'entity' => $post1, 'field_name' => 'another_field'));

$this->drupalLogin($user1);
$this->drupalGet("node/$post1->nid/edit");

// Assert correct selection in both fields.
$this->assertOptionSelected('edit-og-group-ref-und-0-default', $group1->nid);
$this->assertOptionSelected('edit-another-field-und-0-default', $group2->nid);
}
}

/**
* Test the revocation of group roles.
*/
Expand Down
Loading