示例#1
0
 public function setUp()
 {
     parent::setUp();
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->add_lang('ucp');
     $request = $this->getMock('\\phpbb\\request\\request');
     $template = $this->getMock('\\phpbb\\template\\template');
     $this->field = new \phpbb\profilefields\type\type_googleplus($request, $template, $user);
 }
示例#2
0
 public function setUp()
 {
     parent::setUp();
     global $phpbb_root_path, $phpEx;
     $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
     $lang = new \phpbb\language\language($lang_loader);
     $user = new \phpbb\user($lang, '\\phpbb\\datetime');
     $user->add_lang('ucp');
     $request = $this->getMock('\\phpbb\\request\\request');
     $template = $this->getMock('\\phpbb\\template\\template');
     $this->field = new \phpbb\profilefields\type\type_googleplus($request, $template, $user);
 }
示例#3
0
 /**
  * @dataProvider phpbb_exception_data
  */
 public function test_phpbb_exception($is_ajax, $exception, $expected)
 {
     $request = \Symfony\Component\HttpFoundation\Request::create('test.php', 'GET', array(), array(), array(), $is_ajax ? array('HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') : array());
     $template = $this->getMockBuilder('\\phpbb\\template\\twig\\twig')->disableOriginalConstructor()->getMock();
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->add_lang('common');
     $exception_listener = new \phpbb\event\kernel_exception_subscriber($template, $user);
     $event = new \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, $exception);
     $exception_listener->on_kernel_exception($event);
     $response = $event->getResponse();
     $this->assertEquals($expected['status_code'], $response->getStatusCode());
     $this->assertEquals($is_ajax, $response instanceof \Symfony\Component\HttpFoundation\JsonResponse);
     if (isset($expected['content'])) {
         $this->assertContains($expected['content'], $response->getContent());
     }
 }
示例#4
0
 public function setUp()
 {
     global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $user, $cache, $auth;
     parent::setUp();
     $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
     $db = $this->new_dbal();
     $config = new \phpbb\config\config(array());
     set_config(null, null, null, $config);
     set_config_count(null, null, null, $config);
     $cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), $config, $db, $phpbb_root_path, $phpEx);
     $auth = $this->getMock('\\phpbb\\auth\\auth');
     $auth->expects($this->any())->method('acl_get')->with($this->stringContains('_'), $this->anything())->will($this->returnValueMap(array(array('u_viewprofile', 1, false))));
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->data = array('user_lang' => 'en');
     $user->add_lang('common');
     $user_loader = new phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
     $user_loader->load_users(array(2, 3, 4, 5, 6));
     $this->notification = new phpbb_mock_notification_type_post($user_loader, null, null, $user, null, null, $phpbb_root_path, $phpEx, null, null, null);
 }
