Exemplo n.º 1
0
 /**
  * Creates the specified element.
  *
  * @Given /^the following "(?P<element_string>(?:[^"]|\\")*)" exist:$/
  *
  * @throws MaharaBehatTestException
  * @throws PendingException
  * @param string    $elementname The name of the entity to add
  * @param TableNode $data
  */
 public function the_following_exist($elementname, TableNode $data)
 {
     // Now that we need them require the data generators.
     require_once get_config('docroot') . '/testing/classes/generator/lib.php';
     if (empty(self::$elements[$elementname])) {
         throw new PendingException($elementname . ' data generator is not implemented');
     }
     $this->datagenerator = TestingUtil::get_data_generator();
     $elementdatagenerator = self::$elements[$elementname]['datagenerator'];
     $availablefields = self::$elements[$elementname]['available'];
     $requiredfields = self::$elements[$elementname]['required'];
     if (!empty(self::$elements[$elementname]['switchids'])) {
         $switchids = self::$elements[$elementname]['switchids'];
     }
     foreach ($data->getHash() as $elementdata) {
         // Normalise field values
         $this->normalise($elementdata);
         // Validate available fields for given element
         $this->validate_fields($availablefields, $elementdata);
         // Check if all the required fields are there.
         foreach ($requiredfields as $requiredfield) {
             if (!isset($elementdata[$requiredfield])) {
                 throw new MaharaBehatTestException($elementname . ' requires the field ' . $requiredfield . ' to be specified');
             }
         }
         // Preprocess the entities that requires a special treatment.
         if (method_exists($this, 'preprocess_' . $elementdatagenerator)) {
             $elementdata = $this->{'preprocess_' . $elementdatagenerator}($elementdata);
         }
         // Creates element.
         $methodname = 'create_' . $elementdatagenerator;
         if (method_exists($this->datagenerator, $methodname)) {
             // Using data generators directly.
             $this->datagenerator->{$methodname}($elementdata);
         } else {
             if (method_exists($this, 'process_' . $elementdatagenerator)) {
                 // Using an alternative to the direct data generator call.
                 $this->{'process_' . $elementdatagenerator}($elementdata);
             } else {
                 throw new PendingException($elementname . ' the create_ or process_ method is not implemented');
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Skip the original dataroot files to not been reset.
  *
  * @static
  * @param string $utilclassname the util class name..
  */
 protected static function skip_original_data_files($utilclassname)
 {
     $jsonfilepath = self::get_dataroot() . '/' . self::$originaldatafilesjson;
     if (file_exists($jsonfilepath)) {
         $listfiles = file_get_contents($jsonfilepath);
         // Mark each files as to not be reset.
         if (!empty($listfiles) && !self::$originaldatafilesjsonadded) {
             $originaldatarootfiles = json_decode($listfiles);
             // Keep the json file. Only drop_dataroot() should delete it.
             $originaldatarootfiles[] = self::$originaldatafilesjson;
             $utilclassname::$datarootskiponreset = array_merge($utilclassname::$datarootskiponreset, $originaldatarootfiles);
             self::$originaldatafilesjsonadded = true;
         }
     }
 }