Ejemplo n.º 1
0
 public function testSimple()
 {
     $config = TestConfig::getConfig();
     $service_url = $config['server']['baseurl'] . '/version';
     $curl = curl_init($service_url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xml"));
     $curl_response = curl_exec($curl);
     $headers = curl_getinfo($curl);
     curl_close($curl);
     // check if http code fits
     if ($headers["http_code"] != 200) {
         $this->fail("Response has the wrong http code : " . $headers["http_code"] . "\n\n" . print_r($headers, true) . "\n\n" . $curl_response);
     }
     // parse xml result
     try {
         $xml = new SimpleXMLElement($curl_response);
     } catch (Exception $e) {
         $this->fail("An exception has been raised: " . $e->getMessage() . "\n\n" . $e->getTraceAsString());
     }
     $versionAttributes = array();
     foreach ($xml->version[0]->attributes() as $name => $value) {
         $versionAttributes[$name] = $value;
         // test if all values are numbers
         $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_NUMERIC, (string) $value, "Type of Attribute is wrong.");
     }
     $mandatoryAttributes = array("major", "minor", "revision");
     foreach ($mandatoryAttributes as $key => $value) {
         // test if all attributes are included
         $this->assertArrayHasKey($value, $versionAttributes, "Attribute missing in result: \n\n" . $curl_response);
     }
 }
Ejemplo n.º 2
0
 private function tryToTest(AcceptanceGuy $I)
 {
     // need a copy of test folder
     FileSystemTools::copyRecursive(TestConfig::getConfig('testPath'), $this->tmpStaging);
     $I->runShellCommand(TestConfig::getConfig('testRunnerPath') . DS . 'runtests.bat testStagingPath:' . $this->tmpStaging);
     $I->seeInShellOutput('Codeception PHP Testing Framework');
     //$I->seeInShellOutput('PhantomJS server stopped');
 }
Ejemplo n.º 3
0
 protected function getConnection()
 {
     $testconfig = TestConfig::getConfig();
     $dbname = $testconfig["database"]["dbname"];
     $dbhost = $testconfig["database"]["dbhost"];
     $dbport = $testconfig["database"]["dbport"];
     $dbuser = $testconfig["database"]["dbuser"];
     $dbpassword = $testconfig["database"]["dbpassword"];
     $pdo = new PDO("pgsql:dbname={$dbname};host={$dbhost};port={$dbport}", $dbuser, $dbpassword, array(PDO::ATTR_PERSISTENT => true));
     return $this->createDefaultDBConnection($pdo, $dbname);
 }
Ejemplo n.º 4
0
 public static function getRemoteTestFiles()
 {
     $config = TestConfig::getConfig();
     $file_urls = $config['testaddurl'];
     $testfilesremote = array();
     foreach ($file_urls as $ext_key => $url) {
         $testfilesremote[] = array($url, $ext_key, "");
         $testfilesremote[] = array($url, $ext_key . "-C", "C");
     }
     return $testfilesremote;
 }
Ejemplo n.º 5
0
 public function testSimple()
 {
     $config = TestConfig::getConfig();
     $service_url = $config['server']['baseurl'] . '/version';
     $curl = curl_init($service_url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xmlx"));
     $curl_response = curl_exec($curl);
     $headers = curl_getinfo($curl);
     curl_close($curl);
     $xml = SmintTestUtils::validateXMLResponse($headers, $curl_response, "406", array("error"), array("code"), $this);
     $errorAttributes = array();
     foreach ($xml->error[0]->attributes() as $name => $value) {
         $versionAttributes[$name] = $value;
         // test if all values are numbers
         $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_NUMERIC, (string) $value, "Type of ErrorCode is wrong.");
     }
 }
Ejemplo n.º 6
0
 private function myQueryTest($trackid)
 {
     $config = TestConfig::getConfig();
     $service_url = $config['server']['baseurl'] . '/track_external_key/';
     $curl = curl_init($service_url . $trackid);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xml"));
     $curl_response = curl_exec($curl);
     $headers = curl_getinfo($curl);
     curl_close($curl);
     if ($curl_response == true) {
         $xml = SmintTestUtils::validateXMLResponse($headers, $curl_response, "404", array("error", "errorDetail"), array("code"), $this);
     } else {
         echo __METHOD__ . "\n";
         echo "curl_response:" . $curl_response . "\n";
         print_r($headers);
         $this->fail("There was a problem accessing the api! \n\n");
     }
 }
