public function testMessageTranslated() { $validator = new LogLevel(); $validator->setTranslator(\Library\Application::init('Library', true)->getServiceManager()->get('MvcTranslator')); $validator->isValid('Error'); $this->assertEquals(array(LogLevel::LOG_LEVEL => "'Error' ist kein gültiger Loglevel"), $validator->getMessages()); }
/** * Test route matches against various URIs */ public function testRouter() { $application = \Library\Application::init('Console', true); $router = $application->getServiceManager()->get('HttpRouter'); $request = new \Zend\Http\Request(); $matchDefaultDefault = array('controller' => 'client', 'action' => 'index'); $matchControllerDefault = array('controller' => 'controllername', 'action' => 'index'); $matchControllerAction = array('controller' => 'controllername', 'action' => 'actionname'); $request->setUri('/'); $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams()); $request->setUri('/controllername'); $this->assertEquals($matchControllerDefault, $router->match($request)->getParams()); $request->setUri('/controllername/'); $this->assertEquals($matchControllerDefault, $router->match($request)->getParams()); $request->setUri('/controllername/actionname'); $this->assertEquals($matchControllerAction, $router->match($request)->getParams()); $request->setUri('/controllername/actionname/'); $this->assertEquals($matchControllerAction, $router->match($request)->getParams()); $request->setUri('/controllername/actionname/invalid'); $this->assertNull($router->match($request)); $request->setUri('/console'); $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams()); $request->setUri('/console/'); $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams()); $request->setUri('/console/controllername'); $this->assertEquals($matchControllerDefault, $router->match($request)->getParams()); $request->setUri('/console/controllername/'); $this->assertEquals($matchControllerDefault, $router->match($request)->getParams()); $request->setUri('/console/controllername/actionname'); $this->assertEquals($matchControllerAction, $router->match($request)->getParams()); $request->setUri('/console/controllername/actionname/'); $this->assertEquals($matchControllerAction, $router->match($request)->getParams()); $request->setUri('/console/controllername/actionname/invalid'); $this->assertNull($router->match($request)); }
/** * @dataProvider missingTranslationProvider */ public function testMissingTranslationDoesNotTriggerNoticeWhenDisabled($locale) { \Locale::setDefault($locale); $application = \Library\Application::init('Library', true, array('Library\\UserConfig' => array('debug' => array('report missing translations' => false)))); $translator = $application->getServiceManager()->get('MvcTranslator'); $this->assertEquals('this_string_is_not_translated', $translator->translate('this_string_is_not_translated')); }
/** * Create a new view renderer * * @return \Zend\View\Renderer\PhpRenderer */ protected function _createView() { $application = \Library\Application::init('Console', true); $view = new \Zend\View\Renderer\PhpRenderer(); $view->setHelperPluginManager($application->getServiceManager()->get('ViewHelperManager')); return $view; }
public function testMessageTranslated() { $validator = new ProductKey(); $validator->setTranslator(\Library\Application::init('Library', true)->getServiceManager()->get('MvcTranslator')); $validator->isValid('invalid'); $this->assertEquals(array(ProductKey::PRODUCT_KEY => "'invalid' ist kein gültiger Lizenzschlüssel"), $validator->getMessages()); }
public function testNoTranslatorForEnglishLocale() { // Preserve state if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } // Repeat application initialization with english locale $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en_UK'; \Library\Application::init('Library', false); // Invoke translator with untranslatable string - must not trigger notice $translator = \Library\Application::getService('MvcTranslator')->getTranslator(); $message = $translator->translate('this_string_is_not_translated'); // Reset application state ASAP. if (isset($language)) { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $language; } else { unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); } \Library\Application::init('Library', false); $this->assertEquals('this_string_is_not_translated', $message); // No translations should be loaded $reflectionObject = new \ReflectionObject($translator); $reflectionProperty = $reflectionObject->getProperty('files'); $reflectionProperty->setAccessible(true); $this->assertSame(array(), $reflectionProperty->getValue($translator)); }
/** * Test service */ public function testLoggerService() { $application = \Library\Application::init('Library', true); $logger = $application->getServiceManager()->get('Library\\Logger'); $this->assertInstanceOf('\\Zend\\Log\\Logger', $logger); // Log a message. The NULL writer should be attached so that no // exception should be thrown. $logger->debug('test'); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); $helperClass = static::_getHelperClass(); $moduleName = substr($helperClass, 0, strpos($helperClass, '\\')); $application = \Library\Application::init($moduleName, true); static::$_serviceManager = $application->getServiceManager(); static::$_helperManager = static::$_serviceManager->get('ViewHelperManager'); }
public function setUp() { $this->_authService = $this->createMock('Model\\Operator\\AuthenticationService'); $application = \Library\Application::init('Console', true); $serviceManager = $application->getServiceManager(); $serviceManager->setService('Zend\\Authentication\\AuthenticationService', $this->_authService); $this->_view = new \Zend\View\Renderer\PhpRenderer(); $this->_view->setHelperPluginManager($serviceManager->get('ViewHelperManager')); $this->_view->setResolver(new \Zend\View\Resolver\TemplateMapResolver(array('layout' => \Console\Module::getPath('views/layout/layout.php')))); }
public function testService() { $application = \Library\Application::init('Library', true); $serviceManager = $application->getServiceManager(); // Service must not be shared so that a different result is returned // each time. $now1 = $serviceManager->get('Library\\Now'); sleep(1); $now2 = $serviceManager->get('Library\\Now'); $this->assertGreaterThan($now1->getTimestamp(), $now2->getTimestamp()); }
public function testDefaultTranslator() { $translator = $this->createMock('Zend\\Mvc\\I18n\\Translator'); $application = \Library\Application::init('Console', true); // Run test initializion after application initialization because it // would be overwritten otherwise \Zend\Validator\AbstractValidator::setDefaultTranslator(null); $serviceManager = $application->getServiceManager(); $serviceManager->setAllowOverride(true); $serviceManager->setService('MvcTranslator', $translator); // Invoke bootstrap event handler manually. It has already been run // during application initialization, but we changed the default // translator in the meantime. (new \Console\Module())->onBootstrap($application->getMvcEvent()); $this->assertSame($translator, \Zend\Validator\AbstractValidator::getDefaultTranslator()); }
public function testInvokeWithConsoleForm() { $plugin = $this->_getPlugin(false); // Set up \Console\Form\Form using default renderer $form = $this->createMock('Console\\Form\\Form'); $form->expects($this->once())->method('render')->will($this->returnValue('\\Console\\Form\\Form default renderer')); // Evaluate plugin return value $viewModel = $plugin($form); $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $viewModel); $this->assertEquals('plugin/PrintForm.php', $viewModel->getTemplate()); $this->assertEquals($form, $viewModel->form); // Invoke template and test output $application = \Library\Application::init('Console', true); $renderer = $application->getServiceManager()->get('ViewRenderer'); $output = $renderer->render($viewModel); $this->assertEquals('\\Console\\Form\\Form default renderer', $output); }
<?php /** * Bootstrap for unit tests * * Copyright (C) 2011-2016 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); date_default_timezone_set('Europe/Berlin'); \Library\Application::init('Protocol', true);
<?php /** * Bootstrap for unit tests * * Copyright (C) 2011-2015 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); date_default_timezone_set('Europe/Berlin'); require_once __DIR__ . '/../../Library/Application.php'; \Library\Application::init('Protocol', false);
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ namespace Library; error_reporting(-1); date_default_timezone_set('Europe/Berlin'); \Locale::setDefault('de'); /** * A minimal stream wrapper to simulate I/O errors * * No stream methods are implemented except stream_open() (so that a stream can * be opened) and stream_eof() (which always returns FALSE to distinct a read * error from a normal EOF). Every other method will cause the calling stream * function to fail, allowing testing the error handling in the application. */ // @codingStandardsIgnoreStart class StreamWrapperFail { public function stream_open($path, $mode, $options, &$openedPath) { return true; } public function stream_eof() { return false; } } // @codingStandardsIgnoreEnd stream_wrapper_register('fail', 'Library\\StreamWrapperFail'); \Library\Application::init('Library', true);
<?php /** * Bootstrap for unit tests * * Copyright (C) 2011-2016 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); date_default_timezone_set('Europe/Berlin'); $application = \Library\Application::init('Database', true, array('Library\\UserConfig' => array('database' => json_decode(getenv('BRAINTACLE_TEST_DATABASE'), true)))); \Database\Test\Table\AbstractTest::$serviceManager = $application->getServiceManager(); unset($application);
<?php /** * Bootstrap for unit tests * * Copyright (C) 2011-2015 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); require_once __DIR__ . '/../../Library/Application.php'; \Library\Application::init('PackageBuilder', false);
/** * Bootstrap for unit tests * * Copyright (C) 2011-2015 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); ini_set('memory_limit', '300M'); date_default_timezone_set('Europe/Berlin'); require_once __DIR__ . '/../../../Library/Application.php'; require_once 'Zend/Console/Console.php'; // Pretend to be not on a console to force choice of HTTP route over console route. \Zend\Console\Console::overrideIsConsole(false); \Library\Application::init('Console', false); \Locale::setDefault('de_DE'); // Force environment-independent locale // Get absolute path to vfsStream library \Zend\Loader\AutoloaderFactory::factory(array('\\Zend\\Loader\\StandardAutoloader' => array('namespaces' => array('org\\bovigo\\vfs' => stream_resolve_include_path('org/bovigo/vfs')))));
public function testReadableMessageTranslated() { $url = vfsStream::newFile('test', 00)->at($this->_root)->url(); $validator = new FileReadable(); $validator->setTranslator(\Library\Application::init('Library', true)->getServiceManager()->get('MvcTranslator')); $validator->isValid($url); $this->assertEquals(array(FileReadable::READABLE => "Datei '{$url}' ist nicht lesbar"), $validator->getMessages()); }
<?php /** * Bootstrap for unit tests * * Copyright (C) 2011-2015 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); date_default_timezone_set('Europe/Berlin'); require_once 'Nada.php'; require_once __DIR__ . '/../../Library/Application.php'; \Library\Application::init('Database', false);
/** * All interaction with the user agent starts with this script. * * Copyright (C) 2011-2015 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Set up PHP environment. The error configuration is done as early as possible. error_reporting(-1); require_once '../module/Library/Application.php'; if (\Library\Application::isProduction()) { ini_set('display_errors', false); ini_set('display_startup_errors', false); } else { ini_set('display_errors', true); ini_set('display_startup_errors', true); } \Library\Application::init('Console');
public function testWritableMessageTranslated() { $url = vfsStream::newDirectory('test', 00)->at($this->_root)->url(); $validator = new DirectoryWritable(); $validator->setTranslator(\Library\Application::init('Library', true)->getServiceManager()->get('MvcTranslator')); $validator->isValid($url); $this->assertEquals(array(DirectoryWritable::WRITABLE => "Verzeichnis '{$url}' ist nicht schreibbar"), $validator->getMessages()); }
* this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); date_default_timezone_set('Europe/Berlin'); /** * A minimal stream wrapper to simulate I/O errors * * No stream methods are implemented except stream_open() (so that a stream can * be opened) and stream_eof() (which always returns FALSE to distinct a read * error from a normal EOF). Every other method will cause the calling stream * function to fail, allowing testing the error handling in the application. */ class StreamWrapperFail { public function stream_open($path, $mode, $options, &$openedPath) { return true; } public function stream_eof() { return false; } } stream_wrapper_register('fail', 'StreamWrapperFail'); require_once __DIR__ . '/../../Library/Application.php'; \Library\Application::init('Library', false); \Locale::setDefault('de_DE'); // Force environment-independent locale // Get absolute path to vfsStream library \Zend\Loader\AutoloaderFactory::factory(array('\\Zend\\Loader\\StandardAutoloader' => array('namespaces' => array('org\\bovigo\\vfs' => stream_resolve_include_path('org/bovigo/vfs')))));
<?php /** * Bootstrap for unit tests * * Copyright (C) 2011-2016 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); ini_set('memory_limit', '350M'); date_default_timezone_set('Europe/Berlin'); \Locale::setDefault('de'); // Pretend to be not on a console to force choice of HTTP route over console route. \Zend\Console\Console::overrideIsConsole(false); \Library\Application::init('Console', true); // Required to set up autoloaders for some test classes
* Export all clients as XML * * Copyright (C) 2011-2015 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * @package Tools */ error_reporting(-1); // Only set 1 of these options to prevent duplicate messages on the console ini_set('display_errors', true); ini_set('log_errors', false); if (extension_loaded('xdebug')) { xdebug_disable(); // Prevents printing backtraces on validation errors } require_once __DIR__ . '/../module/Library/Application.php'; \Library\Application::init('Export');
public static function setUpBeforeClass() { $module = strtok(get_called_class(), '\\'); $application = \Library\Application::init($module, true); static::$_serviceManager = $application->getServiceManager(); }
* any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); date_default_timezone_set('Europe/Berlin'); /** * A minimal stream wrapper to simulate I/O errors * * Only url_stat() is (partially) implemented to simulate file properties. * Files cannot be actually opened. */ class StreamWrapperStatOnly { public function url_stat($path, $flags) { return array('size' => 42); } } stream_wrapper_register('statonly', 'StreamWrapperStatOnly'); require_once __DIR__ . '/../../Library/Application.php'; \Library\Application::init('Model', false); // Get absolute path to vfsStream library \Zend\Loader\AutoloaderFactory::factory(array('\\Zend\\Loader\\StandardAutoloader' => array('namespaces' => array('org\\bovigo\\vfs' => stream_resolve_include_path('org/bovigo/vfs')))));
<?php /** * Bootstrap for unit tests * * Copyright (C) 2011-2015 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); require_once __DIR__ . '/../../Library/Application.php'; \Library\Application::init('DatabaseManager', false);
public static function setUpBeforeClass() { $application = \Library\Application::init('Protocol', true); static::$_serviceManager = $application->getServiceManager(); }
* This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * @package Tools */ /** * This script creates a package from the command line. This is useful if a file * is too big to be uploaded to the webserver. It can also be used as part of a * package builder script. * * It is limited to the package builder defaults. Only the name and the file * itself can be specified. * * Don't forget to change permissions/ownership of the generated directory and * files. Otherwise the webserver won't be able to read and/or delete them. */ error_reporting(E_ALL); require __DIR__ . '/../vendor/autoload.php'; \Library\Application::init('PackageBuilder')->run();