You are here

public function FieldablePanelsPanesSubContext::cleanFPPs in Panopoly 7

Cleans up FPPs.

@AfterScenario @api

File

modules/panopoly/panopoly_test/behat/steps/panopoly_test_fpp.behat.inc, line 96
Provide Behat step-definitions for Fieldable Panels Panes.

Class

FieldablePanelsPanesSubContext

Code

public function cleanFPPs($event) {
  $fpids = array();

  // Get UIDs of users created during this scenario.
  $uids = $this
    ->getUIDs();
  if (!empty($uids)) {

    // Find any FPPs created by the test users.
    // First, get a list of FPPs with their first revision VID.
    $fpp_vids = db_query('SELECT min(vid) AS vid FROM {fieldable_panels_panes_revision} GROUP BY fpid')
      ->fetchAll();
    $vids = array();
    if (!empty($fpp_vids)) {
      foreach ($fpp_vids as $vid) {
        $vids[] = $vid->vid;
      }

      // Then, check whether that first revision was created by a current test user.
      $fpp_fpids = db_query('SELECT fpid FROM {fieldable_panels_panes_revision} WHERE vid IN (:vids) AND uid IN (:uids)', array(
        ':uids' => $uids,
        ':vids' => $vids,
      ))
        ->fetchAll();
      if (!empty($fpp_fpids)) {
        foreach ($fpp_fpids as $fpid) {
          $fpids[] = $fpid->fpid;
        }
      }
    }

    // Add FPPs created by users to the $fpps variable.
    $fpids = array_unique($fpids);
  }

  // Delete any fieldable panels panes that were created by test users or a Given step.
  foreach ($fpids as $fpid) {
    fieldable_panels_panes_delete($fpid);
  }

  // Clear out the list.
  $this->external_users = array();
}