Ejemplo n.º 7
0
 private function myQueryTest($trackextkey, $collectionname = null, $expectedHTTPStatus = "200", $expectedXMLElements, $expectedXMLAttributes)
 {
     $config = TestConfig::getConfig();
     $service_url = $config['server']['baseurl'] . '/track_external_key/';
     $url = $service_url . $trackextkey;
     if (!is_null($collectionname)) {
         $url = $url . "?collection=" . urlencode($collectionname);
     }
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xml"));
     $curl_response = curl_exec($curl);
     $headers = curl_getinfo($curl);
     curl_close($curl);
     if ($curl_response == true) {
         $xml = SmintTestUtils::validateXMLResponse($headers, $curl_response, $expectedHTTPStatus, $expectedXMLElements, $expectedXMLAttributes, $this);
     } else {
         echo __METHOD__ . "\n";
         echo "curl_response:" . $curl_response . "\n";
         print_r($headers);
         $this->fail("There was a problem accessing the api! \n\n");
     }
 }
Ejemplo n.º 8
0
 echo 'RUN TESTS ' . $folder;
 ob_start();
 $testResult = TestRunner::runTests($folder);
 $testOutput = ob_get_contents();
 ob_end_clean();
 if (!$testResult['result']) {
     $passedAllTests = false;
     $output[] = "TEST FAILED";
 } else {
     $output[] = "TEST PASSED";
 }
 $output[] = $testOutput;
 //$output=array_merge($output,$testResult['output']);
 // CHECK PHP LOG FILE
 if (!empty(TestConfig::getConfig('testLogFiles'))) {
     foreach (explode(",", TestConfig::getConfig('testLogFiles')) as $k => $logFile) {
         $lines = FileSystemTools::checkChangesToFile($snapshots[$logFile], $logFile);
         if (count($lines) > 0) {
             $output[] = "-------------------------------------------------";
             $output[] = 'LOG FILE ' . $logFile;
             $output[] = "-------------------------------------------------";
             $output = array_merge($output, $lines);
             $output[] = "-------------------------------------------------";
         }
     }
 }
 if (php_sapi_name() == 'cli') {
     echo "\n" . implode("\n", $output) . "\n";
     $output = array();
 }
 // $output=array_merge($output,
