示例#1
0
 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   4.0
  */
 public function register(Container $container)
 {
     $container->share('JApplicationAdministrator', function (Container $container) {
         $app = new \JApplicationAdministrator(null, null, null, $container);
         // The session service provider needs JFactory::$application, set it if still null
         if (JFactory::$application === null) {
             JFactory::$application = $app;
         }
         $app->setDispatcher($container->get('Joomla\\Event\\DispatcherInterface'));
         $app->setLogger(JLog::createDelegatedLogger());
         $app->setSession($container->get('Joomla\\Session\\SessionInterface'));
         return $app;
     }, true);
     $container->share('JApplicationSite', function (Container $container) {
         $app = new \JApplicationSite(null, null, null, $container);
         // The session service provider needs JFactory::$application, set it if still null
         if (JFactory::$application === null) {
             JFactory::$application = $app;
         }
         $app->setDispatcher($container->get('Joomla\\Event\\DispatcherInterface'));
         $app->setLogger(JLog::createDelegatedLogger());
         $app->setSession($container->get('Joomla\\Session\\SessionInterface'));
         return $app;
     }, true);
 }
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   3.2
  */
 public function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
     JFactory::$session = $this->getMockSession();
     $this->backupServer = $_SERVER;
     $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
     $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
     $_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     // Set the config for the app
     $config = new Registry();
     $config->set('session', false);
     // Get a new JApplicationAdministrator instance.
     $this->class = new JApplicationAdministrator($this->getMockInput(), $config);
     $this->class->setSession(JFactory::$session);
     $this->class->setDispatcher($this->getMockDispatcher());
     TestReflection::setValue('JApplicationCms', 'instances', array('administrator' => $this->class));
     JFactory::$application = $this->class;
 }