You are here

protected function AbstractOpignoTestCase::createOGContent in Opigno 7.0

File

tests/AbstractOpignoTestCase.inc, line 111
Defines the base class for Opigno unit testing. This base class contains re-usable logic that will make it easier and faster to write Opigno-specific unit tests. This class will also configure all modules to work correctly for Opigno.

Class

AbstractOpignoTestCase
@file Defines the base class for Opigno unit testing. This base class contains re-usable logic that will make it easier and faster to write Opigno-specific unit tests. This class will also configure all modules to work correctly for Opigno.

Code

protected function createOGContent($type, $gid, $user = NULL, $edit = array()) {
  if (!isset($user)) {
    $user = $this->admin_user;
  }

  // Login the node author
  $this
    ->drupalLogin($user);

  // Set the form fields
  $base = array(
    'title' => $this
      ->randomName(8),
    'body[und][0][value]' => $this
      ->randomName(16),
    'group_audience[und][]' => $gid,
  );
  $edit = $base + $edit;
  $this
    ->drupalGet('node/add/' . str_replace('_', '-', $type));

  // Add node
  $this
    ->drupalPost($this
    ->getURL(), $edit, 'Save');

  // Get new node nid
  $matches = array();
  if (preg_match_all('/node\\/([0-9]+)/', $this
    ->getURL(), $matches)) {
    $nid = $matches[1];

    // Return nid
    return $nid;
  }
  else {
    $this
      ->assertTrue(FALSE, 'Could not find the new node nid in the URL.');
    return 0;
  }
}