public static function EndLog(\Library\Application $app, $type) { $logs = Logger::GetLogs($app->user()); $log = $logs[$type][$app->HttpRequest()->requestID()]; $log->setLog_end(Logger::GetTime()); $log->setLog_execution_time(($log->log_end - $log->log_start()) * 1000); $log->setLog_start(gmdate("Y-m-d H:i:s", $log->log_start())); $log->setLog_end(gmdate("Y-m-d H:i:s", $log->log_end())); Logger::AddLogToDatabase($app, $log); Logger::StoreLogs($app->user(), $logs); }
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)); }
public function run() { /*if(!$this->user->isAuthenticated()) $this->controller = new \Tipe\Modules\Connexion\ConnexionController($this,'Connexion','connexion'); */ parent::run(); }
/** * 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)); }
public static function setUpBeforeClass() { // This table must exist before the view can be created \Library\Application::getService('Database\\Table\\ClientsAndGroups')->setSchema(); \Library\Application::getService('Database\\Table\\WindowsProductKeys')->setSchema(); parent::setUpBeforeClass(); }
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()); }
public static function setUpBeforeClass() { // GroupInfo initialization depends on Config table $config = \Library\Application::getService('Database\\Table\\Config'); $config->setSchema(); parent::setUpBeforeClass(); }
/** * 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; }
/** * Test if the helper is properly registered with the service manager */ public function testHelperInterface() { // Test if the helper is registered with the application's service manager $this->assertTrue(\Library\Application::getService('ViewHelperManager')->has($this->_getHelperName())); // Get helper instance through service manager and test for required interface $this->assertInstanceOf('Zend\\View\\Helper\\HelperInterface', $this->_getHelper()); }
/** * @dataProvider findProvider */ public function testFind($criteria, $order, $direction, $clearBlacklist, $expectedOrder, $expectedResult) { if ($clearBlacklist) { \Library\Application::getService('Database\\Table\\DuplicateMacAddresses')->delete(true); \Library\Application::getService('Database\\Table\\DuplicateSerials')->delete(true); \Library\Application::getService('Database\\Table\\DuplicateAssetTags')->delete(true); } $ordercolumns = array('Id' => 'clients.id', 'Name' => 'clients.name', 'NetworkInterface.MacAddress' => 'networkinterface_macaddr'); $sql = new \Zend\Db\Sql\Sql(\Library\Application::getService('Db'), 'clients'); $select = $sql->select()->columns(array('id', 'name', 'lastcome', 'ssn', 'assettag'))->order(array($ordercolumns[$order] => $direction)); $clientManager = $this->getMockBuilder('Model\\Client\\ClientManager')->disableOriginalConstructor()->getMock(); $clientManager->method('getClients')->with(array('Id', 'Name', 'LastContactDate', 'Serial', 'AssetTag'), $order, $direction, null, null, null, null, false, false, false)->willReturn($select); $clients = $this->getMockBuilder('Database\\Table\\Clients')->disableOriginalConstructor()->setMethods(array('getSql', 'selectWith'))->getMock(); $clients->method('getSql')->willReturn($sql); $clients->method('selectWith')->with($this->callback(function ($select) use($expectedOrder) { return $select->getRawState($select::ORDER) == $expectedOrder; }))->willReturnCallback(function ($select) use($sql) { // Build simple result set to bypass hydrator $resultSet = new \Zend\Db\ResultSet\ResultSet(); $resultSet->initialize($sql->prepareStatementForSqlObject($select)->execute()); return $resultSet; }); $duplicates = $this->_getModel(array('Database\\Table\\Clients' => $clients, 'Model\\Client\\ClientManager' => $clientManager)); $resultSet = $duplicates->find($criteria, $order, $direction); $this->assertInstanceOf('Zend\\Db\\ResultSet\\AbstractResultSet', $resultSet); $this->assertEquals($expectedResult, $resultSet->toArray()); }
/** * Set attributes from given package * * Attributes are populated with values from the given package and * hardcoded defaults. * * @param array $data Package data */ public function setPackageData($data) { $node = $this->createElement('DOWNLOAD'); $node->setAttribute('ID', $data['Id']); $node->setAttribute('PRI', $data['Priority']); $node->setAttribute('ACT', strtoupper($data['DeployAction'])); $node->setAttribute('DIGEST', $data['Hash']); $node->setAttribute('PROTO', 'HTTP'); $node->setAttribute('FRAGS', $data['NumFragments']); $node->setAttribute('DIGEST_ALGO', 'SHA1'); $node->setAttribute('DIGEST_ENCODE', 'Hexa'); $node->setAttribute('PATH', $data['DeployAction'] == 'store' ? $data['ActionParam'] : ''); $node->setAttribute('NAME', $data['DeployAction'] == 'launch' ? $data['ActionParam'] : ''); $node->setAttribute('COMMAND', $data['DeployAction'] == 'execute' ? $data['ActionParam'] : ''); $node->setAttribute('NOTIFY_USER', $data['Warn'] ? '1' : '0'); $node->setAttribute('NOTIFY_TEXT', $this->_escapeMessage($data['WarnMessage'])); $node->setAttribute('NOTIFY_COUNTDOWN', $data['WarnCountdown']); $node->setAttribute('NOTIFY_CAN_ABORT', $data['WarnAllowAbort'] ? '1' : '0'); $node->setAttribute('NOTIFY_CAN_DELAY', $data['WarnAllowDelay'] ? '1' : '0'); $node->setAttribute('NEED_DONE_ACTION', $data['PostInstMessage'] ? '1' : '0'); $node->setAttribute('NEED_DONE_ACTION_TEXT', $this->_escapeMessage($data['PostInstMessage'])); $node->setAttribute('GARDEFOU', 'rien'); if ($this->hasChildNodes()) { $this->replaceChild($node, $this->firstChild); } else { $this->appendChild($node); } if (!\Library\Application::isProduction()) { $this->forceValid(); } }
/** * @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')); }
public static function setUpBeforeClass() { // These tables must exist before the view can be created \Library\Application::getService('Database\\Table\\ClientsAndGroups')->setSchema(); \Library\Application::getService('Database\\Table\\ClientSystemInfo')->setSchema(); parent::setUpBeforeClass(); }
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 __construct() { parent::__construct(); $this->name = 'PMTool'; $this->context()->setLanguage(); $this->logoImageUrl = $this->imageUtil->getImageUrl("FWM_logo.jpg"); }
public function getConnection() { if (!$this->_db) { $pdo = \Library\Application::getService('Db')->getDriver()->getConnection()->getResource(); $this->_db = $this->createDefaultDBConnection($pdo, ':memory:'); } return $this->_db; }
/** * Create a new view renderer * * @return \Zend\View\Renderer\PhpRenderer */ protected function _createView() { // Clone helper plugin manager to prevent state changes leaking into other tests $plugins = clone \Library\Application::getService('ViewHelperManager'); $view = new \Zend\View\Renderer\PhpRenderer(); $view->setHelperPluginManager($plugins); return $view; }
/** * Test service */ public function testLoggerService() { $logger = \Library\Application::getService('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() { $serviceManager = \Library\Application::getService('serviceManager'); // 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()); }
/** * @internal */ public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = null) { $applicationConfig = $container->get('ApplicationConfig'); if (isset($applicationConfig['Library\\UserConfig'])) { return $applicationConfig['Library\\UserConfig']; } else { $reader = new \Zend\Config\Reader\Ini(); return $reader->fromFile(getenv('BRAINTACLE_CONFIG') ?: \Library\Application::getPath('user_config/braintacle.ini')); } }
/** * Set up application config */ public function setUp() { parent::setUp(); $this->setTraceError(true); $this->setApplicationConfig(\Library\Application::getApplicationConfig('Console', true)); // Put application in authenticated state $auth = $this->createMock('Model\\Operator\\AuthenticationService'); $auth->expects($this->atLeastOnce())->method('hasIdentity')->willReturn(true); $serviceManager = $this->getApplicationServiceLocator(); $serviceManager->setService('Model\\Operator\\AuthenticationService', $auth); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); // Add columns to CustomFields table static::$_customFields = \Library\Application::getService('Database\\Nada')->getTable('accountinfo'); static::$_customFields->addColumn('col_text', \Nada::DATATYPE_VARCHAR, 255); static::$_customFields->addColumn('col_clob', \Nada::DATATYPE_CLOB); static::$_customFields->addColumn('col_integer', \Nada::DATATYPE_INTEGER, 32); static::$_customFields->addColumn('col_float', \Nada::DATATYPE_FLOAT); static::$_customFields->addColumn('col_date', \Nada::DATATYPE_DATE); }
/** * {@inheritdoc} * @codeCoverageIgnore */ protected function _postSetSchema($logger, $schema, $database) { if (!\Library\Application::isTest() and isset($database->getTables()['network_devices'])) { $definedTypes = $this->fetchCol('name'); foreach ($this->adapter->query('SELECT DISTINCT type FROM network_devices')->execute() as $type) { $type = $type['type']; if (!in_array($type, $definedTypes)) { $logger->notice(sprintf('Creating undefined network device type "%s"', $type)); $this->_serviceLocator->get('Model\\Network\\DeviceManager')->addType($type); } } } }
public function testDeleteItems() { $model = $this->_getModel(); $model->deleteItems(1); $dataSet = new \PHPUnit_Extensions_Database_DataSet_QueryDataSet($this->getConnection()); foreach (static::$_tables as $table) { if ($table == 'ClientsAndGroups' or $table == 'DuplicateMacAddresses' or $table == 'SoftwareDefinitions') { continue; } $table = \Library\Application::getService("Database\\Table\\{$table}")->table; $dataSet->addTable($table, "SELECT hardware_id FROM {$table}"); } $this->assertDataSetsEqual($this->_loadDataSet('DeleteItems'), $dataSet); }
public function testFormElementHelperIntegration() { $element = new \Zend\Form\Element\Select('test'); $element->setAttribute('type', 'select_untranslated')->setValueOptions(array('Yes<b>', 'No')); $expected = <<<EOT <select name="test"><option value="0">Yes<b></option> <option value="1">No</option></select> EOT; $plugins = clone \Library\Application::getService('ViewHelperManager'); $view = new \Zend\View\Renderer\PhpRenderer(); $view->setHelperPluginManager($plugins); $helper = $plugins->get('formElement'); $helper->setView($view); $this->assertEquals($expected, $helper($element)); }
public function testInvokeWithConsoleForm() { $plugin = $this->_getPlugin(false); // Set up \Console\Form\Form using default renderer $form = $this->getMock('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 $renderer = \Library\Application::getService('ViewRenderer'); $output = $renderer->render($viewModel); $this->assertEquals('\\Console\\Form\\Form default renderer', $output); }
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 static function setUpBeforeClass() { parent::setUpBeforeClass(); static::$_nada = \Library\Application::getService('Database\\Nada'); // Add columns to CustomFields table, matching config from fixture $customFields = \Library\Application::getService('Database\\Table\\CustomFields'); $customFields->setSchema(); $fields = static::$_nada->getTable('accountinfo'); $fields->addColumn('fields_3', \Nada::DATATYPE_VARCHAR, 255); $fields->addColumn('fields_4', \Nada::DATATYPE_INTEGER, 32); $fields->addColumn('fields_5', \Nada::DATATYPE_FLOAT); $fields->addColumn('fields_6', \Nada::DATATYPE_CLOB); $fields->addColumn('fields_7', \Nada::DATATYPE_DATE); $fields->addColumn('fields_8', \Nada::DATATYPE_VARCHAR, 255); $fields->addColumn('fields_9', \Nada::DATATYPE_VARCHAR, 255); }