public function touch() { $class = eden('system')->file(realpath(__DIR__ . '/../assets') . '/content.txt')->touch(); $this->assertInstanceOf('Eden\\System\\File', $class); $this->assertTrue(file_exists(__DIR__ . '/../assets/content.txt')); eden('system')->file(realpath(__DIR__ . '/../assets') . '/content.txt')->remove(); }
public function testArrayAccess() { $path = eden('system')->path('some/path/'); $this->assertEquals('some', $path[1]); $path['replace'] = 'foo'; $this->assertEquals('foo', $path['last']); }
public function testImport() { $callback = Eve\Plugin\Csrf\Setup::i()->import(); $this->assertTrue(is_callable($callback)); $error = false; try { eve()->addCsrf(eden('registry'), eden('registry'), array('method' => 'GET', 'check_csrf' => true)); } catch (Exception $e) { $error = true; } $this->assertTrue($error); $error = false; $request = eden('registry')->set('get', 'csrf', '1234567890'); try { eve()->addCsrf($request, eden('registry'), array('method' => 'GET', 'check_csrf' => true, 'make_csrf' => true)); } catch (Exception $e) { $error = true; } $this->assertFalse($error); $this->assertTrue($request->get('get', 'csrf') !== $request->get('csrf')); $_GET['csrf'] = $_SESSION['csrf'] = $request->get('csrf'); $error = false; try { $callback($request, eden('registry')); } catch (Exception $e) { $error = true; } $this->assertFalse($error); }
public function testIterable() { $data = array('foo', 'bar'); $class = eden('type', $data); foreach ($class as $key => $value) { $this->assertEquals($class->current(), $value); } }
public function testUncamelize() { $string = 'testValue'; $resultString = 'test-value'; $class = eden('type', $string)->uncamelize('-'); $this->assertInstanceOf('Eden\\Type\\StringType', $class); $newString = $class->get(); $this->assertEquals($resultString, $newString); }
public function testIterable() { $class = @eden('session')->start(); $class['me'] = array('name' => 'John', 'age' => 31); $class['you'] = array('name' => 'Jane', 'age' => 28); $class['him'] = array('name' => 'Jack', 'age' => 35); foreach ($class as $key => $value) { $this->assertEquals($class[$key]['name'], $value['name']); } }
protected function _getContents($path) { try { $library = front()->registry()->get('path', 'library'); $folder = eden('folder', $library . $path); $files = $folder->getFiles(); $folders = $folder->getFolders(); } catch (Exception $e) { return array('folders' => array(), 'files' => array()); } sort($files); sort($folders); return array('folders' => $folders, 'files' => $files); }
public function testAddRoute() { $rest = eden('rest', 'http://graph.facebook.com', true)->addRoute('create/wall/post', 'create/post')->addRoute('create/page/post', 'create/post')->addRoute('create/group/post', 'create/post')->addRoute('create/event/post', 'create/post')->addRoute('create/post', array('method' => 'post', 'route' => '/*/feed', 'data' => array('tags' => array(array('regex', '/^[0-9\\,]+$/')), 'access_token' => 'required', 'privacy' => 'json'), 'error' => array('tags' => 'tags must be a list of user ids', 'access_token' => 'access_token is required'), 'query' => array('access_token'), 'request' => 'query', 'response' => 'json')); //test pathing $meta = $rest->setAccessToken('123')->setTags('123,234')->createPost(345); $this->assertEquals('http://graph.facebook.com/345/feed?access_token=123', $meta['url']); $this->assertEquals(http_build_query(array('tags' => '123,234')), $meta['post']); //test alias $meta = $rest->createWallPost(345); $this->assertEquals('http://graph.facebook.com/345/feed?access_token=123', $meta['url']); $this->assertEquals(http_build_query(array('tags' => '123,234')), $meta['post']); //test extra $meta = $rest->createPagePost(345, 456); $this->assertEquals('http://graph.facebook.com/345/feed?access_token=123', $meta['url']); $this->assertEquals(http_build_query(array('tags' => '123,234')), $meta['post']); }
public function testImport() { $callback = Eve\Plugin\Captcha\Setup::i()->import('123', '321'); $this->assertTrue(is_callable($callback)); $request = eden('registry'); eve()->addCaptcha($request, eden('registry'), array('method' => 'GET', 'check_captcha' => true)); $this->assertFalse($request->get('valid_captcha')); $request->set('valid_captcha', true); $request->set('get', 'g-recaptcha-response', '1234567890'); eve()->addCaptcha($request, eden('registry'), array('method' => 'GET', 'check_captcha' => true, 'make_captcha' => true)); $this->assertTrue($request->get('valid_captcha') !== false); $_GET['g-recaptcha-response'] = $_SESSION['captcha'] = $request->get('csrf'); $error = false; try { $callback($request, eden('registry')); } catch (Exception $e) { $error = true; } $this->assertFalse($error); }
/** * Main route method * * @return function */ public function import($token, $secret, $escape = '1234567890') { Argument::i()->test(1, 'string')->test(2, 'string')->test(3, 'string'); //remember this scope $self = $this; eve()->addMethod('addCaptcha', function (Registry $request, Registry $response, array $meta) use($token, $self) { //we already checked the captcha it's good //we just need to check if it's set if (isset($meta['check_captcha']) && $meta['check_captcha'] && !$request->isKey('get', 'g-recaptcha-response') && !$request->isKey('post', 'g-recaptcha-response')) { //let the action handle the rest $request->set('valid_captcha', false); } //set captcha if (isset($route['make_captcha']) && $meta['make_captcha']) { $request->set('captcha', $token); } }); //You can add validators here return function (Registry $request, Registry $response) use($secret, $escape, $self) { $request->set('valid_captcha', true); //CAPTCHA - whether or not we are expecting it lets do a check $captcha = false; if ($request->isKey('get', 'g-recaptcha-response')) { $captcha = $request->get('get', 'g-recaptcha-response'); } else { if ($request->isKey('post', 'g-recaptcha-response')) { $captcha = $request->get('post', 'g-recaptcha-response'); } } if ($captcha !== false && $captcha !== $escape) { $result = eden('curl')->setUrl('https://www.google.com/recaptcha/api/siteverify')->verifyHost(false)->verifyPeer(false)->setPostFields(http_build_query(array('secret' => $secret, 'response' => $captcha)))->getJsonResponse(); //let the action handle the rest $request->set('valid_captcha', $result['success']); } }; }
/** * send email template * * @param string * @param array * @param array */ protected function sendEmail($subject, $to, $vars) { //set email account $smtp = eden('mail')->smtp('smtp.gmail.com', self::EMAIL, self::PASSWORD, 465, true); //parse the template with its variables $message = control()->template($this->emailTemp, $vars); //now send the parsed message to the user's email $smtp->setSubject($subject)->setBody($message, true); foreach ($to as $email) { $smtp->addTo($email); } return $smtp->send(); }
if ($getUser->num_rows == 0) { //new user if (!isset($_SESSION['access_token'], $_SESSION['access_secret'])) { if (!isset($_SESSION['request_secret'])) { $token = $auth->getRequestToken(); $_SESSION['request_secret'] = $token['oauth_token_secret']; $login = $auth->getLoginUrl($token['oauth_token'], 'http://goo.gl'); $_SESSION['twitter_login'] = $login; } if (isset($_GET['oauth_token'], $_GET['oauth_verifier'])) { $token = $auth->getAccessToken($_GET['oauth_token'], $_SESSION['request_secret'], $_GET['oauth_verifier']); $_SESSION['access_token'] = $token['oauth_token']; $_SESSION['access_secret'] = $token['oauth_token_secret']; $user_token = $_SESSION['access_token']; $user_secret = $_SESSION['access_secret']; $users = eden('twitter')->users(TWITTER_TOKEN, TWITTER_SECRET, $user_token, $user_secret); $user_info = $users->getCredentials(); $username = $user_info['screen_name']; $oauth_id = $user_info['id']; //newly connected twitter account $db->query("\n\t\t\t\tINSERT INTO tbl_oauth SET oauth_token = '{$user_token}', \n\t\t\t\toauth_secret = '{$user_secret}', oauth_id = '{$oauth_id}', provider = 'twitter',\n\t\t\t\tuser_id = '{$user_id}', username = '******'\n\t\t\t"); unset($_SESSION['request_secret']); } } } else { $user_data = $getUser->fetch_object(); $_SESSION['access_token'] = $user_data->oauth_token; $_SESSION['access_secret'] = $user_data->oauth_secret; } ?> <body>
/** * Returns a generated slug, considering duplicates * * @param string * @return string */ public function getSlug($name) { $slug = (string) eden('type', $name)->dasherize(); $join = $filter = $sort = array(); //SELECT * FROM `post` WHERE post_slug RLIKE '^test\-title\-[0-9]+$' ORDER BY post_slug DESC $filter[] = array('user_slug=%s OR user_slug RLIKE %s', $slug, '^' . str_replace('-', '\\-', $slug) . '-[0-9]+$'); $sort = array('user_id' => 'DESC'); $user = $this->_database->getRows('user', $join, $filter, $sort, 0, 1, 0); if (empty($user)) { return $slug; } $count = substr($user['user_slug'], strlen($slug) + 1); $slug .= '-' . (is_numeric($count) ? $count + 1 : 1); return $slug; }
public function testWhen() { $test = 'Good'; eden()->when(function () { return false; }, function () use(&$test) { $test = 'Bad'; }); $this->assertSame('Good', $test); $test = 'Good'; eden()->when(null, function () use(&$test) { $test = 'Bad'; }); $this->assertSame('Good', $test); $test = 'Good'; eden()->when(false, function () use(&$test) { $test = 'Bad'; }); $this->assertSame('Good', $test); $test = 'Good'; eden()->when(function () { return true; }, function () use(&$test) { $test = 'Bad'; }); $this->assertSame('Bad', $test); $test = 'Good'; eden()->when('hi', function () use(&$test) { $test = 'Bad'; }); $this->assertSame('Bad', $test); $test = 'Good'; eden()->when(true, function () use(&$test) { $test = 'Bad'; }); $this->assertSame('Bad', $test); }
public function testRelease() { $route = eden('core')->route()->release('test'); $this->assertFalse($route->valid('test')); }
$app->delete('/logout', _rcc('UsersController', 'logout'))->before($auth); /** * Welcome */ //require_once ROUTES_PATH . '/gui.php'; /** * Welcome */ //require_once ROUTES_PATH . '/welcome.php'; $app->get('/mosaicoon/code.js', function () use($app) { // echo 'alert("ok google")'; // die; //return $app->stream($stream, 200, array('Content-Type' => 'application/javascript')); }); $app->get('/', function () use($app) { eden('template')->set(array('foo' => 'bar')); //die('ok'); }); //products $app->get('/products', _rcc('ProductsController', 'index')); $app->get('/products/{productId}', _rcc('ProductsController', 'find')); //TODO $app->post('/products', _rcc('ProductsController', 'create'))->before($isAdmin); // -------------------------------------------------------------------- //menu $app->get('/menu', _rcc('MenuController', 'index')); $app->get('/menu/{id}', _rcc('MenuController', 'find')); //TODO $app->post('/menu', _rcc('MenuController', 'create'))->before($isAdmin); // -------------------------------------------------------------------- //user info
public function testIterable() { $data = array('name' => 'Juan', 'surname' => 'dela cruz'); $expires = time() + 60; $path = null; $domain = 'http://openovate.com'; $secure = false; $httponly = false; $class = eden('cookie')->setData($data, $expires, $path, $domain, $secure, $httponly); foreach ($class as $key => $value) { $this->assertEquals($class->current(), $data[$key]); } }
public function testMustache() { $template = eden('handlebars')->compile('{{#foo}}{{this}}{{/foo}}'); $results = $template(array('foo' => array(1, 2, 3))); $this->assertEquals('123', $results); }
public function testSmtp() { $class = eden('mail')->smtp('smtp.gmail.com', '[EMAIL-ADDRESS]', '[PASSWORD]', 465, true); $this->assertInstanceOf('Eden\\Mail\\Smtp', $class); }
public function testRoute() { $class = eden('core')->route(); $this->assertInstanceOf('Eden\\Core\\Route', $class); }
public function testPath() { $class = eden('system')->path('/some/path'); $this->assertInstanceOf('Eden\\System\\Path', $class); }
public function testUnlisten() { $class = eden('core')->event()->unlisten('some-event'); $this->assertInstanceOf('Eden\\Core\\Event', $class); eden('core')->event()->trigger('some-event'); }
public function testWordwrap() { $string = 'Hello You'; $resultString = 'Hello<br />You'; $class = eden('string')->set($string)->wordwrap(3, '<br />'); $this->assertInstanceOf('Eden_String_Index', $class); $newString = $class->get(); $this->assertEquals($resultString, $newString); $class = eden('string')->set($string)->wordwrap(3, '<br />'); $this->assertInstanceOf('Eden_String_Index', $class); $newString = $class->get(); $this->assertEquals($resultString, $newString); }
public function testRegisterPartial() { //basic Eden\Handlebars\Runtime::registerPartial('foo', 'This is {{ foo }}'); Eden\Handlebars\Runtime::registerPartial('bar', 'Foo is not {{ bar }}'); $template = eden('handlebars')->compile('{{> foo }} ... {{> bar }}'); $results = $template(array('foo' => 'FOO', 'bar' => 'BAR')); $this->assertEquals('This is FOO ... Foo is not BAR', $results); //with scope Eden\Handlebars\Runtime::registerPartial('foo', 'This is {{ foo }}'); Eden\Handlebars\Runtime::registerPartial('bar', 'Foo is not {{ bar }}'); $template = eden('handlebars')->compile('{{> foo }} ... {{> bar zoo}}'); $results = $template(array('foo' => 'FOO', 'bar' => 'BAR', 'zoo' => array('bar' => 'ZOO'))); $this->assertEquals('This is FOO ... Foo is not ZOO', $results); //with attributes Eden\Handlebars\Runtime::registerPartial('foo', 'This is {{ foo }}'); Eden\Handlebars\Runtime::registerPartial('bar', 'Foo is not {{ something }}'); $template = eden('handlebars')->compile('{{> foo }} ... {{> bar zoo something="Amazing"}}'); $results = $template(array('foo' => 'FOO', 'bar' => 'BAR', 'zoo' => array('bar' => 'ZOO'))); $this->assertEquals('This is FOO ... Foo is not Amazing', $results); }
public function setUp() { date_default_timezone_set('GMT'); $this->imap = eden('mail')->imap('imap.gmail.com', '[EMAIL-ADDRESS]', '[PASSWORD]', 993, true); }
public function testTruncate() { $path = __DIR__ . '/../assets/foobar2'; eden('system')->folder($path)->create(0777); eden('system')->folder($path . '/subfolder2')->create(0777); eden('system')->file($path . '/file1.txt')->touch(); eden('system')->file($path . '/2files.txt')->touch(); eden('system')->file($path . '/file3.txt')->touch(); eden('system')->folder($path)->truncate(); $this->assertFalse(is_dir($path . '/subfolder2')); $this->assertFalse(file_exists($path . '/2files.txt')); eden('system')->folder($path)->remove(); }
public function testGetString() { $class = eden('type')->getString('some data'); $this->assertInstanceOf('Eden\\Type\\StringType', $class); }
public function testSetTimezone() { $class = eden()->setTimezone('GMT'); $this->assertInstanceOf('Eden\\Core\\Controller', $class); }
public function testUnregisterPartial() { $instance = eden('handlebars')->registerPartial('foo', 'bar')->unregisterPartial('foo'); $this->assertInstanceOf('Eden\\Handlebars\\Index', $instance); $this->assertNull($instance->getPartial('foo')); }
public function test_usort() { $test = eden('array')->set(1, 2, 0)->usort(function ($value1, $value2) { if ($value1 === $value2) { return 0; } return $value1 > $value2 ? 1 : -1; })->get(); $this->assertEquals(0, $test[0]); $this->assertEquals(1, $test[1]); $this->assertEquals(2, $test[2]); }