Exemple #1
0
<?php

namespace Dotink\Lab;

use Dotink\Sage\TokenParser;
return ['setup' => function ($data) {
    needs(implode(DS, [$data['app_root'], 'src', 'TokenParsers', 'TokenAuthor.php']));
}, 'tests' => ['validate()' => function () {
    assert('Dotink\\Sage\\TokenParser\\TokenAuthor::validate')->with('Matthew J. Sahagian [mattsah] <*****@*****.**>')->equals(TRUE)->with('Matthew J. Sahagian')->equals(TRUE)->with('[mattsah] <*****@*****.**>')->equals(TRUE)->with('Matthew J. Sahagian <*****@*****.**>')->equals(TRUE)->with('<*****@*****.**>')->equals(TRUE)->with('[mattsah]')->equals(TRUE)->with('Matthew J. Sahagian [mattsah]')->equals(TRUE);
}, 'parse()' => function () {
    assert('Dotink\\Sage\\TokenParser\\TokenAuthor::parse')->with('Matthew J. Sahagian [mattsah] <*****@*****.**>')->equals(['name' => 'Matthew J. Sahagian', 'handle' => 'mattsah', 'email' => '*****@*****.**'])->with('Matthew J. Sahagian')->equals(['name' => 'Matthew J. Sahagian', 'handle' => '', 'email' => ''])->with('[mattsah] <*****@*****.**>')->equals(['name' => '', 'handle' => 'mattsah', 'email' => '*****@*****.**'])->with('Matthew J. Sahagian <*****@*****.**>')->equals(['name' => 'Matthew J. Sahagian', 'handle' => '', 'email' => '*****@*****.**'])->with('<*****@*****.**>')->equals(['name' => '', 'handle' => '', 'email' => '*****@*****.**'])->with('[mattsah]')->equals(['name' => '', 'handle' => 'mattsah', 'email' => ''])->with('Matthew J. Sahagian [mattsah]')->equals(['name' => 'Matthew J. Sahagian', 'handle' => 'mattsah', 'email' => '']);
}]];
Exemple #2
0
<?php

needs("Mysql.Mysql");
/**
 * this is is used to maniuplate the htaccess file
 * and requires the mysql class
 */
