/**
  * HtmlHelperTest::testImageFromBlob()
  *
  * @return void
  */
 public function testImageFromBlob()
 {
     $folder = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS;
     $content = file_get_contents($folder . 'hotel.png');
     $is = $this->Html->imageFromBlob($content);
     $this->assertTrue(!empty($is));
 }
 /**
  * Return the webroot path to the image generated variant if this exist or to the controller if not.
  *
  * @param string $imagePath         Path to the original image file from webroot if absolute, or relative to img/
  * @param string|array $variantName Name of the variant configuration key or options array
  * @param array $options            options
  * @return string
  */
 public function variant($imagePath, $variantName, array $options = [])
 {
     if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
         list($plugin, $imagePath) = $this->_View->pluginSplit($imagePath, false);
     }
     $url = false;
     $imagePath = $imagePath[0] === '/' ? substr($imagePath, 1) : $imagePath;
     if (!isset($plugin)) {
         $originalFile = WWW_ROOT . $imagePath;
         $variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile);
         if (is_file($variantFile)) {
             $url = str_replace(DS, '/', str_replace(WWW_ROOT, '/', $variantFile));
         }
     } else {
         $originalFile = WWW_ROOT . Inflector::underscore($plugin) . DS . $imagePath;
         $variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile);
         if (is_file($variantFile)) {
             $url = str_replace(DS, '/', str_replace(WWW_ROOT, '/', $variantFile));
         } else {
             $originalFile = Plugin::path($plugin) . 'webroot' . DS . $imagePath;
             $variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile);
             if (is_file($variantFile)) {
                 $url = str_replace(Plugin::path($plugin) . 'webroot' . DS, '/' . Inflector::underscore($plugin) . '/', $variantFile);
                 $url = str_replace(DS, '/', $url);
             }
         }
     }
     if ($url === false) {
         $url = ['controller' => 'Presenter', 'action' => 'variant', 'plugin' => 'ImagePresenter', 'prefix' => false, '?' => ['image' => isset($plugin) ? "{$plugin}.{$imagePath}" : $imagePath, 'variant' => $variantName]];
     }
     return Router::url($url);
 }
 /**
  * @return void
  */
 public function setUp()
 {
     Configure::write('Roles', ['user' => 1, 'moderator' => 2, 'admin' => 3]);
     $this->config = ['filePath' => Plugin::path('TinyAuth') . 'tests' . DS . 'test_files' . DS, 'autoClearCache' => true];
     $this->View = new View();
     $this->AuthUserHelper = new AuthUserHelper($this->View, $this->config);
 }
 /**
  * Overrides the original method from phinx in order to return a tailored
  * Config object containing the connection details for the database.
  *
  * @return Phinx\Config\Config
  */
 public function getConfig()
 {
     if ($this->configuration) {
         return $this->configuration;
     }
     $folder = 'Migrations';
     if ($this->input->getOption('source')) {
         $folder = $this->input->getOption('source');
     }
     $dir = ROOT . DS . 'config' . DS . $folder;
     $plugin = null;
     if ($this->input->getOption('plugin')) {
         $plugin = $this->input->getOption('plugin');
         $dir = Plugin::path($plugin) . 'config' . DS . $folder;
     }
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     $plugin = $plugin ? Inflector::underscore($plugin) . '_' : '';
     $plugin = str_replace(array('\\', '/', '.'), '_', $plugin);
     $connection = 'default';
     if ($this->input->getOption('connection')) {
         $connection = $this->input->getOption('connection');
     }
     $config = ConnectionManager::config($connection);
     return $this->configuration = new Config(['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $this->getAdapterName($config['driver']), 'host' => isset($config['host']) ? $config['host'] : null, 'user' => isset($config['username']) ? $config['username'] : null, 'pass' => isset($config['password']) ? $config['password'] : null, 'port' => isset($config['port']) ? $config['port'] : null, 'name' => $config['database'], 'charset' => $config['encoding']]]]);
 }
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'BakeTemplate' . DS;
     $io = $this->getMock('Cake\\Console\\ConsoleIo', [], [], '', false);
     $this->Task = $this->getMock('Bake\\Shell\\Task\\BakeTemplateTask', ['in', 'err', 'createFile', '_stop', 'clear'], [$io]);
 }
 /**
  * Overrides the original method from phinx in order to return a tailored
  * Config object containing the connection details for the database.
  *
  * @param bool $forceRefresh
  * @return \Phinx\Config\Config
  */
 public function getConfig($forceRefresh = false)
 {
     if ($this->configuration && $forceRefresh === false) {
         return $this->configuration;
     }
     $folder = 'Migrations';
     if ($this->input->getOption('source')) {
         $folder = $this->input->getOption('source');
     }
     $dir = ROOT . DS . 'config' . DS . $folder;
     $plugin = null;
     if ($this->input->getOption('plugin')) {
         $plugin = $this->input->getOption('plugin');
         $dir = Plugin::path($plugin) . 'config' . DS . $folder;
     }
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     $plugin = $plugin ? Inflector::underscore($plugin) . '_' : '';
     $plugin = str_replace(['\\', '/', '.'], '_', $plugin);
     $connection = $this->getConnectionName($this->input);
     $connectionConfig = ConnectionManager::config($connection);
     $adapterName = $this->getAdapterName($connectionConfig['driver']);
     $config = ['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $adapterName, 'host' => isset($connectionConfig['host']) ? $connectionConfig['host'] : null, 'user' => isset($connectionConfig['username']) ? $connectionConfig['username'] : null, 'pass' => isset($connectionConfig['password']) ? $connectionConfig['password'] : null, 'port' => isset($connectionConfig['port']) ? $connectionConfig['port'] : null, 'name' => $connectionConfig['database'], 'charset' => isset($connectionConfig['encoding']) ? $connectionConfig['encoding'] : null, 'unix_socket' => isset($connectionConfig['unix_socket']) ? $connectionConfig['unix_socket'] : null]]];
     if ($adapterName === 'mysql') {
         if (!empty($connectionConfig['ssl_key']) && !empty($connectionConfig['ssl_cert'])) {
             $config['environments']['default']['mysql_attr_ssl_key'] = $connectionConfig['ssl_key'];
             $config['environments']['default']['mysql_attr_ssl_cert'] = $connectionConfig['ssl_cert'];
         }
         if (!empty($connectionConfig['ssl_ca'])) {
             $config['environments']['default']['mysql_attr_ssl_ca'] = $connectionConfig['ssl_ca'];
         }
     }
     return $this->configuration = new Config($config);
 }
 /**
  * Wrap Moxiemanager's api.php in a controller action.
  *
  * @return void
  */
 public function api()
 {
     try {
         $pluginPath = Plugin::path('CkTools');
         define('MOXMAN_CLASSES', $pluginPath . 'src/Lib/moxiemanager/classes');
         define('MOXMAN_PLUGINS', $pluginPath . 'src/Lib/moxiemanager/plugins');
         define('MOXMAN_ROOT', $pluginPath . 'src/Lib/moxiemanager');
         define('MOXMAN_API_FILE', __FILE__);
         $appConfig = Configure::read('CkTools.moxiemanager');
         Configure::load('CkTools.moxiemanager');
         $moxieManagerConfig = Configure::read('moxiemanager');
         if (is_array($appConfig)) {
             $moxieManagerConfig = Hash::merge($moxieManagerConfig, $appConfig);
         }
         $GLOBALS['moxieManagerConfig'] = $moxieManagerConfig;
         require_once MOXMAN_CLASSES . '/MOXMAN.php';
         $context = \MOXMAN_Http_Context::getCurrent();
         $pluginManager = \MOXMAN::getPluginManager();
         foreach ($pluginManager->getAll() as $plugin) {
             if ($plugin instanceof \MOXMAN_Http_IHandler) {
                 $plugin->processRequest($context);
             }
         }
     } catch (Exception $e) {
         \MOXMAN_Exception::printException($e);
     }
     return $this->render(false, false);
 }
 /**
  * setUp method
  *
  * Ensure that the default template is used
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Template' . DS;
     Configure::write('App.namespace', 'Bake\\Test\\App');
     $this->_setupTask(['in', 'err', 'error', 'createFile', '_stop']);
     TableRegistry::get('TemplateTaskComments', ['className' => __NAMESPACE__ . '\\TemplateTaskCommentsTable']);
 }
 public function icon()
 {
     $iconFile = \Cake\Core\Plugin::path('Admin') . '/config/icons.json';
     $iconJson = file_get_contents($iconFile);
     $iconArr = json_decode($iconJson, true);
     $this->viewBuilder()->autoLayout(false);
     $this->set('iconArr', $iconArr);
 }
 public function beforeFilter(Event $event)
 {
     parent::beforeFilter($event);
     if ($specific = Configure::read('Country.image_path')) {
         $this->imageFolder = WWW_ROOT . 'img' . DS . $specific . DS;
     } else {
         $this->imageFolder = Plugin::path('Data') . DS . 'webroot' . DS . 'img' . DS . 'country_flags' . DS;
     }
 }
Exemple #11
0
 /**
  * Test baking within a plugin.
  *
  * @return void
  */
 public function testBakePlugin()
 {
     $this->_loadTestPlugin('TestBake');
     $path = Plugin::path('TestBake');
     $this->Task->plugin = 'TestBake';
     $this->Task->expects($this->at(0))->method('createFile')->with($this->_normalizePath($path . 'src/Shell/Task/ExampleTask.php'), $this->logicalAnd($this->stringContains('namespace TestBake\\Shell\\Task;'), $this->stringContains('class ExampleTask extends Shell')));
     $result = $this->Task->bake('Example');
     $this->assertSameAsFile(__FUNCTION__ . '.php', $result);
 }
 /**
  * startTest
  *
  * @return void
  */
 public function setUp()
 {
     $this->Table = new VoidUploadModel();
     //		$this->Table->addBehavior('Burzum/FileStorage.UploadValidator', [
     //			'localFile' => true
     //		]);
     $this->FileUpload = $this->Table->behaviors()->UploadValidator;
     $this->testFilePath = Plugin::path('Burzum/FileStorage') . 'Test' . DS . 'Fixture' . DS . 'File' . DS;
 }
Exemple #13
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'BakeView' . DS;
     $request = new Request();
     $response = new Response();
     $this->View = new BakeView($request, $response);
     Configure::write('App.paths.templates.x', Plugin::path('Bake') . 'tests' . DS . 'test_app' . DS . 'App' . DS . 'Template' . DS);
 }
 /**
  * [setUp description]
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->resetReflectionCache();
     $this->_eventManager = EventManager::instance();
     $existing = Configure::read('App.paths.templates');
     $existing[] = Plugin::path('Crud') . 'tests/App/Template/';
     Configure::write('App.paths.templates', $existing);
 }
 /**
  * setUp
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('FileStorage.imageSizes', []);
     $this->fileFixtures = Plugin::path('Burzum/FileStorage') . 'tests' . DS . 'Fixture' . DS . 'File' . DS;
     $this->listener = $this->getMockBuilder('Burzum\\FileStorage\\Storage\\Listener\\LegacyLocalFileStorageListener')->setMethods(['storageAdapter'])->setConstructorArgs([['models' => ['Item']]])->getMock();
     $this->adapterMock = $this->getMock('\\Gaufrette\\Adapter\\Local', [], ['']);
     $this->FileStorage = TableRegistry::get('Burzum/FileStorage.FileStorage');
 }
 /**
  * testGetFileInfoFromUpload
  *
  * @return void
  */
 public function testGetFileInfoFromUpload()
 {
     $filename = Plugin::path('Burzum/FileStorage') . DS . 'tests' . DS . 'Fixture' . DS . 'File' . DS . 'titus.jpg';
     $data = new \ArrayObject(['file' => ['name' => 'titus.jpg', 'tmp_name' => $filename]]);
     $this->FileStorage->getFileInfoFromUpload($data);
     $this->assertEquals(332643, $data['filesize']);
     $this->assertEquals('image/jpeg', $data['mime_type']);
     $this->assertEquals('jpg', $data['extension']);
 }
Exemple #17
0
 /**
  * List all plugins name & version
  */
 public function index()
 {
     // Get plugins Folder
     $folders = new Folder(ROOT . DS . 'plugins');
     $folders = $folders->read();
     foreach ($folders[0] as $folder) {
         $config[] = json_decode((new File(Plugin::path($folder) . 'webroot' . DS . 'files' . DS . 'config.json'))->read());
     }
     $this->set(compact('config'));
 }
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Model' . DS;
     $io = $this->getMock('Cake\\Console\\ConsoleIo', [], [], '', false);
     $this->Task = $this->getMock('Bake\\Shell\\Task\\ModelTask', ['in', 'err', 'createFile', '_stop', '_checkUnitTest'], [$io]);
     $this->Task->connection = 'test';
     $this->_setupOtherMocks();
     TableRegistry::clear();
 }
 public function setUp()
 {
     parent::setUp();
     if ($this->isDebug()) {
         $this->CurrencyBitcoin = new CurrencyBitcoinLib();
         return;
     }
     $this->CurrencyBitcoin = $this->getMock('Data\\Lib\\CurrencyBitcoinLib', ['_get']);
     $this->path = Plugin::path('Data') . 'tests' . DS . 'test_files' . DS . 'json' . DS;
 }
 /**
  * @return void
  */
 public function testVariantWithoutExistingImage()
 {
     $file = Plugin::path('ImagePresenter') . 'webroot' . DS . 'img' . DS . 'thumbnail' . DS . 'image-1.jpg';
     if (is_file($file)) {
         unlink($file);
     }
     $result = $this->Image->variant('ImagePresenter.img/image-1.jpg', 'thumbnail');
     $expected = Router::url(['controller' => 'Presenter', 'action' => 'variant', 'plugin' => 'ImagePresenter', '?' => ['image' => 'ImagePresenter.img/image-1.jpg', 'variant' => 'thumbnail']]);
     $this->assertEquals($expected, $result);
 }
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Test' . DS;
     $this->io = $this->getMock('Cake\\Console\\ConsoleIo', [], [], '', false);
     $this->Task = $this->getMock('Bake\\Shell\\Task\\TestTask', ['in', 'err', 'createFile', '_stop', 'isLoadableClass'], [$this->io]);
     $this->Task->name = 'Test';
     $this->Task->Template = new TemplateTask($this->io);
     $this->Task->Template->interactive = false;
 }
