public function testThemeConstruct() { $path = realpath(dirname(__FILE__) . '/../../../'); $path_r = explode(DIRECTORY_SEPARATOR, $path); $app = $this->getApp(); $this->assertEquals(FileHelper::replaceSeparators('vfs://root/public/'), FileHelper::replaceSeparators($app->getTheme()->getBasePath())); unsetRealpath(); }
public function testResizedWithoutMaxOnly() { unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'stretched.jpg'); $originalPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'original.jpg'; $path = ImageProcessor::resize($originalPath, array('maxOnly' => false, 'w' => 1500, 'resultDir' => dirname(__FILE__) . DIRECTORY_SEPARATOR, 'outputFilename' => 'stretched.jpg')); $imagesize = getimagesize($path); $this->assertEquals(1500, $imagesize[0]); $this->assertEquals(FileHelper::replaceSeparators(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'stretched.jpg'), $path); }
public function testPackCommand() { $app = __setupApp(); $console = new Console($app, true); $packedPath = FileHelper::replaceSeparators(realpath(__DIR__ . '/packerTest/packed.js')); if (file_exists($packedPath)) { unlink($packedPath); } $this->assertFalse(file_exists($packedPath)); ob_get_clean(); ob_start(); $output = $console->run("skully:pack Commands/packerTest/packerTest.txt"); // Cannot test this on Windows somehow, so just check if pack command is running. $this->assertNotEmpty($output); }
function S3ProcessTempImage($tmp, $options, $oldFile = '') { $path = $this->parentProcessTempImage($tmp, $options, $oldFile); $key = S3Helpers::key($this->app->config('publicDir'), $path); $amazonS3Config = $this->app->config('amazonS3'); $client = S3Client::factory($amazonS3Config['settings']); $abspath = FileHelper::replaceSeparators($this->app->getTheme()->getBasePath() . $path); $client->putObject(array('Bucket' => $amazonS3Config['bucket'], 'Key' => $key, 'SourceFile' => $abspath, 'ACL' => 'public-read')); $client->waitUntil('ObjectExists', array('Bucket' => $amazonS3Config['bucket'], 'Key' => $key)); unlink($abspath); // Delete Old File if (!empty($oldFile)) { $relativeOldFile = str_replace($this->app->getTheme()->getPublicBasePath(), '', $oldFile); $oldKey = S3Helpers::key($this->app->config('publicDir'), $relativeOldFile); $client->deleteObject(array('Bucket' => $amazonS3Config['bucket'], 'Key' => $oldKey)); } return $path; }
public function testLoadDefaultTheme() { $app = $this->getApp(); $this->assertTrue(file_exists('vfs://root/public/test/App/')); $this->assertEquals(FileHelper::replaceSeparators('vfs://root/public/test/App/'), $app->getTheme()->getAppPath('')); $this->assertEquals(FileHelper::replaceSeparators('vfs://root/public/test/'), $app->getTheme()->getPath('')); $this->assertEquals(FileHelper::replaceSeparators('vfs://root/public/default/App/views/home/index.tpl'), $app->getTheme()->getAppPath(FileHelper::replaceSeparators('views/home/index.tpl'))); $this->assertEquals(FileHelper::replaceSeparators('vfs://root/public/test/App/views/admin/home/index.tpl'), $app->getTheme()->getAppPath(FileHelper::replaceSeparators('views/admin/home/index.tpl'))); /**@var Controller $controller **/ $controller = new \App\Controllers\HomeController($app, 'index'); $this->assertEquals('This is app default home', $controller->fetch('/home/index')); ob_start(); $controller->render(); $output = ob_get_clean(); $this->assertEquals('This is app default home', $output); $controller = new \App\Controllers\Admin\HomeController($app, 'index'); $this->assertEquals('This is app test admin home', $controller->fetch()); unsetRealpath(); }
public function testUploadFile() { $this->migrate(); $this->login(); // Preparation: Create an image entry. $image = $this->app->createModel('image', array('position' => 0)); R::store($image); $this->assertNotEmpty($image->getID()); // upload to aws s3 $filename = 'original.jpg'; $filepath = realpath(__DIR__ . '/' . $filename); $_SERVER['REQUEST_METHOD'] = "POST"; $params = array('image_id' => $image->getID(), 'data' => '{ "id": ' . $image->getID() . ', "type": "uploadOnce", "settingName": "multiple_many_types" }', 'settingName' => 'multiple_many_types', 'uploadOnce' => 1); $size = filesize($filepath); $_FILES = array('file-0' => array('name' => $filename, 'type' => 'image/jpeg', 'tmp_name' => $filepath, 'error' => 0, 'size' => $size)); ob_start(); $this->app->runControllerFromRawUrl('admin/cRUDImages/uploadImage', $params); $output = ob_get_clean(); echo "\nOutput of uploadImage:\n"; echo $output; $output_r = json_decode($output); print_r($output_r); $this->assertFalse(property_exists($output_r[0], 'error')); // See if file uploaded successfully. echo "\nFind image with id " . $image->getID(); $imageBean = R::findOne('image', 'id = ?', array($image->getID())); $this->assertNotEmpty($imageBean); echo "\n...Found!"; $data = json_decode($imageBean['multiple_many_types']); echo "\nUploaded images:\n"; print_r($data); $this->assertEquals(1, count($data)); // Uploaded data must contain 'images/Image/1/original-smartphone' $this->assertNotEquals(-1, strpos(SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone), 'public/images/Image/' . $image->getID() . '/original-smartphone')); // Now see if file does exist in Amazon S3 repository. $amazonS3Config = $this->app->config('amazonS3'); $client = \Aws\S3\S3Client::factory($amazonS3Config['settings']); $result = $client->getObject(array('Bucket' => $amazonS3Config['bucket'], 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone))); $this->assertNotEmpty($result['Body']); // $this->app->getLogger()->log("result get object : " . print_r($result, true)); // TEST ACL $resultAcl = $client->getObjectAcl(array('Bucket' => $amazonS3Config['bucket'], 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone))); // $this->app->getLogger()->log("result get object ACL : " . print_r($resultAcl, true)); $this->assertNotEmpty($resultAcl["Grants"]); $dataAcl = array(); foreach (\Aws\S3\Model\Acp::fromArray($resultAcl->toArray()) as $grant) { $grantee = $grant->getGrantee(); $dataAcl[$grantee->getGroupUri()] = array($grantee->getType(), $grant->getPermission()); } $this->assertEquals(2, count($dataAcl)); $this->assertArrayHasKey('http://acs.amazonaws.com/groups/global/AllUsers', $dataAcl); $this->assertEquals(array('Group', 'READ'), $dataAcl['http://acs.amazonaws.com/groups/global/AllUsers']); // ---- end of test ACL ---- // Local file must have been deleted. $filepath = \Skully\App\Helpers\FileHelper::replaceSeparators($this->app->getTheme()->getBasePath() . $data[0]->smartphone); echo "\nChecking if file {$filepath} is deleted..."; $this->assertFalse(file_exists($filepath)); echo "\nYep"; // Delete Models try { R::trash($imageBean); } catch (\Exception $e) { echo 'failed to delete image bean. reason: ' . $e->getMessage(); } // // Cleanup by removing files in bucket. // $client->deleteObject(array( // 'Bucket' => $amazonS3Config['bucket'], // 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone)) // ); // // $client->deleteObject(array( // 'Bucket' => $amazonS3Config['bucket'], // 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->desktop)) // ); // Check existence of deleted files on s3 server $result = $client->doesObjectExist($amazonS3Config['bucket'], SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone)); $this->assertFalse($result); $result = $client->doesObjectExist($amazonS3Config['bucket'], SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->desktop)); $this->assertFalse($result); }
public function testSSL() { $app = $this->getApp(); $this->assertEquals(realpath(dirname(__FILE__)), $app->getRealpath(dirname(__FILE__))); $appHomeDir = FileHelper::replaceSeparators(__DIR__ . '/App/public/default/App/views/home'); file_put_contents(FileHelper::replaceSeparators($appHomeDir . '/ssl.tpl'), '{public_url value="test"}'); ob_start(); $_SERVER['HTTPS'] = true; $app->runControllerFromRawUrl('/home/ssl'); $_SERVER['HTTPS'] = false; $output = ob_get_clean(); $this->assertEquals('https://localhost/skully/public/?value=test', $output); file_put_contents(FileHelper::replaceSeparators($appHomeDir . '/ssl1.tpl'), '{public_url value="test" __ssl=true}'); ob_start(); $app->runControllerFromRawUrl('/home/ssl1'); $output = ob_get_clean(); $this->assertEquals('https://localhost/skully/public/?value=test', $output); file_put_contents(FileHelper::replaceSeparators($appHomeDir . '/ssl2.tpl'), '{theme_url value="test"}'); ob_start(); $_SERVER['HTTPS'] = true; $app->runControllerFromRawUrl('/home/ssl2'); $_SERVER['HTTPS'] = false; $output = ob_get_clean(); $this->assertEquals('https://localhost/skully/public/default/?value=test', $output); file_put_contents(FileHelper::replaceSeparators($appHomeDir . '/ssl3.tpl'), '{theme_url value="test" __ssl=true}'); ob_start(); $app->runControllerFromRawUrl('/home/ssl3'); $output = ob_get_clean(); $this->assertEquals('https://localhost/skully/public/default/?value=test', $output); /** * Testing SSL with url() function. */ file_put_contents(FileHelper::replaceSeparators($appHomeDir . '/ssl4.tpl'), '{url path="home/ssltest"}'); ob_start(); $_SERVER['HTTPS'] = true; $app->runControllerFromRawUrl('/home/ssl4'); $_SERVER['HTTPS'] = false; $output = ob_get_clean(); $this->assertEquals('https://localhost/skully/home/ssltest', $output); // If pointing to other site, do not attempt to change http. file_put_contents(FileHelper::replaceSeparators($appHomeDir . '/ssl5.tpl'), '{url path="http://teguhwijaya.com"}'); ob_start(); $_SERVER['HTTPS'] = true; $app->runControllerFromRawUrl('/home/ssl5'); $_SERVER['HTTPS'] = false; $output = ob_get_clean(); $this->assertEquals('http://teguhwijaya.com', $output); }
<?php namespace Tests; use RedBeanPHP\Facade as R; use Skully\App\Helpers\FileHelper; require_once FileHelper::replaceSeparators(dirname(__FILE__) . '/DatabaseTestCase.php'); class ModelTest extends \Tests\DatabaseTestCase { /** * Cant have camelcased beans * @expectedException \RedBeanPHP\RedException */ public function testTwoWordsCamelcasedBean() { R::freeze(false); $testName = R::dispense('testName'); $id = R::store($testName); R::load('testName', $id); R::freeze($this->frozen); } /** * Cant have underscored beans * @expectedException \RedBeanPHP\RedException */ public function testTwoWordsUnderscoredBean() { R::freeze(false); $testName = R::dispense('test_name'); $id = R::store($testName); R::load('test_name', $id);
/** * @param string $path * @param array $params * @param boolean $hideErrors True to hide errors from file not found. * @param boolean $ssl When true or false force to change security mode (http or https). * @throws \Skully\Exceptions\ThemeFileNotFoundException Given a path, must find that path within the themes/ directory * @return string */ public function getUrl($path = '', $params = array(), $hideErrors = false, $ssl = null) { $fullUrl = $path; $fullPath = $this->getBasePath() . $this->themeName . DIRECTORY_SEPARATOR . $path; if (!file_exists(FileHelper::replaceSeparators($fullPath))) { $fullPath = $this->getBasePath() . 'default' . DIRECTORY_SEPARATOR . $path; if (!file_exists(FileHelper::replaceSeparators($fullPath))) { } else { $fullUrl = $this->getPublicBaseUrl($ssl) . 'default/' . $path; } } else { $fullUrl = $this->getPublicBaseUrl($ssl) . $this->themeName . '/' . $path; } if (!file_exists(FileHelper::replaceSeparators($fullPath)) && !$hideErrors) { throw new ThemeFileNotFoundException("Theme file not found after searching at these locations: \n" . $this->getBasePath() . $this->themeName . DIRECTORY_SEPARATOR . FileHelper::replaceSeparators($path) . "\n" . $this->getBasePath() . 'default' . DIRECTORY_SEPARATOR . FileHelper::replaceSeparators($path) . "\n"); } if (empty($params)) { return $fullUrl; } else { return $fullUrl . '?' . http_build_query($params); } }
/** * @return array * Return additional pluginsDir used in template engine. * Override this as needed in the app. */ protected function additionalTemplateEnginePluginsDir() { return array(FileHelper::replaceSeparators($this->config('basePath') . $this->getAppName() . '/smarty/plugins/')); }