class Htaccess
{
    private $filename;
    private $htaccess;
    public function __construct($filename = null)
    {
        if (is_null($filename)) {
            $this->filename = ".htaccess";
        }
    }
    function read()
    {
    }
    function writeOut()
    {
        if (touch($this->filename)) {
            $rules = "RewriteEngine On ";
            $rules .= "\n########## Begin - Rewrite rules to block out some common exploits";
            $rules .= "\n## If you experience problems on your site block out the operations listed below";
            $rules .= "\n## This attempts to block the most common type of exploit !";
            $rules .= "\n# Block out any script trying to set a mosConfig value through the URL";
            $rules .= "\nRewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\\%3D) [OR]";
            $rules .= "\n# Block out any script trying to base64_encode crap to send via URL";
            $rules .= "\nRewriteCond %{QUERY_STRING} base64_encode.*\\(.*\\) [OR]";
Exemple #3
0
<?php

namespace Dotink\Lab;

use Dotink\Parody\Mime;
return ['setup' => function ($data, $shared) {
    needs('src/Quip.php');
    needs('src/Mime.php');
}, 'tests' => ['Test' => function ($data, $shared) {
    $static = Mime::define('Bar');
    $instance = Mime::create('Bar')->onCall('foo')->give('bar');
    $static->onCall('foo')->give('bar');
    assert(\Bar::foo())->equals('bar');
    assert($instance()->foo())->equals('bar');
    $instance = $static->create()->onCall('foo')->give('bar');
    assert($instance()->foo())->equals('bar');
    $static->onNew('test', function ($mime) {
        $mime->onCall('foo')->give('foo');
    });
    $instance = new \Bar('test');
    assert($instance->foo())->equals('foo');
}]];
Exemple #4
0
<?php

namespace Dotink\Lab;

use Dotink\Jin;
use Dotink\Flourish;
return ['setup' => function ($data, $shared) {
    needs($data['root'] . '/src/Parser.php');
    needs($data['root'] . '/vendor/dotink/flourish-collection/src/Collection.php');
    $shared->jin = new Jin\Parser(new Flourish\Collection());
}, 'tests' => ['Kitchen Sink' => function ($data, $shared) {
    $jin_file = $data['root'] . '/test/resources/kitchen_sink.jin';
    $contents = file_get_contents($jin_file);
    $data = $shared->jin->parse($contents)->get();
    assert(is_array($data))->equals(TRUE);
    assert(isset($data['person']['education']['level']))->equals(TRUE);
    assert(is_bool($data['person']['single']))->equals(TRUE);
    assert(is_int($data['person']['age']))->equals(TRUE);
    assert(is_float($data['person']['pi']))->equals(TRUE);
    assert($data['person']['education']['level'])->equals('Associates');
    assert($data['person']['vehicles'])->contains('2005 Mazda 6');
}]];
Exemple #5
0
<?php

namespace Dotink\Lab;

use Dotink\Flourish\Core;
use stdClass;
return ['setup' => function ($data, $shared) {
    needs($data['root'] . '/src/Core.php');
    needs($data['root'] . '/src/Exception.php');
    needs($data['root'] . '/src/Exceptions/UnexpectedException.php');
    needs($data['root'] . '/src/Exceptions/Unexpected/ProgrammerException.php');
}, 'tests' => ['Seed Random' => function ($data, $shared) {
    $shared->core = new Core();
    assert('Dotink\\Flourish\\Core::seedRandom')->equals(TRUE, EXACTLY)->equals(TRUE, EXACTLY);
}, 'Check OS' => function ($data, $shared) {
    assert('Dotink\\Flourish\\Core::checkOS')->with('foobar')->throws('Dotink\\Flourish\\ProgrammerException');
    assert('Dotink\\Flourish\\Core::checkOS')->with('linux')->is(IN, [TRUE, FALSE])->with('freebsd')->is(IN, [TRUE, FALSE])->with('netbsd')->is(IN, [TRUE, FALSE])->with('openbsd')->is(IN, [TRUE, FALSE])->with('windows')->is(IN, [TRUE, FALSE])->with('osx')->is(IN, [TRUE, FALSE])->with('solaris')->is(IN, [TRUE, FALSE])->with('aix')->is(IN, [TRUE, FALSE]);
}, 'Dereference' => function ($data, $shared) {
    $struct = ['bar' => 'bar', 'foo' => ['bar' => 'bar'], 'foobar' => ['foo' => ['bar' => 'bar']]];
    assert('Dotink\\Flourish\\Core::dereference')->with('bar', $struct)->equals('bar')->with('foo[bar]', $struct)->equals('bar')->with('foobar[foo][bar]', $struct)->equals('bar')->with('bogus', $struct)->throws('Dotink\\Flourish\\ProgrammerException');
}]];
Exemple #6
0
<?php

namespace Dotink\Lab;

use iMarc\Auth\ACL;
use iMarc\Auth\Manager;
use Dotink\Parody\Mime;
return ['setup' => function ($data, $shared) {
    Mime::define('User')->implementing('iMarc\\Auth\\EntityInterface');
    needs($data['root'] . '/src/ACLInterface.php');
    needs($data['root'] . '/src/ACL.php');
    needs($data['root'] . '/src/Manager.php');
    $shared->user = Mime::create('User')->onCall('getRoles')->give(['Editor', 'User'])->onCall('getPermissions')->give(['user' => ['read']])->resolve();
    $shared->manager = new Manager($shared->user);
    $shared->acl = new ACL();
    $shared->acl->allow('Admin', 'User', ['create', 'read', 'update', 'delete', 'permit']);
    $shared->acl->allow('Admin', 'Article', ['create', 'read', 'UPDATE', 'delete', 'permit']);
    $shared->acl->allow('editor', 'Article', ['create', 'read', 'update', 'delete']);
    $shared->acl->allow('user', 'Article', ['read']);
    $shared->manager->add($shared->acl);
}, 'tests' => ['Can' => function ($data, $shared) {
    assert('iMarc\\Auth\\Manager::can')->using($shared->manager)->with('create', 'user')->equals(FALSE)->with('read', 'article')->equals(TRUE)->with('read', 'user')->equals(TRUE);
    $shared->manager->override('User', 'create', function ($auth, $user) {
        return TRUE;
    });
    assert('iMarc\\Auth\\Manager::can')->using($shared->manager)->with('create', 'user')->equals(TRUE);
}, 'Has' => function ($data, $shared) {
    assert('iMarc\\Auth\\Manager::has')->using($shared->manager)->with('create', 'user')->equals(FALSE)->with('read', 'article')->equals(TRUE);
}, 'Is' => function ($data, $shared) {
    assert('iMarc\\Auth\\Manager::is')->using($shared->manager)->with('Admin')->equals(FALSE)->with('EDITOR')->equals(TRUE);
}]];
Exemple #7
0
<?php

namespace Dotink\Lab;

use Affinity;
return ['setup' => function ($data, $shared) {
    needs($data['root'] . '/src/ConfigInterface.php');
    needs($data['root'] . '/src/Config.php');
    needs($data['root'] . '/src/ActionInterface.php');
    needs($data['root'] . '/src/Action.php');
    needs($data['root'] . '/src/DriverInterface.php');
    needs($data['root'] . '/src/NativeDriver.php');
    needs($data['root'] . '/src/Engine.php');
}, 'tests' => ['Complete test with sample data' => function ($data, $shared) {
    $config_driver = new Affinity\NativeDriver($data['root'] . '/test/sample/config');
    $action_driver = new Affinity\NativeDriver($data['root'] . '/test/sample/include');
    $engine = new Affinity\Engine($config_driver, $action_driver);
    $engine->start('dev', ['engine' => $engine]);
    assert($engine->fetch('core', 'foo'))->equals('too');
    assert($engine->fetch('@test', 'foo'))->equals(['core' => 'bar']);
}]];
Exemple #8
0
<?php

namespace Dotink\Lab;

use iMarc\Auth\ACL;
return ['setup' => function ($data, $shared) {
    needs($data['root'] . '/src/ACLInterface.php');
    needs($data['root'] . '/src/ACL.php');
    $shared->acl = new ACL();
    $shared->acl->allow('Admin', 'User', ['create', 'read', 'update', 'delete', 'permit']);
    $shared->acl->allow('Admin', 'Article', ['create', 'read', 'UPDATE', 'delete', 'permit']);
    $shared->acl->allow('editor', 'Article', ['create', 'read', 'update', 'delete']);
}, 'tests' => ['Allowing (Check Roles)' => function ($data, $shared) {
    assert('iMarc\\Auth\\ACL::getRoles')->using($shared->acl)->equals(['admin', 'editor']);
}, 'Allowing (Check Permissions)' => function ($data, $shared) {
    assert('iMarc\\Auth\\ACL::getPermissions')->with('admin')->using($shared->acl)->equals(['user' => ['create', 'read', 'update', 'delete', 'permit'], 'article' => ['create', 'read', 'update', 'delete', 'permit']])->with('EDITOR')->using($shared->acl)->equals(['article' => ['create', 'read', 'update', 'delete']]);
}, 'Alias' => function ($data, $shared) {
    $shared->acl->alias('manage', ['create', 'read', 'update', 'delete']);
    $shared->acl->allow('editor', 'Alert', ['manage']);
    assert('iMarc\\Auth\\ACL::getPermissions')->with('editor')->using($shared->acl)->equals(['article' => ['create', 'read', 'update', 'delete'], 'alert' => ['create', 'read', 'update', 'delete']]);
}, 'Recursive Alias' => function ($data, $shared) {
    $shared->acl->alias('admin', ['manage', 'permit']);
    $shared->acl->allow('editor', 'Article', ['admin']);
    assert('iMarc\\Auth\\ACL::getPermissions')->with('editor')->using($shared->acl)->equals(['article' => ['create', 'read', 'update', 'delete', 'permit'], 'alert' => ['create', 'read', 'update', 'delete']]);
}]];
Exemple #9
0
<?php

namespace Dotink\Lab;

use Dotink\Sage\TokenParser;
return ['setup' => function ($data) {
    needs(implode(DS, [$data['app_root'], 'src', 'TokenParsers', 'TokenReturn.php']));
}, 'tests' => ['validate()' => function () {
    assert('Dotink\\Sage\\TokenParser\\TokenReturn::validate')->with('int This should validate')->equals(TRUE)->with('int')->equals(FALSE)->with('int|boolean This should also not validate')->equals(FALSE)->with('int        This should validate')->equals(TRUE)->with('float|int         This should also not validate')->equals(FALSE)->with('void')->equals(TRUE)->with('void     ')->equals(TRUE);
}, 'parse()' => function () {
    assert('Dotink\\Sage\\TokenParser\\TokenReturn::parse')->with('int An integer to be returned')->equals(['type' => 'int', 'note' => 'An integer to be returned'])->with('void')->equals(['type' => NULL, 'note' => NULL]);
}]];
<?php

namespace Dotink\Lab;

use Dotink\Flourish\Collection;
return ['setup' => function ($data, $shared) {
    needs($data['root'] . '/src/Collection.php');
    needs($data['root'] . '/test/shims/NotFoundException.php');
}, 'tests' => ['Setting / Getting' => function ($data, $shared) {
    $collection = new Collection(['a' => 'apple', 'b' => 'banana']);
    $collection->set('c', 'carrot');
    $assertion = assert('Dotink\\Flourish\\Collection::get')->using($collection);
    $assertion->with()->equals(['a' => 'apple', 'b' => 'banana', 'c' => 'carrot'])->with(['a', 'b'])->equals(['a' => 'apple', 'b' => 'banana'])->with('c')->equals('carrot')->with('c')->equals('carrot')->with(['d'], 'date')->equals(['d' => 'date']);
    $collection->set(['b' => 'blueberry']);
    $assertion->with()->equals(['a' => 'apple', 'b' => 'blueberry', 'c' => 'carrot']);
}, 'Iteration' => function ($data, $shared) {
    $keys = array();
    $values = array();
    $collection = new Collection(['a' => 'apple', 'b' => 'banana']);
    foreach ($collection as $key => $value) {
        $keys[] = $key;
        $values[] = $value;
    }
    assert($keys)->equals(['a', 'b']);
    assert($values)->equals(['apple', 'banana']);
}, 'Compound Keys' => function ($data, $shared) {
    $collection = new Collection(['foo' => ['bar' => 'foobar'], 'bar' => (object) ['foo' => 'foobar']]);
    assert('Dotink\\Flourish\\Collection::get')->using($collection)->with('foo.bar')->equals('foobar')->with('foo')->equals(['bar' => 'foobar'])->with('bar.foo')->equals('foobar')->with('bar')->equals((object) ['foo' => 'foobar']);
    $collection->set('bar.foo', 'barfoo');
    $collection->set('foo.bar', 'barfoo');
    assert('Dotink\\Flourish\\Collection::get')->using($collection)->with('foo.bar')->equals('barfoo')->with('bar.foo')->equals('barfoo');
Exemple #11
0
<?php

namespace Dotink\Lab;

use Dotink\Parody\Mime;
use Dotink\Inkwell;
return ['setup' => function ($data) {
    needs($data['root'] . DS . 'includes/core.php');
}, 'cleanup' => function ($config) {
}, 'tests' => ['transformClassToIW()' => function ($config) {
    assert('Dotink\\Inkwell\\IW::transformClassToIW')->with('\\Vendor\\Project\\Class')->equals('Vendor/Project/Class.php');
    assert('Dotink\\Inkwell\\IW::transformClassToIW')->with('Vendor\\Project\\ClassException')->equals('Vendor/Project/Exceptions/ClassException.php');
    assert('Dotink\\Inkwell\\IW::transformClassToIW')->with('Vendor\\Project\\Exception')->equals('Vendor/Project/Exceptions/Exception.php');
    assert('Dotink\\Inkwell\\IW::transformClassToIW')->with('Vendor\\Project\\ClassTrait')->equals('Vendor/Project/Traits/ClassTrait.php');
    assert('Dotink\\Inkwell\\IW::transformClassToIW')->with('Vendor\\Project\\ClassInterface')->equals('Vendor/Project/Interfaces/ClassInterface.php');
}, 'transformClassToPSR0()' => function ($config) {
    assert('Dotink\\Inkwell\\IW::transformClassToPSR0')->with('\\Vendor\\Project\\Class')->equals('Vendor/Project/Class.php');
    assert('Dotink\\Inkwell\\IW::transformClassToPSR0')->with('Vendor\\Project\\Class')->equals('Vendor/Project/Class.php');
    assert('Dotink\\Inkwell\\IW::transformClassToPSR0')->with('Vendor\\Project\\Example_Class')->equals('Vendor/Project/Example/Class.php');
}, 'addLoadingStandard()' => function ($config) {
    $app = new Inkwell\IW($config['root']);
    assert('Dotink\\Inkwell\\IW::addLoadingStandard')->using($app)->with('IW', 'Dotink\\Inkwell\\IW::transformClassToIW')->equals('Dotink\\Inkwell\\IW::transformClassToIW');
    assert('Dotink\\Inkwell\\IW::addLoadingStandard')->using($app)->with('IW', 'Dotink\\Inkwell\\IW::bogusTransformCallback')->throws('Dotink\\Flourish\\ProgrammerException');
}, 'addRoot()' => function ($config) {
    $app = new Inkwell\IW($config['root']);
    assert('Dotink\\Inkwell\\IW::addRoot')->using($app)->with('testing', 'external/testing')->equals($config['root'] . DS . implode(DS, ['external', 'testing']))->with('testing', '/tmp')->equals('/tmp')->with('testing', '/tmp/is/garbage/dir')->throws('Dotink\\Flourish\\ProgrammerException');
}, 'getRoot()' => function ($config) {
    $app = new Inkwell\IW($config['root']);
    $app->addRoot('testing', implode(DS, ['external', 'testing']));
    $app->addRoot('tmp', '/tmp');
    assert('Dotink\\Inkwell\\IW::getRoot')->using($app)->with('testing')->equals($config['root'] . DS . implode(DS, ['external', 'testing']))->with('tmp')->equals('/tmp')->with('value not added')->equals($config['root']);