*/ function dbprefs() { if (!config::has('lepton.db.default')) { $this->skip(); } $tf = $this->getTempFile(); $s = new DbPrefs('prefstest'); $this->assertNotNull($s); $s->foo = 'bar'; unset($s); $s = new DbPrefs('prefstest'); $this->assertNotNull($s); $this->assertEquals($s->foo, 'bar'); $s->destroy(); unset($s); // unlink('/tmp/jsonprefs.tmp'); } /** * @description Array-based storage (Optionset) */ function arrayprefs() { $s = new ArrayPrefs(array('foo' => 'bar')); $this->assertEquals($s->foo, 'bar'); $this->assertEquals($s->get('foo'), 'bar'); $this->assertEquals($s->get('bar', 'baz'), 'baz'); } } Lunit::register('LeptonPrefsTests');
<?php using('lunit.*'); class LeptonWebTests extends LunitCase { /** * @description Parsing URLs and setting properties */ function url() { using('lepton.web.url'); $u = new url('http://www.google.com?foo=bar'); $u->setParameter('baz', 'bin'); $this->assertEquals($u->toString(), 'http://www.google.com?foo=bar&baz=bin'); } /** * @description Service Discovery */ function discover() { using('lepton.net.httprequest'); using('lepton.web.discovery'); $d = Discovery::discover('http://127.0.0.1'); $this->assertNotNull($d); } } Lunit::register('LeptonWebTests');
$this->assertEquals($ds->getCount(), 2); $this->ds = $ds; } /** * @description Testing native pie chart implementation */ function piechart() { $pc = new PieChart(400, 400); $this->assertNotNull($pc); $pc->setData($this->ds); $c = $pc->render(); $this->assertEquals($c->width, 400); $this->assertEquals($c->height, 400); } /** * @description Testing Google pie chart implementation */ function gpiechart() { $this->explicitFail('Not Implemented!'); $pc = new GPieChart(400, 400); $this->assertNotNull($pc); $pc->setData($this->ds); $c = $pc->render(); $this->assertEquals($c->width, 400); $this->assertEquals($c->height, 400); } } Lunit::register('LeptonDataTests');
$this->results[] = $word; } /** * @description Creating delegate chain */ function delegatecreate() { $this->delegate = new Delegate(); $this->assertNotNull($this->delegate); } /** * @description Attaching delegates to chain */ function delegateattach() { $this->delegate->addDelegate(array(&$this, '_dlgcb')); $this->delegate->addDelegate(array(&$this, '_dlgcb')); } /** * @description Calling delegate */ function delegatecall() { $this->delegate->call("foo"); $this->assertTrue(count($this->results) == 2); $this->assertEquals($this->results[0], "foo"); $this->assertEquals($this->results[0], $this->results[1]); } } Lunit::register('LeptonDelegatesTests');
*/ function testfmt() { $this->assertEquals(__fmt(array('foo%s')), 'foo%s'); $this->assertEquals(__fmt(array('foo%s', 'bar')), 'foobar'); } /** * @description __filepath() and __fileext() shorthands */ function filepaths() { $this->assertEquals(__fileext('/foo/bar.baz'), 'baz'); $this->assertEquals(__filepath('/foo/bar.baz'), '/foo'); } /** * @description file_find() to locate file with globbing */ function filefind() { $this->assertEquals(file_find(base::basePath(), 'defaults.php'), base::basePath() . 'sys/defaults.php'); } /** * @description file_find() on a bad path returning null */ function filefindbaddir() { $this->assertNull(file_find('/foo/bar', 'baz')); } } Lunit::register('LeptonBaseTests');
$this->rw = new Stream($this->fn, 'r'); $this->assertNotNull($this->rw); } /** * @description Reading data from stream */ function readdata() { $data = $this->rw->gets(); $this->assertEquals($data, 'Hello World!'); } /** * @description Seeking, telling, and reading again */ function readseek() { $this->rw->seek(0); $this->assertEquals($this->rw->tell(), 0); $data = $this->rw->gets(); $this->assertEquals($data, 'Hello World!'); } /** * @description Closing stream */ function readclose() { unset($this->rw); } } Lunit::register('LeptonStreamsTest');
{ /** * @description Setting languages */ function setlanguage() { intl::setLanguage('sv'); $this->assertEquals(intl::getLanguage(), 'sv'); $this->assertEquals(intl::getFullLanguage(), 'sv'); intl::setLanguage('en-gb'); $this->assertEquals(intl::getLanguage(), 'en'); $this->assertEquals(intl::getRegion(), 'gb'); $this->assertEquals(intl::getFullLanguage(), 'en-gb'); } /** * @description Setting bad language throws exception */ function setbadlanguage() { intl::setLanguage('sv'); try { intl::setLanguage('swe'); } catch (Exception $e) { $this->assertEquals(intl::getLanguage(), 'sv'); return; } $this->explicitFail('No exception thrown'); } } Lunit::register('LeptonInternationalizationTests');
} $tf = $this->getTempFile('.png'); $this->assertNotNull($this->canvas); $this->canvas->save($tf); $im = new ImagickImage($tf); $this->assertNotNull($im); } /** * @description Screen capture with Screenshot() class. * @repeat 5 */ function screenshot() { unset($this->canvas); $this->canvas = new Screenshot(); $this->assertNotNull($this->canvas); } /** * @description Verifying properties of canvas */ function screenshotprops() { if (!isset($this->canvas)) { $this->skip(); } $this->assertTrue($this->canvas->width > 0); $this->assertTrue($this->canvas->height > 0); } } Lunit::register('LeptonCanvasTests');
<?php /** * @description Base tests for Lepton Application Platform */ class BaseTests extends LunitCase { /** * @description Simple test */ function simple() { $this->assertTrue(false); } } Lunit::register('BaseTests');
<?php using('lunit.*'); class LeptonMemcachedTests extends LunitCase { function __construct() { using('lepton.utils.cache'); } function setcacheitems() { cache::set('foo', 'bar', '1m'); } function hitcacheitem() { $r = cache::get('foo'); $this->assertNotNull($r); } function hitfailcacheitem() { try { $r = cache::get('bar'); } catch (CacheException $e) { } } } Lunit::register('LeptonMemcachedTests');
return; } $this->assertTrue(false); } /** * @description Testing incomplete BasicContainer */ function ibasiccontainer() { try { $c1 = new IncompleteTestContainer(); $this->assertTrue(false); } catch (Exception $e) { $this->assertTrue(true); return; } $this->assertTrue(false); } function basiclist() { $l = new BasicList(); $l->push('Hello World'); $l['foo'] = 'Bar'; $this->assertEquals($l['foo'], 'Bar'); $this->assertEquals($l->pop(), 'Bar'); $this->assertEquals($l->pop(), 'Hello World'); $this->assertEquals($l->pop(), null); } } Lunit::register('LeptonContainersTest');
$this->assertEquals($this->os->xyzzy, null); } /** * @description Accessing via properties with defaults */ function opttestdefaults() { $this->assertEquals($this->osd->foo, 'bar'); $this->assertEquals($this->osd->xyzzy, 'omg'); } /** * @description Accessing via get() without defaults */ function opttestgetclean() { $this->assertEquals($this->os->get('foo'), 'bar'); $this->assertEquals($this->os->get('xyzzy'), null); $this->assertEquals($this->os->get('xyzzy', 'omg'), 'omg'); } /** * @description Accessing via properties with defaults */ function opttestgetdefaults() { $this->assertEquals($this->osd->get('foo'), 'bar'); $this->assertEquals($this->osd->get('xyzzy'), 'omg'); $this->assertEquals($this->osd->get('xyzzy', 'xing'), 'xing'); } } Lunit::register('LeptonOptionsetTests');
/** * @description Twofish Cryptography Implementation */ function twofishcrypto() { $c = new CryptoCipher(MCRYPT_TWOFISH, 'hello'); $e = $c->encrypt('helloworld'); $this->assertEquals($e, 'uIfx79ilnvRVY5RT/znzXA=='); $this->assertEquals($c->decrypt($e), 'helloworld'); } /** * @description DES Cryptography Implementation */ function descrypto() { $c = new CryptoCipher(MCRYPT_DES, 'hello'); $e = $c->encrypt('helloworld'); $this->assertEquals($e, 'q8dBduudWGAuIw4LPXMCFQ=='); $this->assertEquals($c->decrypt($e), 'helloworld'); } /** * @description Generate UUID V4 */ function uuid_v4() { $uuid = uuid::v4(); $this->assertEquals(strlen($uuid), uuid::LENGTH); } } Lunit::register('LeptonCryptoTests');
using('lepton.mvc.session'); } /** * @description Generating a new captcha */ function testgenerate() { config('lepton.captcha.font', 'FreeSans.ttf'); $this->captchaid = captcha::generate(); $this->assertNotNull($this->captchaid); $this->captchatext = captcha::getstring($this->captchaid); $this->assertNotNull($this->captchatext); } /** * @description Displaying/saving captcha * @repeat 20 */ function display() { captcha::display($this->captchaid, $this->getTempFile('png')); } /** * @description Validating captcha string */ function validate() { $this->assertTrue(captcha::verify($this->captchatext, $this->captchaid)); } } Lunit::register('LeptonCaptchaTests');
function run() { $cases = Lunit::getCases(); $casedata = array(); // Enumerate the cases foreach ($cases as $case) { // Setup report structure $casereport = array(); // Reflect the class to find methods and metadata $r = new ReflectionClass($case); $ml = $r->getMethods(); $skip = false; $meta = LunitUtil::parseDoc($r->getDocComment()); if (!isset($meta['description'])) { $meta['description'] = $case; } $meta['casename'] = $case; if (isset($meta['extensions'])) { $extn = explode(' ', $meta['extensions']); foreach ($extn as $ext) { if (!extension_loaded($ext)) { $skip = true; $skipmsg = "Need extension: " . $ext; } } } $casereport['meta'] = $meta; // Callback if set if ($this->statuscb) { $this->statuscb->onCaseBegin($case, $meta); } if ($this->dblog) { $this->dblog->onCaseBegin($case, $meta); } try { if (!$skip) { $tc = new $case($this); } foreach ($ml as $method) { $methodname = $method->getName(); if ($method->isPublic() && substr($methodname, 0, 1) != '_') { $methodreport = array(); $tmeta = LunitUtil::parseDoc($method->getDocComment()); if (!isset($tmeta['description'])) { $tmeta['description'] = $methodname; } if (!isset($tmeta['repeat'])) { $tmeta['repeat'] = 1; } // Save meta to method report $methodreport['meta'] = $tmeta; // Times to repeat the test $repeat = intval($tmeta['repeat']); // Callback if set, then create timer if ($this->statuscb) { $this->statuscb->onTestBegin($methodname, $tmeta); } if ($this->dblog) { $this->dblog->onTestBegin($methodname, $meta); } $methodreport['skipped'] = false; $tavg = null; $tmax = null; $tmin = null; if (!$skip) { $tm = new Timer(); try { $telapsed = array(); $ttotal = 0; for ($n = 0; $n < $repeat; $n++) { $tm->start(); $tc->{$methodname}(); $tm->stop(); $telapsed[] = $tm->getElapsed() * 1000; $ttotal += $tm->getElapsed() * 1000; } $ttot = math::sum($telapsed); $tavg = math::average($telapsed); $tmin = math::min($telapsed); $tmax = math::max($telapsed); $tdev = math::deviation($telapsed); $methodreport['passed'] = true; $methodreport['message'] = null; if ($repeat > 1) { // console::write('%6.1fms <%6.1fms> %6.1fms ', $tmin, $tavg, $tmax); } else { // console::write('%6.1fms ', $tmax); } if ($this->statuscb) { $this->statuscb->onTestEnd(true, null); } if ($this->dblog) { $this->dblog->onTestEnd(true, null); } } catch (LunitAssertionFailure $f) { $tm->stop(); $methodreport['passed'] = false; $methodreport['message'] = $f->getMessage(); if ($this->statuscb) { $this->statuscb->onTestEnd(false, $f->getMessage()); } if ($this->dblog) { $this->dblog->onTestEnd(false, $f->getMessage()); } } catch (LunitAssertionSkip $f) { $tm->stop(); $methodreport['passed'] = false; $methodreport['skipped'] = true; $methodreport['message'] = 'Skipped'; if ($this->statuscb) { $this->statuscb->onTestEnd(null, $f->getMessage()); } if ($this->dblog) { $this->dblog->onTestEnd(null, $f->getMessage()); } } catch (Exception $e) { $tm->stop(); $methodreport['passed'] = false; $methodreport['message'] = $e->getMessage(); if ($this->statuscb) { $this->statuscb->onTestEnd(false, $e->getMessage()); } if ($this->dblog) { $this->dblog->onTestEnd(false, $f->getMessage()); } } } else { $methodreport['passed'] = false; $methodreport['skipped'] = true; $methodreport['message'] = $skipmsg; $this->statuscb->onTestEnd(null, $skipmsg); if ($this->dblog) { $this->dblog->onTestEnd(null, $skipmsg); } } $methodreport['elapsed'][] = $tm->getElapsed(); $methodreport['average'] = $tavg; $methodreport['minmax'] = array($tmin, $tmax); // Save report $casereport['tests'][$methodname] = $methodreport; } } } catch (Exception $e) { console::writeLn("Skipped due to exception: %s", $e->getMessage()); } $casedata[$case] = $casereport; // Callback if set if ($this->statuscb) { $this->statuscb->onCaseEnd(); } if ($this->dblog) { $this->dblog->onCaseEnd($casereport); } } $this->results = $casedata; }
<?php using('lunit.*'); class LeptonVartypeTest extends LunitCase { function stringtest() { $s = vartype::string()->required()->defaultvalue('foo'); $this->assertTrue($s->getRequired()); $this->assertEquals($s->getDefault(), 'foo'); } function floattest() { $s = vartype::float()->nullable()->defaultvalue('foo'); $this->assertFalse($s->getRequired()); $this->assertEquals($s->getDefault(), 'foo'); } } Lunit::register('LeptonVartypeTest');
ContentManager::registerProvider(new DummyContentProvider()); ContentManager::registerExtension(new DummyContentExtension()); /** * @description Content Wrappers */ class LeptonContentTests extends LunitCase { private $co = null; function __construct() { } /** * @description Testing provider for namespace dummy */ function providertest() { $this->co = ContentManager::get('dummy:hello-world'); $this->assertNotNull($this->co); $this->assertEquals($this->co->getHtml(), 'hello-world'); } /** * @description Testing extension via dummy->reverse() */ function extensiontest() { $this->assertNotNull($this->co); $this->assertEquals($this->co->dummy->reverse(), 'dlrow-olleh'); } } Lunit::register('LeptonContentTests');
* @description Filesystem Factory test (FsObject) */ function factory_test() { $f = FsObject::get(base::appPath()); $this->assertNotNull($f); $this->assertEquals(typeof($f), 'FsDirectory'); } function paths() { $f = FsObject::get(base::appPath()); $path = $f->getDirname(); $this->assertNotNull($path); } function usage() { $f = FsObject::get(base::appPath()); $usage = $f->getDiskUsage(true); $this->assertNotNull($usage); $this->assertEquals(typeof($usage), 'array'); } function joininigpaths() { $f = FsObject::get(base::appPath()); $p1 = $f->joinPath('foo/bar'); $p2 = $f->joinPath(array('foo', 'bar')); $this->assertEquals($p1, $p2); } } Lunit::register('LeptonFsTests');
$this->qfn = $this->getTempFile(); $this->queue = new MessageQueue($this->qfn); $this->assertNotNull($this->queue); } /** * @description MessageQueue: Posting message to queue * @repeat 50 */ function queuepostmessage() { $this->queue->push(1, new MessageEnvelope('lepton.test', array('foo' => 'bar'))); } /** * @description MessageQueue: Reading message from queue * @repeat 50 */ function queuegetmessage() { $message = $this->queue->pop(1); $this->assertEquals($message->foo, 'bar'); } /** * @description MessageQueue: Destroy queue */ function destroyqueue() { $this->queue->destroy(); } } Lunit::register('LeptonIpcTests');
$this->assertTrue(true); return; } $this->assertTrue(false); } /** * @description Releasing lock through unset() */ function mutexrelease() { unset($this->mutex); $this->assertTrue(true); } /** * @description Releasing lock through mutex->release() */ function mutexreleasemtd() { $m = new Mutex('lunitlock', 100); $m->release(); } /** * @description Cleaning up locks */ function cleanup() { mutex::void(); } } Lunit::register('LeptonMutexTest');