function OgVocabComplexWidgetTestCase::setUp in OG Vocabulary 7
Sets up a Drupal site for running functional and integration tests.
Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.
After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.
Parameters
...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.
Overrides DrupalWebTestCase::setUp
See also
DrupalWebTestCase::prepareDatabasePrefix()
DrupalWebTestCase::changeDatabasePrefix()
DrupalWebTestCase::prepareEnvironment()
File
- ./
og_vocab.test, line 110 - Test organic groups vocabulary module.
Class
Code
function setUp() {
parent::setUp('og_vocab');
// Add OG group field sto article node.
og_create_field(OG_GROUP_FIELD, 'node', 'article');
$this
->drupalCreateContentType(array(
'type' => 'post',
));
og_create_field(OG_AUDIENCE_FIELD, 'node', 'post');
og_create_field(OG_VOCAB_FIELD, 'node', 'post');
// Create two users.
$user1 = $this
->drupalCreateUser(array(
'access content',
'create post content',
));
$user2 = $this
->drupalCreateUser();
// Array key with the node ID (to be created) and the user ID as the
// value.
$info = array(
// Groups owned by user1.
1 => $user1->uid,
2 => $user1->uid,
// Group owned by user2.
3 => $user2->uid,
);
$settings = array();
$settings['type'] = 'article';
$settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
foreach ($info as $uid) {
$settings['uid'] = $uid;
$node = $this
->drupalCreateNode($settings);
}
// Array keyed by a serial ID and the value is array with node ID of
// the group and the settings to pass to og_vocab_create_og_vocab().
$info = array(
1 => array(
'nid' => 1,
'settings' => array(
'required' => TRUE,
),
),
2 => array(
'nid' => 1,
'settings' => array(
'cardinality' => 1,
),
),
3 => array(
'nid' => 2,
'settings' => array(
'widget_type' => 'entityreference_autocomplete',
),
),
4 => array(
'nid' => 3,
'settings' => array(),
),
);
$og_vocabs = array();
foreach ($info as $id => $value) {
// Create a terms vocabulary and relate them to the groups.
$vocabulary = new stdClass();
$vocabulary->name = "Vocabulary {$id}";
$vocabulary->machine_name = "vocabulary_{$id}";
taxonomy_vocabulary_save($vocabulary);
// Relate vocabulary to group.
og_vocab_relation_save($vocabulary->vid, 'node', $value['nid']);
// Create OG-vocab entity.
$og_vocab = og_vocab_create_og_vocab($vocabulary->vid, 'node', 'post', OG_VOCAB_FIELD, $value['settings']);
$og_vocab
->save();
$og_vocabs[$vocabulary->vid] = $og_vocab;
// Create terms in the vocabulary.
for ($i = 1; $i < 3; ++$i) {
$term = new stdClass();
$term->name = "Vocab {$vocabulary->vid} term {$i}";
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
}
$this
->drupalLogin($user1);
$this->user1 = $user1;
}
}