/**
  * Test basic usage of the command tester
  *
  * @return void
  * @author Dan Cox
  */
 public function test_basic()
 {
     $this->CT->execute('utility:main');
     $this->assertContains('The main action', $this->CT->getOutput());
     $this->assertInstanceOf('\\Danzabar\\CLI\\Application', $this->CT->getApplication());
     $this->assertInstanceOf('\\UtilityTask', $this->CT->getTask());
 }
Exemple #2
0
 /**
  * Executes an SQL statement
  * @param type $sql SQL query to execute
  * @param type $params params for the query
  */
 public function query($sql, $params = null)
 {
     if (isset($this->cfg->prefix)) {
         $sql = str_replace('#__', $this->cfg->prefix, $sql);
     }
     $this->stmt = $this->instance->prepare($sql);
     $this->stmt->execute($params);
     $this->checkQuery();
 }
 /**
  * Test the help list format is correct
  *
  * @return void
  * @author Dan Cox
  */
 public function test_helpFormat()
 {
     $this->CT->execute();
     // Application Detail Assertions
     $this->assertContains('Test CLI', $this->CT->getOutput());
     $this->assertContains('version 1.0.0', $this->CT->getOutput());
     // Random detail assertions
     $this->assertContains('Help', $this->CT->getOutput());
     $this->assertContains('Fake', $this->CT->getOutput());
     $this->assertContains('confirmation', $this->CT->getOutput());
     // Instruction Assertions
     $this->assertContains('php [file] [command] [arguments] [options]', $this->CT->getOutput());
     // Example commands Assertions
     $this->assertContains('php [file] fake [params]', $this->CT->getOutput());
     $this->assertContains('php [file] fake:askMe [params]', $this->CT->getOutput());
 }
 /**
  * Exectutes a statement and calls the get_result method.
  *
  * @param Object $stmt : MySQLI query to be executed
  **/
 function process($stmt)
 {
     if (!$stmt->execute()) {
         echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
     }
     return $this->get_result($stmt);
 }
Exemple #5
0
 /**
  * Test the table drawing functionality.
  *
  * @return void
  * @author Dan Cox
  */
 public function test_table()
 {
     $this->CT->execute('utility:table');
     $this->assertContains('Header1', $this->CT->getOutput());
     $this->assertContains('Header2', $this->CT->getOutput());
 }
 /**
  * Test the acceptance of the explicit confirmation
  *
  * @return void
  * @author Dan Cox
  */
 public function test_acceptedExplicitConfirmation()
 {
     $this->CT->setInput("yes\n");
     $this->CT->execute('fake:explicitConfirm');
     $this->assertContains("Confirmed", $this->CT->getOutput());
 }