Exemple #22
0
 /**
  * Get the migrations or seeds files path based on the current InputInterface
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input Input of the current command.
  * @param string $default Default folder to set if no source option is found in the $input param
  * @return string
  */
 protected function getOperationsPath(InputInterface $input, $default = 'Migrations')
 {
     $folder = $input->getOption('source') ?: $default;
     $dir = ROOT . DS . 'config' . DS . $folder;
     $plugin = $this->getPlugin($input);
     if ($plugin !== null) {
         $dir = Plugin::path($plugin) . 'config' . DS . $folder;
     }
     return $dir;
 }
Exemple #23
0
 /**
  * Test baking within a plugin.
  *
  * @return void
  */
 public function testBakePlugin()
 {
     $this->_loadTestPlugin('TestBake');
     $path = Plugin::path('TestBake');
     $this->Task->plugin = 'TestBake';
     $this->Task->expects($this->at(0))->method('createFile')->with($this->_normalizePath($path . 'src/Template/Cell/Example/display.ctp'), '');
     $this->Task->expects($this->at(1))->method('createFile')->with($this->_normalizePath($path . 'src/View/Cell/ExampleCell.php'), $this->stringContains('class ExampleCell extends Cell'));
     $result = $this->Task->bake('Example');
     $this->assertSameAsFile(__FUNCTION__ . '.php', $result);
 }
 protected function _publish($option)
 {
     $folderElement = new Folder(Plugin::path('TwitterBootstrap') . DS . 'src' . DS . 'Template' . DS . 'Element');
     switch ($option) {
         case 'all':
             $folderElement->copy(APP . 'Template' . DS . 'Element', false);
             break;
     }
     $this->out('Arquivos publicados');
 }
