public static function suite() { require 'ampoliros.php'; $suite = new TestSuite('Ampoliros'); $suite->addTest(AllAmpolirosCoreTests::suite()); $suite->addTest(AllAmpolirosDatatransferTests::suite()); return $suite; }
{ /* put any common endup here */ } function testGoogleLogFilesExist() { $Glog = new GoogleLog(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG, L_ALL, false); $this->assertEquals($Glog->logLevel, L_ALL, "This Should Pass"); } function testGoogleLogError() { $Glog = new GoogleLog(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG, L_ERR, false); $this->assert($Glog->LogError("error")); } function testGoogleLogRequest() { $Glog = new GoogleLog(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG, L_RQST, false); $this->assert($Glog->LogRequest("request")); } function testGoogleLogResponse() { $Glog = new GoogleLog(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG, L_RESP, false); $this->assert($Glog->LogResponse("response")); } } if (!isset($suite)) { $suite = new TestSuite(); } $suite->addTest(new TestGoogleLog("testGoogleLogFilesExist")); $suite->addTest(new TestGoogleLog("testGoogleLogError")); $suite->addTest(new TestGoogleLog("testGoogleLogRequest")); $suite->addTest(new TestGoogleLog("testGoogleLogResponse"));
/** * Runs suite * * @param string[] args * @return int exitcode */ public function run(array $args) { if (!$args) { return $this->usage(); } // Setup suite $suite = new TestSuite(); // Parse arguments $sources = new Vector(); $listener = TestListeners::$DEFAULT; $coverage = NULL; $arguments = array(); $colors = NULL; $cmap = array('' => NULL, '=on' => TRUE, '=off' => FALSE, '=auto' => NULL); try { for ($i = 0, $s = sizeof($args); $i < $s; $i++) { if ('-v' == $args[$i]) { $listener = TestListeners::$VERBOSE; } else { if ('-q' == $args[$i]) { $listener = TestListeners::$QUIET; } else { if ('-c' == $args[$i]) { $coverage = new CoverageListener(); foreach (explode(PATH_SEPARATOR, $this->arg($args, ++$i, 'c')) as $path) { $coverage->registerPath($path); } } else { if ('-cp' == $args[$i]) { foreach (explode(PATH_SEPARATOR, $this->arg($args, ++$i, 'cp')) as $element) { ClassLoader::registerPath($element, NULL); } } else { if ('-e' == $args[$i]) { $sources->add(new xp·unittest·sources·EvaluationSource($this->arg($args, ++$i, 'e'))); } else { if ('-l' == $args[$i]) { $arg = $this->arg($args, ++$i, 'l'); $class = XPClass::forName(strstr($arg, '.') ? $arg : 'xp.unittest.' . ucfirst($arg) . 'Listener'); $arg = $this->arg($args, ++$i, 'l'); if ('-?' == $arg || '--help' == $arg) { return $this->listenerUsage($class); } $output = $this->streamWriter($arg); $instance = $suite->addListener($class->newInstance($output)); // Get all @arg-annotated methods $options = array(); foreach ($class->getMethods() as $method) { if ($method->hasAnnotation('arg')) { $arg = $method->getAnnotation('arg'); if (isset($arg['position'])) { $options[$arg['position']] = $method; } else { $name = isset($arg['name']) ? $arg['name'] : strtolower(preg_replace('/^set/', '', $method->getName())); $short = isset($arg['short']) ? $arg['short'] : $name[0]; $options[$name] = $options[$short] = $method; } } } $option = 0; } else { if ('-o' == $args[$i]) { if (isset($options[$option])) { $name = '#' . ($option + 1); $method = $options[$option]; } else { $name = $this->arg($args, ++$i, 'o'); if (!isset($options[$name])) { $this->err->writeLine('*** Unknown listener argument ' . $name . ' to ' . $instance->getClassName()); return 2; } $method = $options[$name]; } $option++; if (0 == $method->numParameters()) { $pass = array(); } else { $pass = $this->arg($args, ++$i, 'o ' . $name); } try { $method->invoke($instance, $pass); } catch (TargetInvocationException $e) { $this->err->writeLine('*** Error for argument ' . $name . ' to ' . $instance->getClassName() . ': ' . $e->getCause()->toString()); return 2; } } else { if ('-?' == $args[$i] || '--help' == $args[$i]) { return $this->usage(); } else { if ('-a' == $args[$i]) { $arguments[] = $this->arg($args, ++$i, 'a'); } else { if ('--color' == substr($args[$i], 0, 7)) { $remainder = (string) substr($args[$i], 7); if (!array_key_exists($remainder, $cmap)) { throw new IllegalArgumentException('Unsupported argument for --color (must be <empty>, "on", "off", "auto" (default))'); } $colors = $cmap[$remainder]; } else { if (strstr($args[$i], '.ini')) { $sources->add(new xp·unittest·sources·PropertySource(new Properties($args[$i]))); } else { if (strstr($args[$i], xp::CLASS_FILE_EXT)) { $sources->add(new xp·unittest·sources·ClassFileSource(new File($args[$i]))); } else { if (strstr($args[$i], '.**')) { $sources->add(new xp·unittest·sources·PackageSource(Package::forName(substr($args[$i], 0, -3)), TRUE)); } else { if (strstr($args[$i], '.*')) { $sources->add(new xp·unittest·sources·PackageSource(Package::forName(substr($args[$i], 0, -2)))); } else { if (FALSE !== ($p = strpos($args[$i], '::'))) { $sources->add(new xp·unittest·sources·ClassSource(XPClass::forName(substr($args[$i], 0, $p)), substr($args[$i], $p + 2))); } else { if (is_dir($args[$i])) { $sources->add(new xp·unittest·sources·FolderSource(new Folder($args[$i]))); } else { $sources->add(new xp·unittest·sources·ClassSource(XPClass::forName($args[$i]))); } } } } } } } } } } } } } } } } } } catch (Throwable $e) { $this->err->writeLine('*** ', $e->getMessage()); xp::gc(); return 1; } if (isset($coverage)) { $suite->addListener($coverage); } if ($sources->isEmpty()) { $this->err->writeLine('*** No tests specified'); return 1; } // Set up suite $l = $suite->addListener($listener->newInstance($this->out)); if ($l instanceof ColorizingListener) { $l->setColor($colors); } foreach ($sources as $source) { try { $tests = $source->testCasesWith($arguments); foreach ($tests as $test) { $suite->addTest($test); } } catch (NoSuchElementException $e) { $this->err->writeLine('*** Warning: ', $e->getMessage()); continue; } catch (IllegalArgumentException $e) { $this->err->writeLine('*** Error: ', $e->getMessage()); return 1; } catch (MethodNotImplementedException $e) { $this->err->writeLine('*** Error: ', $e->getMessage(), ': ', $e->method, '()'); return 1; } } // Run it! if (0 == $suite->numTests()) { return 3; } else { $r = $suite->run(); return $r->failureCount() > 0 ? 1 : 0; } }
} function testAddingTest() { $f = new xmlrpcmsg('examples.getStateName', array(new xmlrpcval(23, 'int'))); $r = $this->client->send($f, 180, 'https'); if ($r->faultCode()) { // create dummy value so assert fails $v = new xmlrpcval('SSL send failed.'); print '<pre>Fault: ' . $r->faultString() . '</pre>'; } else { $v = $r->value(); } $this->assertEquals('Michigan', $v->scalarval()); } } $suite->addTest(new LocalhostTests('testString')); $suite->addTest(new LocalhostTests('testAdding')); $suite->addTest(new LocalhostTests('testAddingDoubles')); $suite->addTest(new LocalhostTests('testInvalidNumber')); $suite->addTest(new LocalhostTests('testBoolean')); $suite->addTest(new LocalhostTests('testCountEntities')); $suite->addTest(new LocalhostTests('testBase64')); $suite->addTest(new LocalhostTests('testServerMulticall')); $suite->addTest(new LocalhostTests('testClientMulticall')); $suite->addTest(new LocalhostTests('testZeroParams')); $suite->addTest(new LocalhostTests('testCodeInjectionServerSide')); $suite->addTest(new InvalidHostTests('test404')); /* $suite->addTest(new FileCasesTests('testStringBug')); $suite->addTest(new FileCasesTests('testWhiteSpace')); $suite->addTest(new FileCasesTests('testWeirdHTTP')); $suite->addTest(new FileCasesTests('testCodeInjection'));*/
} function testFail1() { $this->assert($this->intVal == 0, "1 == 0"); } function testFail2() { $this->assert($this->strVal == 'bar'); } function testPass1() { $this->assert($this->intVal == 1); } } $suite = new TestSuite(); $suite->addTest(new TestFixture("testFail1")); $suite->addTest(new TestFixture("testFail2")); $suite->addTest(new TestFixture("testPass1")); //$suite->addTest(new TestFixture("testNotExistFail")); class Fixture2 extends TestCase { function Fixture2($name) { $this->TestCase($name); } function setUp() { $this->str1 = 'foo'; $this->str2 = 'bar'; } function runTest()
$Gitem = new GoogleItem('Name', 'description', '3', '12.34'); $Gitem->SetMerchantPrivateItemData(new MerchantPrivateItemData('PrivateItemData')); $Gitem->SetMerchantItemId('123-4321'); // $Gitem->SetTaxTableSelector('TaxableGood'); $Gcart->AddItem($Gitem); $this->assertEquals(trim($Gcart->getXML()), trim('<?xml version="1.0" encoding="utf-8"?> <checkout-shopping-cart xmlns="http://checkout.google.com/schema/2"> <shopping-cart> <items> <item> <item-name>Name</item-name> <item-description>description</item-description> <unit-price currency="GBP">12.34</unit-price> <quantity>3</quantity> <merchant-private-item-data>PrivateItemData</merchant-private-item-data> <merchant-item-id>123-4321</merchant-item-id> </item> </items> </shopping-cart> <checkout-flow-support> <merchant-checkout-flow-support> </merchant-checkout-flow-support> </checkout-flow-support> </checkout-shopping-cart>')); } } if (!isset($suite)) { $suite = new TestSuite(); } $suite->addTest(new TestGoogleCart("TestGoogleCartSimple"));
} function addingTest() { $f = new xmlrpcmsg('examples.getStateName', array(new xmlrpcval(23, "int"))); $r = $this->client->send($f, 180, "https"); if ($r->faultCode()) { // create dummy value so assert fails $v = new xmlrpcval("SSL send failed."); print "<pre>Fault: " . $r->faultString() . "</pre>"; } else { $v = $r->value(); } $this->assertEquals("Michigan", $v->scalarval()); } } $suite->addTest(new TestLocalhost("stringTest")); $suite->addTest(new TestLocalhost("addingTest")); $suite->addTest(new TestLocalhost("addingDoublesTest")); $suite->addTest(new TestLocalhost("invalidNumber")); $suite->addTest(new TestLocalhost("booleanTest")); $suite->addTest(new TestLocalhost("base64Test")); $suite->addTest(new TestInvalidHost("test404")); $suite->addTest(new TestFileCases("stringBug")); $suite->addTest(new TestFileCases("whiteSpace")); $suite->addTest(new TestHTTPSConnection("addingTest")); $title = 'XML-RPC Unit Tests'; ?> <html> <head><title><?php echo $title; ?>
<rule>PER_LINE</rule> </rounding-policy> </merchant-checkout-flow-support> </checkout-flow-support> </checkout-shopping-cart>'; $xml_parsed = new xmlParser($xml); $data = $xml_parsed->getData(); $this->assertEquals(serialize($data), 'a:1:{s:22:"checkout-shopping-cart";a:3:{s:5:"xmlns";s:35:"http://checkou' . 't.google.com/schema/2";s:13:"shopping-cart";a:2:{s:5:"items";a:1:{s:4:"i' . 'tem";a:7:{s:9:"item-name";a:1:{s:5:"VALUE";s:31:"Microsoft IntelliMouse ' . 'Explorer";}s:16:"item-description";a:1:{s:5:"VALUE";s:12:"[Model:USB] ";' . '}s:10:"unit-price";a:2:{s:8:"currency";s:3:"USD";s:5:"VALUE";s:5:"70.95"' . ';}s:8:"quantity";a:1:{s:5:"VALUE";s:1:"1";}s:26:"merchant-private-item-d' . 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. 'ozOiJVU0IiO3M6MjA6Im9wdGlvbnNfdmFsdWVzX3ByaWNlIjtzOjY6IjYuMDAwMCI7czoxMj' . 'oicHJpY2VfcHJlZml4IjtzOjE6IisiO319";}s:16:"merchant-item-id";a:1:{s:5:"V' . 'ALUE";s:35:"26:4614766d78b26fb71bfd21d09f9eb98c";}s:18:"tax-table-select' . 'or";a:1:{s:5:"VALUE";s:13:"Taxable Goods";}}}s:21:"merchant-private-data' . '";a:2:{s:12:"session-data";a:1:{s:5:"VALUE";s:38:"f2f7a0b668ff17095fb996' . '420b8f428c;zenid";}s:10:"ip-address";a:1:{s:5:"VALUE";s:15:"192.168.128.' . '150";}}}s:21:"checkout-flow-support";a:1:{s:30:"merchant-checkout-flow-s' . 'upport";a:7:{s:13:"edit-cart-url";a:1:{s:5:"VALUE";s:77:"http://200.69.2' . '05.154/~brovagnati/zen_demo2/index.php?main_page=shopping_cart";}s:21:"c' . 'ontinue-shopping-url";a:1:{s:5:"VALUE";s:77:"http://200.69.205.154/~brov' . 'agnati/zen_demo2/index.php?main_page=shopping_cart";}s:16:"shipping-meth' . 'ods";a:1:{s:28:"merchant-calculated-shipping";a:4:{i:0;a:4:{s:4:"name";s' . ':42:"Per Item International: Item International";s:5:"price";a:2:{s:8:"c' . 'urrency";s:3:"USD";s:5:"VALUE";s:2:"10";}s:21:"shipping-restrictions";a:' . '3:{s:15:"allow-us-po-box";a:1:{s:5:"VALUE";s:4:"true";}s:13:"allowed-are' . 'as";a:1:{s:10:"world-area";a:1:{s:5:"VALUE";s:0:"";}}s:14:"excluded-area' . 's";a:1:{s:11:"postal-area";a:1:{s:12:"country-code";a:1:{s:5:"VALUE";s:2' . ':"US";}}}}s:15:"address-filters";a:3:{s:15:"allow-us-po-box";a:1:{s:5:"V' . 'ALUE";s:4:"true";}s:13:"allowed-areas";a:1:{s:10:"world-area";a:1:{s:5:"' . 'VALUE";s:0:"";}}s:14:"excluded-areas";a:1:{s:11:"postal-area";a:1:{s:12:' . '"country-code";a:1:{s:5:"VALUE";s:2:"US";}}}}}i:1;a:4:{s:4:"name";s:32:"' . 'Per Item National: Item National";s:5:"price";a:2:{s:8:"currency";s:3:"U' . 'SD";s:5:"VALUE";s:1:"5";}s:21:"shipping-restrictions";a:2:{s:15:"allow-u' . 's-po-box";a:1:{s:5:"VALUE";s:4:"true";}s:13:"allowed-areas";a:1:{s:15:"u' . 's-country-area";a:2:{s:12:"country-area";s:3:"ALL";s:5:"VALUE";s:0:"";}}' . '}s:15:"address-filters";a:2:{s:15:"allow-us-po-box";a:1:{s:5:"VALUE";s:4' . ':"true";}s:13:"allowed-areas";a:1:{s:15:"us-country-area";a:2:{s:12:"cou' . 'ntry-area";s:3:"ALL";s:5:"VALUE";s:0:"";}}}}i:2;a:4:{s:4:"name";s:18:"Zo' . 'nes: Zones Rates";s:5:"price";a:2:{s:8:"currency";s:3:"USD";s:5:"VALUE";' . 's:1:"1";}s:21:"shipping-restrictions";a:2:{s:15:"allow-us-po-box";a:1:{s' . ':5:"VALUE";s:4:"true";}s:13:"allowed-areas";a:1:{s:15:"us-country-area";' . 'a:2:{s:12:"country-area";s:3:"ALL";s:5:"VALUE";s:0:"";}}}s:15:"address-f' . 'ilters";a:2:{s:15:"allow-us-po-box";a:1:{s:5:"VALUE";s:4:"true";}s:13:"a' . 'llowed-areas";a:1:{s:15:"us-country-area";a:2:{s:12:"country-area";s:3:"' . 'ALL";s:5:"VALUE";s:0:"";}}}}i:3;a:4:{s:4:"name";s:23:"Zones: Zones Rates' . ' intl";s:5:"price";a:2:{s:8:"currency";s:3:"USD";s:5:"VALUE";s:1:"2";}s:' . '21:"shipping-restrictions";a:3:{s:15:"allow-us-po-box";a:1:{s:5:"VALUE";' . 's:4:"true";}s:13:"allowed-areas";a:1:{s:10:"world-area";a:1:{s:5:"VALUE"' . ';s:0:"";}}s:14:"excluded-areas";a:1:{s:11:"postal-area";a:1:{s:12:"count' . 'ry-code";a:1:{s:5:"VALUE";s:2:"US";}}}}s:15:"address-filters";a:3:{s:15:' . '"allow-us-po-box";a:1:{s:5:"VALUE";s:4:"true";}s:13:"allowed-areas";a:1:' . '{s:10:"world-area";a:1:{s:5:"VALUE";s:0:"";}}s:14:"excluded-areas";a:1:' . '{s:11:"postal-area";a:1:{s:12:"country-code";a:1:{s:5:"VALUE";s:2:"US";}' . '}}}}}}s:26:"request-buyer-phone-number";a:1:{s:5:"VALUE";s:4:"true";}s:2' . '1:"merchant-calculations";a:3:{s:25:"merchant-calculations-url";a:1:{s:5' . ':"VALUE";s:78:"http://200.69.205.154/~brovagnati/zen_demo2/googlecheckou' . 't/responsehandler.php";}s:23:"accept-merchant-coupons";a:1:{s:5:"VALUE";' . 's:4:"true";}s:24:"accept-gift-certificates";a:1:{s:5:"VALUE";s:5:"false"' . ';}}s:10:"tax-tables";a:2:{s:19:"merchant-calculated";s:5:"false";s:20:"a' . 'lternate-tax-tables";a:1:{s:19:"alternate-tax-table";a:3:{s:10:"standalo' . 'ne";s:5:"false";s:4:"name";s:13:"Taxable Goods";s:19:"alternate-tax-rule' . 's";a:1:{s:18:"alternate-tax-rule";a:2:{s:4:"rate";a:1:{s:5:"VALUE";s:4:"' . '0.07";}s:8:"tax-area";a:1:{s:15:"us-country-area";a:2:{s:12:"country-are' . 'a";s:3:"ALL";s:5:"VALUE";s:0:"";}}}}}}}s:15:"rounding-policy";a:2:{s:4:"' . 'mode";a:1:{s:5:"VALUE";s:9:"HALF_EVEN";}s:4:"rule";a:1:{s:5:"VALUE";s:8:' . '"PER_LINE";}}}}}}'); } function testGoogleXMLParserGetRootXMLNotFolding() { $xml = '<addresses> <anonymous-address id="123"> <test>data 1 </test> </anonymous-address> <anonymous-address id="456"> <test>data 2 </test> </anonymous-address> </addresses>'; $xml_parsed = new xmlParser($xml, array()); $this->assertEquals($xml_parsed->getRoot(), 'ADDRESSES', 'Should be root in UpperCase'); } } if (!isset($suite)) { $suite = new TestSuite(); } $suite->addTest(new testGoogleXMLParser("testGoogleXMLParserGetRoot")); $suite->addTest(new testGoogleXMLParser("testGoogleXMLParserGetDataSimpleXML")); $suite->addTest(new testGoogleXMLParser("testGoogleXMLParserGetDataMediumXML")); $suite->addTest(new testGoogleXMLParser("testGoogleXMLParserGetDataComplexXML")); $suite->addTest(new testGoogleXMLParser("testGoogleXMLParserGetRootXMLNotFolding"));
} function sslTest() { $f = CreateObject('phpgwapi.xmlrpcmsg', 'examples.getStateName', array(CreateObject('phpgwapi.xmlrpcval', 23, 'int'))); $r = $this->client->send($f, 180, 'https'); if ($r->faultCode() || $r) { // create dummy value so assert fails $v = CreateObject('phpgwapi.xmlrpcval', 'SSL send failed.'); echo "<pre>Fault: " . $r->faultString() . "</pre>"; } else { $v = $r->value(); } $this->assertEquals('Michigan', $v->scalarval()); } } $suite->addTest(new TestLocalhost('stringTest')); $suite->addTest(new TestLocalhost('addingTest')); $suite->addTest(new TestLocalhost('addingDoublesTest')); $suite->addTest(new TestLocalhost('invalidNumber')); $suite->addTest(new TestLocalhost('booleanTest')); $suite->addTest(new TestLocalhost('base64Test')); $suite->addTest(new TestLocalhost('countEntities')); $suite->addTest(new TestInvalidHost('test404')); $suite->addTest(new TestFileCases('stringBug')); $suite->addTest(new TestFileCases('whiteSpace')); $suite->addTest(new TestHTTPSConnection('sslTest')); $title = 'XML-RPC Unit Tests'; ?> <p>Note, tests beginning with 'f_' <i>should</i> fail.</p> <p> <?php