/**
  * Tests and ensures processors run correctly
  * 
  * @param array $properties
  * @param boolean $success
  * @param string $message
  * @param array $object
  * @dataProvider providerRun
  * @depends testSetProperties
  * @depends testSetPath
  */
 public function testRun(array $properties, $success = true, $message = '', $object = array())
 {
     $this->processor->setPath(MODX_BASE_PATH . self::MODX_TEST_PROCESSOR);
     $this->processor->setProperties($properties);
     /** @var modProcessorResponse $response */
     $response = $this->processor->run();
     $this->assertInstanceOf('modProcessorResponse', $response);
     $this->assertEquals($success, $response->response['success'], 'modProcessor->run did not return the proper response type: ' . ($success ? 'success' : 'failure'));
     if (!empty($message)) {
         $this->assertEquals($message, $response->response['message'], 'modProcessor->run did not return the proper response message.');
     }
     if (!empty($object)) {
         $this->assertEquals($object, $response->response['object'], 'modProcessor->run did not return the proper response object.');
     }
 }
Exemple #2
0
 /**
  * Loads and runs a specific processor.
  *
  * @param string $action The processor to run, eg: context/update
  * @param array $scriptProperties Optional. An array of parameters to pass to the processor.
  * @param array $options Optional. An array of options for running the processor, such as:
  *
  * - processors_path - If specified, will override the default MODX processors path.
  * - location - A prefix to load processor files from, will prepend to the action parameter
  * (Note: location will be deprecated in future Revolution versions.)
  *
  * @return mixed The result of the processor.
  */
 public function runProcessor($action = '', $scriptProperties = array(), $options = array())
 {
     if (!$this->loadClass('modProcessor', '', false, true)) {
         $this->log(modX::LOG_LEVEL_ERROR, 'Could not load modProcessor class.');
         return false;
     }
     $result = null;
     /* backwards compat for $options['action']
      * @deprecated Removing in 2.2
      */
     if (empty($action)) {
         if (!empty($options['action'])) {
             $action = $options['action'];
         } else {
             return $result;
         }
     }
     /* calculate processor file path from options and action */
     $processorFile = isset($options['processors_path']) && !empty($options['processors_path']) ? $options['processors_path'] : $this->config['processors_path'];
     if (isset($options['location']) && !empty($options['location'])) {
         $processorFile .= ltrim($options['location'], '/') . '/';
     }
     $processorFile .= ltrim(str_replace('../', '', $action . '.php'), '/');
     if (file_exists($processorFile)) {
         if (!isset($this->lexicon)) {
             $this->getService('lexicon', 'modLexicon');
         }
         if (!isset($this->error)) {
             $this->request->loadErrorHandler();
         }
         $processor = new modProcessor($this);
         $processor->setPath($processorFile);
         $processor->setProperties($scriptProperties);
         $response = $processor->run();
     } else {
         $this->log(modX::LOG_LEVEL_ERROR, "Processor {$processorFile} does not exist; " . print_r($options, true));
     }
     return $response;
 }