Exemple #25
0
 /**
  * Test baking within a plugin.
  *
  * @return void
  */
 public function testBakePlugin()
 {
     $this->_loadTestPlugin('TestBake');
     $path = Plugin::path('TestBake');
     $this->Task->plugin = 'TestBake';
     $this->Task->expects($this->at(0))->method('createFile')->with($this->_normalizePath($path . 'src/Template/Layout/Email/html/example.ctp'), '');
     $this->Task->expects($this->at(1))->method('createFile')->with($this->_normalizePath($path . 'src/Template/Layout/Email/text/example.ctp'), '');
     $this->Task->expects($this->at(2))->method('createFile')->with($this->_normalizePath($path . 'src/Mailer/ExampleMailer.php'), $this->stringContains('class ExampleMailer extends Mailer'));
     $result = $this->Task->bake('Example');
     $this->assertSameAsFile(__FUNCTION__ . '.php', $result);
 }
 /**
  * Get the Assets or webroot path for the provided $plugin
  * depending on whether $isAssetRequest is true or false.
  *
  * @param string $plugin The name of the plugin.
  * @param array $parts The url split by '/'.
  * @param bool $isAssetRequest Whether the request is for an asset in /src/Assets or webroot.
  * @return string
  */
 protected function _getPluginAsset($plugin, $parts, $isAssetRequest)
 {
     $fileFragment = implode(DS, $parts);
     $path = Plugin::path($plugin);
     if ($isAssetRequest) {
         $path .= 'src' . DS . 'Assets' . DS;
     } else {
         $path .= 'webroot' . DS;
     }
     return $path . $fileFragment;
 }
 /**
  * @param string|null $path
  * @return string
  */
 protected function getPath($path = null)
 {
     if ($path === null) {
         $path = ROOT . DS;
     } elseif ($path === 'core') {
         $path = CORE_PATH;
     } elseif (Plugin::loaded($path)) {
         $path = Plugin::path($path);
     }
     return $path;
 }