Exemple #7
0
 /**
  * Store uploaded file to cache folder,
  * fully manage error messages and ask for database insert
  * 
  * @access public
  * @return boolean 
  */
 public function import()
 {
     // Get file info
     $file = $this->app->input->files->get('datasourceimport');
     $tmpFile = $file['tmp_name'];
     $tmpFileName = $file['name'];
     try {
         if (!$tmpFile || !$tmpFileName) {
             throw new JMapException(JText::_('COM_JMAP_NOFILE_SELECTED'), 'error');
         }
         $tmpFileSize = $file['size'];
         $allowedFileSize = 2 * 1024 * 1024;
         // MB->Bytes
         if ($tmpFileSize > $allowedFileSize) {
             throw new JMapException(JText::_('COM_JMAP_SIZE_ERROR') . ' Max 2MB.', 'error');
         }
         $tmpFileExtension = @array_pop(explode('.', $tmpFileName));
         if ($tmpFileExtension != 'json') {
             throw new JMapException(JText::_('COM_JMAP_EXT_ERROR'), 'error');
         }
         // Deserialize contents
         $fileContents = file_get_contents($tmpFile);
         if ($fileContents) {
             $objectToRestore = json_decode($fileContents);
         }
         if (!is_array($objectToRestore)) {
             throw new JMapException(JText::_('COM_JMAP_INVALID_IMPORT_DATA'), 'error');
         }
         // Prepare the values array
         $dbQueryArray = array();
         foreach ($objectToRestore as $dataSource) {
             // Check if the data source is of type plugin and if the plugin is installed, otherwise skip and warn user
             if ($dataSource->type == 'plugin' && !JFolder::exists(JPATH_COMPONENT_ADMINISTRATOR . '/plugins/' . strtolower($dataSource->name))) {
                 $this->app->enqueueMessage(JText::sprintf('COM_JMAP_NOPLUGIN_INSTALLED_IMPORTED_DATASOURCE', $dataSource->name));
                 continue;
             }
             $dbSourceArray = array();
             $dbSourceArray[] = $this->dbo->quote($dataSource->type);
             $dbSourceArray[] = $this->dbo->quote(strip_tags($dataSource->name));
             $dbSourceArray[] = $this->dbo->quote(strip_tags($dataSource->description));
             $dbSourceArray[] = (int) $dataSource->published;
             $dbSourceArray[] = $this->dbo->quote($dataSource->sqlquery);
             $dbSourceArray[] = $this->dbo->quote($dataSource->sqlquery_managed);
             $dbSourceArray[] = $this->dbo->quote($dataSource->params);
             // Source imploded assignment
             $dbQueryArray[] = implode(',', $dbSourceArray);
         }
         // Check if some valid data to import are available
         if (!count($dbQueryArray)) {
             throw new JMapException(JText::_('COM_JMAP_NO_IMPORT_DATA_FOUND'), 'warning');
         }
         // Final sources imploded assignment
         $implodedSources = '(' . implode('),(', $dbQueryArray) . ')';
         $queryImport = "INSERT INTO" . $this->dbo->quoteName('#__jmap') . "\n (" . "\n" . $this->dbo->quoteName('type') . "," . "\n" . $this->dbo->quoteName('name') . "," . "\n" . $this->dbo->quoteName('description') . "," . "\n" . $this->dbo->quoteName('published') . "," . "\n" . $this->dbo->quoteName('sqlquery') . "," . "\n" . $this->dbo->quoteName('sqlquery_managed') . "," . "\n" . $this->dbo->quoteName('params') . ")" . "\n VALUES " . $implodedSources;
         $this->dbo->setQuery($queryImport);
         $this->dbo->execute();
         if ($this->dbo->getErrorNum()) {
             throw new JMapException(JText::sprintf('COM_JMAP_DBERROR_IMPORT_DATA', $this->dbo->getErrorMsg()), 'error');
         }
     } catch (JMapException $e) {
         $this->setError($e);
         return false;
     } catch (Exception $e) {
         $jmapException = new JMapException($e->getMessage(), 'error');
         $this->setError($jmapException);
         return false;
     }
     return true;
 }
 /**
  * Test that an exception is thrown on a mulitple choice question
  *
  * @return void
  * @author Dan Cox
  */
 public function test_exceptionOnFalseMultipleChoiceAnswers()
 {
     $this->CT->setInput("answer, fake\n");
     $this->CT->execute("fake:multiChoice");
     $this->assertContains("The answer you selected is invalid", $this->CT->getOutput());
 }
 /**
  * Runs the purge method on loaded fixtures
  *
  * @return void
  * @author Dan Cox
  */
 public function purge()
 {
     $this->executor->execute($this->loader, new ChainFilter(), Executor::PURGE);
 }
 /**
  * Same as above but a fail
  *
  * @return void
  * @author Dan Cox
  */
 public function test_intOptionFail()
 {
     $this->setExpectedException('Danzabar\\CLI\\Input\\Exceptions\\ValidationFailException');
     $this->CT->execute('Input:intTest', array('int' => 'skjkd'));
 }