public function testExecuteOperation()
 {
     $operationManager = new tx_caretakerinstance_OperationManager();
     $operation = $this->getMock('tx_caretakerinstance_IOperation', array('execute'));
     $operation->expects($this->once())->method('execute')->with($this->equalTo(array('foo' => 'bar')))->will($this->returnValue(new tx_caretakerinstance_OperationResult(true, 'bar')));
     $operationManager->registerOperation('mock', $operation);
     $result = $operationManager->executeOperation('mock', array('foo' => 'bar'));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('bar', $result->getValue());
 }
 /**
  * Execute a Command Request (which consists of multiple Operation keys and parameters).
  *
  * The Command Request is validated, decoded and then executed.
  *
  * @param tx_caretakerinstance_CommandRequest $commandRequest
  * @return tx_caretakerinstance_CommandResult The command result object
  */
 public function executeCommand(tx_caretakerinstance_CommandRequest $commandRequest)
 {
     if ($this->securityManager->validateRequest($commandRequest)) {
         if ($this->securityManager->decodeRequest($commandRequest)) {
             $operations = $commandRequest->getData('operations');
             $results = array();
             foreach ($operations as $operation) {
                 $results[] = $this->operationManager->executeOperation($operation[0], $operation[1]);
             }
             return new tx_caretakerinstance_CommandResult(tx_caretakerinstance_CommandResult::status_ok, $results);
         } else {
             return new tx_caretakerinstance_CommandResult(tx_caretakerinstance_CommandResult::status_error, NULL, 'The request could not be decrypted');
         }
     } else {
         return new tx_caretakerinstance_CommandResult(tx_caretakerinstance_CommandResult::status_error, NULL, 'The request could not be certified');
     }
 }
 /**
  * @return tx_caretakerinstance_OperationManager
  */
 public function getOperationManager()
 {
     if ($this->operationManager == null) {
         $this->operationManager = new tx_caretakerinstance_OperationManager();
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['caretaker_instance']['operations'])) {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['caretaker_instance']['operations'] as $key => $operationRef) {
                 if (is_string($operationRef)) {
                     $operation = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($operationRef);
                 } elseif ($operationRef instanceof tx_caretakerinstance_IOperation) {
                     $operation = $operationRef;
                 } else {
                     // TODO log error if some strange value is registered
                 }
                 $this->operationManager->registerOperation($key, $operation);
             }
         }
     }
     return $this->operationManager;
 }