示例#1
0
 public function get_default_options_cases()
 {
     return array(array('<t>apple</t>', 'banana'), array('<t>apple</t>', 'banana', function ($phpbb_container) {
         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->optionset('viewcensors', false);
         $phpbb_container->set('user', $user);
     }), array('<t>apple</t>', 'banana', function ($phpbb_container) {
         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->optionset('viewcensors', false);
         $config = new \phpbb\config\config(array('allow_nocensors' => true));
         $phpbb_container->set('user', $user);
         $phpbb_container->set('config', $config);
     }), array('<t>apple</t>', 'apple', function ($phpbb_container, $test) {
         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->optionset('viewcensors', false);
         $config = new \phpbb\config\config(array('allow_nocensors' => true));
         $auth = $test->getMock('phpbb\\auth\\auth');
         $auth->expects($test->any())->method('acl_get')->with('u_chgcensors')->will($test->returnValue(true));
         $phpbb_container->set('user', $user);
         $phpbb_container->set('config', $config);
         $phpbb_container->set('auth', $auth);
     }), array('<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://localhost/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://localhost/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>'), array('<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', 'http://localhost/foo.swf', function ($phpbb_container) {
         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->optionset('viewflash', false);
         $phpbb_container->set('user', $user);
     }), array('<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', '<img src="http://localhost/mrgreen.gif" class="postimage" alt="Image">'), array('<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', '<a href="http://localhost/mrgreen.gif" class="postlink">http://localhost/mrgreen.gif</a>', function ($phpbb_container) {
         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->optionset('viewimg', false);
         $phpbb_container->set('user', $user);
     }), array('<r><E>:)</E></r>', '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">'), array('<r><E>:)</E></r>', ':)', function ($phpbb_container) {
         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->optionset('smilies', false);
         $phpbb_container->set('user', $user);
     }));
 }
 public function get_text_formatter_tests()
 {
     return array(array('<t>Plain text</t>', 'Plain text'), array('<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL></r>', 'Hello <a href="http://example.org" class="postlink">world</a>'), array('<t>&amp;&lt;&gt;"\'</t>', '&amp;&lt;&gt;"\''), array('<r><CENSOR with="banana">apple</CENSOR></r>', 'banana', true), array('<r><CENSOR with="banana">apple</CENSOR></r>', 'apple', false), array('<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://localhost/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://localhost/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>'), array('<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', 'http://localhost/foo.swf', true, function ($phpbb_container) {
         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->optionset('viewflash', false);
         $phpbb_container->set('user', $user);
     }), array('<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', '<img src="http://localhost/mrgreen.gif" class="postimage" alt="Image">'), array('<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', '<a href="http://localhost/mrgreen.gif" class="postlink">http://localhost/mrgreen.gif</a>', true, function ($phpbb_container) {
         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->optionset('viewimg', false);
         $phpbb_container->set('user', $user);
     }), array('<r><E>:)</E></r>', '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" width="15" height="17" alt=":)" title="Smile">'), array('<r><E>:)</E></r>', ':)', true, function ($phpbb_container) {
         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->optionset('smilies', false);
         $phpbb_container->set('user', $user);
     }));
 }