示例#5
0
/**
* Stk add lang
*
* A wrapper for the $user->add_lang method that will use the custom language path that is used
* in this tool kit.
* The function shall first try to include the file in the users language, if that fails it will
* take the boards default language, if that also fails it will fall back to English
*
* @param	String	$lang_file	the name of the language file
* @param	mixed	$force_lang	If this parameter contains an ISO code this language
*								is used for the file. If set to "false" the users default
*								langauge will be used
*/
function stk_add_lang($lang_file)
{
    global $config, $user;
    if (!isset($user)) {
        if (file_exists(STK_ROOT_PATH . 'default_lang.txt')) {
            $default_lang = trim(file_get_contents(STK_ROOT_PATH . 'default_lang.txt'));
            if (empty($default_lang)) {
                $default_lang = 'en';
            }
        } else {
            $default_lang = 'en';
        }
        if (!class_exists('phpbb\\session')) {
            include PHPBB_ROOT_PATH . 'phpbb/session.' . PHP_EXT;
        }
        if (!class_exists('phpbb\\user')) {
            include PHPBB_ROOT_PATH . 'phpbb/user.' . PHP_EXT;
        }
        $dir = @opendir(PHPBB_ROOT_PATH . 'language');
        if (!$dir) {
            die('Unable to access the language directory');
            exit;
        }
        while (($file = readdir($dir)) !== false) {
            $path = STK_ROOT_PATH . 'language/' . $file;
            if (!is_file($path) && !is_link($path) && $file == strtolower($default_lang)) {
                $language = $file;
                break;
            }
        }
        closedir($dir);
        if (!file_exists(PHPBB_ROOT_PATH . 'language/' . $language) || !is_dir(PHPBB_ROOT_PATH . 'language/' . $language)) {
            die('No language found!');
        }
        $user = new \phpbb\user('\\phpbb\\datetime');
        $user->lang_path = $user->lang_path . $language;
        $user->data['user_lang'] = $default_lang;
    }
    // Internally cache some data
    static $lang_data = array();
    static $lang_dirs = array();
    // Store current phpBB data
    if (empty($lang_data)) {
        $lang_data = array('lang_path' => $user->lang_path, 'lang_name' => $user->data['user_lang']);
    }
    if (empty($user->lang_path)) {
        die('No language found!');
    }
    // Empty the lang_name
    $user->lang_name = '';
    // Find out what languages we could use
    if (empty($config['default_lang'])) {
        $config['default_lang'] = $language;
    }
    if (empty($lang_dirs)) {
        $lang_dirs = array($user->data['user_lang'], basename($config['default_lang']), 'en');
        // Only unique dirs
        $lang_dirs = array_unique($lang_dirs);
    }
    // Switch to the STK language dir
    $user->lang_path = STK_ROOT_PATH . 'language/';
    // Test all languages
    foreach ($lang_dirs as $dir) {
        if (file_exists($user->lang_path . $dir . "/{$lang_file}." . PHP_EXT)) {
            $user->lang_name = $dir;
            break;
        }
    }
    // No language file :/
    if (empty($user->lang_name)) {
        trigger_error("Language file: {$lang_file}." . PHP_EXT . ' missing!', E_USER_ERROR);
    }
    // Add the file
    $user->add_lang($lang_file);
    // Now reset the paths so phpBB can continue to operate as usual
    $user->lang_path = PHPBB_ROOT_PATH . 'language/';
    $user->lang_name = !isset($user->lang_name) ? $user->lang_name : $user->data['user_lang'];
}
示例#6
0
 function user_setup($user = false)
 {
     if (!isset($user)) {
         if (!class_exists('phpbb\\session')) {
             include PHPBB_ROOT_PATH . 'phpbb/session.' . PHP_EXT;
         }
         if (!class_exists('phpbb\\user')) {
             include PHPBB_ROOT_PATH . 'phpbb/user.' . PHP_EXT;
         }
         if (file_exists(STK_ROOT_PATH . 'default_lang.txt')) {
             $default_lang = trim(file_get_contents(STK_ROOT_PATH . 'default_lang.txt'));
         } else {
             $default_lang = 'en';
         }
         $dir = @opendir(PHPBB_ROOT_PATH . 'language');
         if (!$dir) {
             die('Unable to access the language directory');
             exit;
         }
         while (($file = readdir($dir)) !== false) {
             $path = STK_ROOT_PATH . 'language/' . $file;
             $lang[] = $file;
         }
         closedir($dir);
         $lang = array_diff($lang, array('index.htm', '.', '..'));
         foreach ($lang as $key => $value) {
             if ($value == strtolower($default_lang)) {
                 $language = $value;
             }
         }
         if (empty($language)) {
             $language = $default_lang;
         }
         if (empty($lang)) {
             die('No language found!');
         }
         $user = new \phpbb\user('\\phpbb\\datetime');
         $lang_path = $user->lang_path;
         $lang_path = '' . $lang_path . '' . $language . '';
         $user->lang_path = '' . PHPBB_ROOT_PATH . '' . $lang_path . '';
         $user->data['user_lang'] = $language;
         $user->add_lang(array(), array(), 'install.' . PHP_EXT . '');
         $user->add_lang(array(), array(), 'common.' . PHP_EXT . '');
         $user->lang_path = $lang_path;
     }
     return $user;
 }