Exemple #28
0
 public static function suite()
 {
     $suite = new TestSuite('All CRUD action tests');
     $path = Plugin::path('Crud');
     $testPath = $path . '/tests/TestCase';
     if (!is_dir($testPath)) {
         return $suite;
     }
     $suite->addTestDirectoryRecursive($testPath . '/Action');
     return $suite;
 }
Exemple #29
0
 public static function suite()
 {
     $suite = new TestSuite('All CRUD listener tests');
     $path = Plugin::path('Crud');
     $testPath = $path . DS . 'tests' . DS . 'TestCase';
     if (!is_dir($testPath)) {
         return $suite;
     }
     $suite->addTestDirectoryRecursive($testPath . DS . 'Listener');
     return $suite;
 }
 /**
  * setup method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->_compareBasePath = Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Migration' . DS;
     $inputOutput = $this->getMock('Cake\\Console\\ConsoleIo', [], [], '', false);
     $this->Task = $this->getMock('Migrations\\Shell\\Task\\MigrationSnapshotTask', ['in', 'err', 'dispatchShell', '_stop'], [$inputOutput]);
     $this->Task->name = 'Migration';
     $this->Task->connection = 'test';
     $this->Task->BakeTemplate = new BakeTemplateTask($inputOutput);
     $this->Task->BakeTemplate->initialize();
     $this->Task->BakeTemplate->interactive = false;
 }