Esempio n. 1
0
 /**
  * Test route matches against various URIs
  */
 public function testRouter()
 {
     $router = \Library\Application::getService('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));
 }
Esempio n. 2
0
 public static function setUpBeforeClass()
 {
     // GroupInfo initialization depends on Config table
     $config = \Library\Application::getService('Database\\Table\\Config');
     $config->setSchema();
     parent::setUpBeforeClass();
 }
Esempio n. 3
0
 /**
  * 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());
 }
Esempio n. 4
0
 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 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 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();
 }
 /**
  * @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());
 }
 /**
  * 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 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;
 }
Esempio n. 11
0
 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());
 }
 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);
 }
Esempio n. 13
0
 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&lt;b&gt;</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));
    }
Esempio n. 15
0
 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 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);
 }
    public function testFormElementHelperIntegration()
    {
        $element = new \Library\Form\Element\SelectSimple('test');
        $element->setValueOptions(array('option<b>1', 'option2'))->setValue('option<b>1');
        $expected = <<<EOT
<select name="test">
<option selected="selected">option&lt;b&gt;1</option>
<option>option2</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 setUp()
 {
     // GroupInfo::initialize() table has a dependency on Model\Config which
     // can have side effects on oter tests. For better test isolation, set
     // up a GroupInfo instance with a Model\Config mock object. Every test
     // that relies on the GroupInfo table should override the
     // Database\Table\GroupInfo service with $this->_groupInfo.
     // The setup is done only once, but cannot be done in setUpBeforeClass()
     // because mock objects cannot be created in a static method.
     if (!$this->_config) {
         $this->_config = $this->getMockBuilder('Model\\Config')->disableOriginalConstructor()->getMock();
         $this->_config->method('__get')->willReturnMap(array(array('groupCacheExpirationInterval', 30)));
         $serviceManager = $this->getMock('Zend\\ServiceManager\\ServiceManager');
         $serviceManager->method('get')->willReturnMap(array(array('Db', true, \Library\Application::getService('Db')), array('Database\\Nada', true, \Library\Application::getService('Database\\Nada')), array('Library\\Logger', true, \Library\Application::getService('Library\\Logger')), array('Model\\Config', true, $this->_config), array('Model\\Group\\Group', true, \Library\Application::getService('Model\\Group\\Group'))));
         $this->_groupInfo = new \Database\Table\GroupInfo($serviceManager);
         $this->_groupInfo->setSchema();
         $this->_groupInfo->initialize();
     }
     return parent::setUp();
 }
Esempio n. 19
0
 /**
  * Get an initialized instance of the controller plugin
  *
  * If controller setup is requested, the controller will be a
  * \Library\Test\Mvc\Controller\TestController. Its MvcEvent will be
  * initialized with a standard route 'test' (/module/controller/action/)
  * with defaults of "defaultcontroller" and "defaultaction".
  * The RouteMatch is initialized with "currentcontroller" and
  * "currentaction". An empty response is created.
  *
  * @param bool $setController Initialize the helper with a working controller (default: TRUE)
  * @return \Zend\Mvc\Controller\Plugin\PluginInterface Plugin instance
  */
 protected function _getPlugin($setController = true)
 {
     if ($setController) {
         $router = new \Zend\Mvc\Router\Http\TreeRouteStack();
         $router->addRoute('test', \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/[module[/]][:controller[/][:action[/]]]', 'defaults' => array('controller' => 'defaultcontroller', 'action' => 'defaultaction'))));
         $routeMatch = new \Zend\Mvc\Router\RouteMatch(array('controller' => 'currentcontroller', 'action' => 'currentaction'));
         $routeMatch->setMatchedRouteName('test');
         $event = new \Zend\Mvc\MvcEvent();
         $event->setRouter($router);
         $event->setRouteMatch($routeMatch);
         $event->setResponse(new \Zend\Http\Response());
         // Register TestController with the service manager because this is
         // not done in the module setup
         $manager = Application::getService('ControllerManager');
         $manager->setInvokableClass('test', 'Library\\Test\\Mvc\\Controller\\TestController');
         $this->_controller = $manager->get('test');
         $this->_controller->setEvent($event);
         return $this->_controller->plugin($this->_getPluginName());
     } else {
         return $this->_getPluginManager()->get($this->_getPluginName());
     }
 }
 public function testService()
 {
     $this->assertInstanceOf('Protocol\\Message\\InventoryRequest', \Library\Application::getService('Protocol\\Message\\InventoryRequest'));
 }
    public function testRenderFieldsetWithoutLabel()
    {
        $view = \Library\Application::getService('ViewManager')->getRenderer();
        $text1 = new \Zend\Form\Element\Text('text1');
        $text2 = new \Zend\Form\Element\Text('text2');
        $text2->setMessages(array('message'));
        $submit = new \Zend\Form\Element\Submit('submit');
        $form = new \Console\Form\Form();
        $form->init();
        $form->add($text1);
        $form->add($text2);
        $form->add($submit);
        $expected = <<<EOT
<div class="table">
<div class='row'>
<span class='label'></span>
<input type="text" name="text1" value="">
</div>
<div class='row'>
<span class='label'></span>
<input type="text" name="text2" class="input-error" value="">
</div>
<span class='cell'></span>
<ul class="errors"><li>message</li></ul>
<span class='cell'></span>
<input type="submit" name="submit" value="">
</div>

EOT;
        $this->assertEquals($expected, $form->renderFieldset($view, $form));
    }
Esempio n. 22
0
 public function testService()
 {
     $this->assertInstanceOf('Protocol\\Hydrator\\Software', \Library\Application::getService('Protocol\\Hydrator\\Software'));
 }
Esempio n. 23
0
 public function testService()
 {
     $this->assertInstanceOf('Protocol\\Hydrator\\Filesystems', \Library\Application::getService('Protocol\\Hydrator\\Filesystems'));
 }
Esempio n. 24
0
 /**
  * Provide table class and create table
  */
 public static function setUpBeforeClass()
 {
     static::$_table = \Library\Application::getService(static::_getClass());
     static::$_table->setSchema();
     parent::setUpBeforeClass();
 }
Esempio n. 25
0
 /**
  * Test for valid factory output
  */
 public function testMainMenuFactory()
 {
     $this->assertInstanceOf('Zend\\Navigation\\Navigation', Application::getService('Console\\Navigation\\MainMenu'));
 }
 public function testSetConfigUnchanged()
 {
     $config = $this->getMockBuilder('Model\\Config')->disableOriginalConstructor()->getMock();
     $config->method('getDbIdentifier')->with('inventoryInterval')->willReturn('FREQUENCY');
     $clientConfig = $this->getMockBuilder('Database\\Table\\ClientConfig')->disableOriginalConstructor()->getMock();
     $clientConfig->method('getAdapter')->willReturn(\Library\Application::getService('Db'));
     $clientConfig->expects($this->never())->method('insert');
     $clientConfig->expects($this->never())->method('update');
     $clientConfig->expects($this->never())->method('delete');
     $serviceManager = $this->getMock('Zend\\ServiceManager\\ServiceManager');
     $serviceManager->method('get')->will($this->returnValueMap(array(array('Database\\Table\\ClientConfig', true, $clientConfig), array('Model\\Config', true, $config))));
     $model = $this->getMockBuilder($this->_getClass())->setMethods(array('__destruct', 'getConfig'))->getMockForAbstractClass();
     $model->expects($this->once())->method('getConfig')->with('inventoryInterval')->willReturn(23);
     $model->setServiceLocator($serviceManager);
     $model['Id'] = 10;
     $model->setConfig('inventoryInterval', '23');
     $cache = new \ReflectionProperty($model, '_configCache');
     $cache->setAccessible(true);
     $this->assertSame(23, $cache->getValue($model)['inventoryInterval']);
 }
 public function testCreateFull()
 {
     $model = $this->_getModel();
     $model->create(array('Id' => 'new_id', 'FirstName' => 'new_first', 'LastName' => 'new_last', 'MailAddress' => 'new_mail', 'Comment' => 'new_comment', 'Password' => 'ignore'), 'new_passwd');
     $this->assertTablesEqual($this->_loadDataset('CreateFull')->getTable('operators'), $this->getConnection()->createQueryTable('operators', 'SELECT * from operators'));
     $auth = clone \Library\Application::getService('Zend\\Authentication\\AuthenticationService');
     $this->assertFalse($auth->hasIdentity());
     $this->assertTrue($auth->login('new_id', 'new_passwd'));
     $this->assertEquals('new_id', $auth->getIdentity());
 }
Esempio n. 28
0
 public function testInvokeWithRenderCallback()
 {
     // Test with render callback on column2.
     $this->_escapeHtml->expects($this->exactly(2))->method('__invoke')->will($this->returnArgument(0));
     $table = $this->getMockBuilder($this->_getHelperClass())->setConstructorArgs(array($this->_escapeHtml, $this->_htmlTag, $this->_consoleUrl, $this->_dateFormat))->setMethods(array('sortableHeader', 'row'))->getMock();
     $table->expects($this->never())->method('sortableHeader');
     $table->expects($this->exactly(3))->method('row')->with($this->anything(), $this->anything(), array())->will($this->returnCallback(array($this, 'mockRow')));
     $table->setView(\Library\Application::getService('ViewManager')->getRenderer());
     $this->_renderCallbackData = array();
     $this->assertEquals($this->_expected, $table($this->_data, $this->_headers, array(), array('column2' => array($this, 'renderCallback'))));
     $this->assertEquals(array('value2a', 'value2b'), $this->_renderCallbackData);
 }
Esempio n. 29
0
 public function setUp()
 {
     parent::setUp();
     $this->setTraceError(true);
     $this->setApplicationConfig(\Library\Application::getService('ApplicationConfig'));
 }
Esempio n. 30
0
 /**
  * Get new model instance via service manager
  *
  * This method allows temporarily overriding services with manually supplied
  * instances. This is useful for injecting mock objects which will be passed
  * to the model's constructor by a factory. A clone of the service manager is
  * used to avoid interference with other tests.
  *
  * @param array $overrideServices Optional associative array (name => instance) with services to override
  * @return object Model instance
  */
 protected function _getModel(array $overrideServices = array())
 {
     $serviceManager = \Library\Application::getService('ServiceManager');
     if (!empty($overrideServices)) {
         // Clone service manager to keep changes local.
         $serviceManager = clone $serviceManager;
         $serviceManager->setAllowOverride(true);
         // Reset SM config. This will force a new instance of our model to
         // be created with overriden services.
         $module = $serviceManager->get('ModuleManager')->getModule('Model');
         $config = new \Zend\ServiceManager\Config($module->getConfig()['service_manager']);
         $config->configureServiceManager($serviceManager);
         // Override specified services
         foreach ($overrideServices as $name => $service) {
             $serviceManager->setService($name, $service);
         }
     }
     $model = $serviceManager->get($this->_getClass());
     return clone $model;
 }