示例#3
0
 /**
  * Set working instances of the text_formatter.* services
  *
  * If no container is passed, the global $phpbb_container will be used and/or
  * created if applicable
  *
  * @param  ContainerInterface $container   Service container
  * @param  string             $fixture     Path to the XML fixture
  * @param  string             $styles_path Path to the styles dir
  * @return ContainerInterface
  */
 public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null)
 {
     static $first_run;
     global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
     $cache_dir = __DIR__ . '/../tmp/';
     // Remove old cache files on first run
     if (!isset($first_run)) {
         $first_run = 1;
         array_map('unlink', array_merge(glob($cache_dir . 'data_s9e_*'), glob($cache_dir . 's9e_*')));
     }
     if (!isset($container)) {
         if (!isset($phpbb_container)) {
             $phpbb_container = new phpbb_mock_container_builder();
         }
         $container = $phpbb_container;
     }
     if (!isset($fixture)) {
         $fixture = __DIR__ . '/../text_formatter/s9e/fixtures/default_formatting.xml';
     }
     if (!isset($styles_path)) {
         $styles_path = $phpbb_root_path . 'styles/';
     }
     $dataset = new DOMDocument();
     $dataset->load($fixture);
     $tables = array('phpbb_bbcodes' => array(), 'phpbb_smilies' => array(), 'phpbb_styles' => array(), 'phpbb_words' => array());
     foreach ($dataset->getElementsByTagName('table') as $table) {
         $name = $table->getAttribute('name');
         $columns = array();
         foreach ($table->getElementsByTagName('column') as $column) {
             $columns[] = $column->textContent;
         }
         foreach ($table->getElementsByTagName('row') as $row) {
             $values = array();
             foreach ($row->getElementsByTagName('value') as $value) {
                 $values[] = $value->textContent;
             }
             $tables[$name][] = array_combine($columns, $values);
         }
     }
     // Set up a default style if there's none set
     if (empty($tables['phpbb_styles'])) {
         $tables['phpbb_styles'][] = array('style_id' => 1, 'style_path' => 'prosilver', 'bbcode_bitfield' => 'kNg=');
     }
     // Mock the DAL, make it return data from the fixture
     $mb = $this->test_case->getMockBuilder('phpbb\\textformatter\\data_access');
     $mb->setMethods(array('get_bbcodes', 'get_censored_words', 'get_smilies', 'get_styles'));
     $mb->setConstructorArgs(array($this->test_case->getMock('phpbb\\db\\driver\\driver'), 'phpbb_bbcodes', 'phpbb_smilies', 'phpbb_styles', 'phpbb_words', $styles_path));
     $dal = $mb->getMock();
     $container->set('text_formatter.data_access', $dal);
     $dal->expects($this->test_case->any())->method('get_bbcodes')->will($this->test_case->returnValue($tables['phpbb_bbcodes']));
     $dal->expects($this->test_case->any())->method('get_smilies')->will($this->test_case->returnValue($tables['phpbb_smilies']));
     $dal->expects($this->test_case->any())->method('get_styles')->will($this->test_case->returnValue($tables['phpbb_styles']));
     $dal->expects($this->test_case->any())->method('get_censored_words')->will($this->test_case->returnValue($tables['phpbb_words']));
     // Cache the parser and renderer with a key based on this method's arguments
     $cache = new \phpbb\cache\driver\file($cache_dir);
     $prefix = '_s9e_' . md5(serialize(func_get_args()));
     $cache_key_parser = $prefix . '_parser';
     $cache_key_renderer = $prefix . '_renderer';
     $container->set('cache.driver', $cache);
     $container->setParameter('cache.dir', $cache_dir);
     // Create a path_helper
     if (!$container->has('path_helper')) {
         $container->set('path_helper', new \phpbb\path_helper(new \phpbb\symfony_request(new phpbb_mock_request()), new \phpbb\filesystem(), $this->test_case->getMock('\\phpbb\\request\\request'), $phpbb_root_path, $phpEx));
     }
     // Create an event dispatcher
     if ($container->has('dispatcher')) {
         $dispatcher = $container->get('dispatcher');
     } else {
         if (isset($phpbb_dispatcher)) {
             $dispatcher = $phpbb_dispatcher;
         } else {
             $dispatcher = new phpbb_mock_event_dispatcher();
         }
     }
     if (!isset($phpbb_dispatcher)) {
         $phpbb_dispatcher = $dispatcher;
     }
     // Create and register the text_formatter.s9e.factory service
     $factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $cache_dir, $cache_key_parser, $cache_key_renderer);
     $container->set('text_formatter.s9e.factory', $factory);
     // Create a user if none was provided, and add the common lang strings
     if ($container->has('user')) {
         $user = $container->get('user');
     } else {
         $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->optionset('viewcensors', true);
         $user->optionset('viewflash', true);
         $user->optionset('viewimg', true);
         $user->optionset('viewsmilies', true);
         $container->set('user', $user);
     }
     $user->add_lang('common');
     if (!isset($user->style)) {
         $user->style = array('style_id' => 1);
     }
     // Create and register the text_formatter.s9e.parser service and its alias
     $parser = new \phpbb\textformatter\s9e\parser($cache, $cache_key_parser, $factory, $dispatcher);
     $container->set('text_formatter.parser', $parser);
     $container->set('text_formatter.s9e.parser', $parser);
     // Create and register the text_formatter.s9e.renderer service and its alias
     $renderer = new \phpbb\textformatter\s9e\renderer($cache, $cache_dir, $cache_key_renderer, $factory, $dispatcher);
     $config = $container->has('config') ? $container->get('config') : new \phpbb\config\config(array('smilies_path' => 'images/smilies', 'allow_nocensors' => false));
     $auth = $container->has('auth') ? $container->get('auth') : new \phpbb\auth\auth();
     // Calls configured in services.yml
     $renderer->configure_smilies_path($config, $container->get('path_helper'));
     $renderer->configure_user($user, $config, $auth);
     $container->set('text_formatter.renderer', $renderer);
     $container->set('text_formatter.s9e.renderer', $renderer);
     // Create and register the text_formatter.s9e.utils service and its alias
     $utils = new \phpbb\textformatter\s9e\utils();
     $container->set('text_formatter.utils', $utils);
     $container->set('text_formatter.s9e.utils', $utils);
     return $container;
 }