Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
C
Core
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 935
    • Issues 935
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • Development
  • Core
  • Issues
  • #1898

Closed
Open
Opened Jul 22, 2020 by eileen@eileen🎱Owner

Test support for extensions

In CiviCRM core test class we have a function createLogggedInnser to emulated having a logged in user

When running extension tests a) this function is not available and b) the UFClass is Drupal not Tests - which causes problems running tests.

We have a function like this in our test class.

  /**
   * Emulate a logged in user since certain functions use that.
   * value to store a record in the DB (like activity)
   * CRM-8180
   *
   * @return int
   *   Contact ID of the created user.
   */
  public function imitateAdminUser() {
    $result = $this->callAPISuccess('UFMatch', 'get', array(
      'uf_id' => 1,
      'sequential' => 1,
    ));
    if (empty($result['id'])) {
      $contact = $this->callAPISuccess('Contact', 'create', array(
        'first_name' => 'Super',
        'last_name' => 'Duper',
        'contact_type' => 'Individual',
        'api.UFMatch.create' => array('uf_id' => 1, 'uf_name' => 'Wizard'),
      ));
      $contactID = $contact['id'];
    }
    else {
      $contactID = $result['values'][0]['contact_id'];
    }
    $session = CRM_Core_Session::singleton();
    $session->set('userID', $contactID);
    CRM_Core_Config::singleton()->userPermissionClass = new CRM_Core_Permission_UnitTests();
    CRM_Core_Config::singleton()->userPermissionClass->permissions = array(
      'edit all contacts',
      'Access CiviCRM',
      'Administer CiviCRM',
    );
    return $contactID;
  }

I wonder about either

  1. providing some civix support or
  2. adding a new test trait \Civi\Test\UserTrait with
  • createLoggedInUser
  • something like the above
  • move some of the stuff from the unavailable permission trait

ping @totten

Edited Jul 22, 2020 by eileen
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: dev/core#1898