Ejemplo n.º 9
0
 static function runTests($testFolder)
 {
     $output = [];
     // clean staging
     $cmds = array();
     $staging = TestConfig::getConfig('testStagingPath');
     //FileSystemTools::setPermissionsAllowEveryone($staging);
     //FileSystemTools::setPermissionsAllowEveryone(TestConfig::getConfig('testOutputPath'));
     $passedAllTests = true;
     // some sanity checking before pruning
     if (strlen(trim($staging)) > 0) {
         // clean up staging
         FileSystemTools::prune($staging);
         //return array();
         // create staging location
         @mkdir($staging . DS . 'tests', 0777, true);
         @mkdir($staging . DS . 'tests' . DS . '_support', 0777, true);
         // copy shared test support files
         FileSystemTools::copyRecursive(TestConfig::getConfig('testSharedSupportPath'), $staging . DS . 'tests' . DS . '_support');
         //return array();
         // then copy over the top, test suites etc to staging
         FileSystemTools::copyRecursive($testFolder, $staging . DS . 'tests');
         // ensure required test directories
         @mkdir($staging . DS . 'tests' . DS . '_support', 0777, true);
         @mkdir($staging . DS . 'tests' . DS . '_output', 0777, true);
         @mkdir($staging . DS . 'tests' . DS . '_data', 0777, true);
         @mkdir($staging . DS . 'tests' . DS . '_support' . DS . 'Helper', 0777, true);
         TestConfig::writeCodeceptionConfig();
         $objects = glob($staging . DS . 'tests' . DS . '*.suite.yml');
         if (sizeof($objects) > 0) {
             foreach ($objects as $file) {
                 if ($file == "." || $file == "..") {
                     continue;
                 }
                 TestConfig::writeWebDriverConfig($file);
             }
         }
         // cm5?
         if (strlen(trim(TestConfig::getConfig('cmFivePath'))) > 0) {
             // copy installer sql to test data directory
             copy(TestConfig::getConfig('cmFivePath') . DS . 'cache' . DS . 'install.sql', $staging . DS . 'tests' . DS . '_data' . DS . 'dump.sql');
             // copy c3.php for accptance test coverage
             if (TestConfig::getConfig('coverage')) {
                 copy(TestConfig::getConfig('testRunnerPath') . DS . 'src' . DS . 'lib' . DS . 'c3.php', TestConfig::getConfig('testRunnerPath') . DS . 'staging' . DS . 'c3.php');
             }
         }
         // build and run
         array_push($cmds, array('CODECEPTION BUILD', TestConfig::getConfig('codeception') . ' build ' . ' -c ' . $staging));
         $testParam = TestConfig::getConfig('testSuite');
         $testParam .= strlen(trim(TestConfig::getConfig('testSuite'))) > 0 ? ' ' . TestConfig::getConfig('test') : '';
         // these options conflict with coverage options below so only one set
         $coverage = ' -d --no-colors --steps ';
         if (TestConfig::getConfig('coverage')) {
             //--coverage-xml
             $coverage = ' --coverage --xml --html --coverage-html   --report ';
         }
         array_push($cmds, array('CODECEPTION RUN', TestConfig::getConfig('codeception') . ' run ' . $coverage . ' -c ' . $staging . ' ' . $testParam));
         foreach ($cmds as $cmd) {
             if (php_sapi_name() == 'cli') {
                 echo "-------------------------------------------------\n";
                 echo $cmd[0] . "\n";
                 echo $cmd[1] . "\n";
                 echo "-------------------------------------------------\n";
             } else {
                 $output[] = "-------------------------------------------------";
                 $output[] = $cmd[0];
                 $output[] = $cmd[1];
                 $output[] = "-------------------------------------------------";
             }
             $handle = popen($cmd[1], "r");
             $detailsTest = '';
             $errorActive = false;
             $testType = '';
             while (!feof($handle)) {
                 $buffer = fgets($handle);
                 //$buffer = trim(htmlspecialchars($buffer));
                 if (php_sapi_name() == 'cli') {
                     echo $buffer;
                 } else {
                     $output[] = trim($buffer);
                 }
             }
             $exitCode = pclose($handle);
             if ($exitCode > 0) {
                 $passedAllTests = false;
             }
         }
         // save output files
         $testSuiteName = str_replace(':', '_', str_replace(DS, '_', $testFolder));
         @mkdir(TestConfig::getConfig('testOutputPath') . DS . $testSuiteName);
         $output[] = "COPY test results from " . $staging . DS . 'tests' . DS . '_output' . " to " . TestConfig::getConfig('testOutputPath') . DS . $testSuiteName;
         FileSystemTools::copyRecursive($staging . DS . 'tests' . DS . '_output', TestConfig::getConfig('testOutputPath') . DS . $testSuiteName);
     }
     // clean up
     if (strlen(trim(TestConfig::getConfig('testRunnerPath'))) > 0 && file_exists(TestConfig::getConfig("testRunnerPath") . "/staging/c3.php")) {
         //unlink(TestConfig::getConfig("testRunnerPath")."/staging/c3.php");
     }
     //FileSystemTools::setPermissionsAllowEveryone($staging);
     //FileSystemTools::setPermissionsAllowEveryone(TestConfig::getConfig('testOutputPath'));
     return array('output' => $output, 'result' => $passedAllTests);
 }
Ejemplo n.º 10
0
 static function writeWebDriverConfig($configFile)
 {
     // write webdriver parameters
     $data = Yaml::parse(file_get_contents($configFile));
     // PROBLEM IN IF STATEMENT BELOW CHECKING FOR WEBDRIVER WHICH IS ACTUALLY A KEY ONE LEVEL DEEPER INSIDE ONE OF?? NUMERIC KEYS
     if (is_array($data) && array_key_exists('modules', $data) && array_key_exists('enabled', $data['modules'])) {
         // && is_array($data['modules']['enabled']['WebDriver']
         foreach ($data['modules']['enabled'] as $k => $moduleName) {
             if (is_array($moduleName) && array_key_exists('WebDriver', $moduleName)) {
                 $data['modules']['enabled'][$k]['WebDriver']['url'] = strlen(trim(TestConfig::getConfig('testUrl'))) > 0 ? TestConfig::getConfig('testUrl') : 'http://localhost';
                 $data['modules']['enabled'][$k]['WebDriver']['browser'] = 'firefox';
                 $data['modules']['enabled'][$k]['WebDriver']['host'] = 'localhost';
                 $data['modules']['enabled'][$k]['WebDriver']['wait'] = '1';
                 $yaml = Yaml::dump($data);
                 file_put_contents($configFile, $yaml);
                 break;
             }
         }
     }
 }
Ejemplo n.º 11
0
 protected function setUp()
 {
     $this->config = TestConfig::getConfig();
     $this->testfilesremote = TestConfig::getRemoteTestFiles();
     $this->testfileslocal = TestConfig::getLocalTestFiles();
 }
Ejemplo n.º 12
0
 protected function setUp()
 {
     $this->config = TestConfig::getConfig();
     $this->service_url = $this->config['server']['baseurl'] . '/track/delete/';
 }