mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-08 09:46:46 +02:00
[ticket/11768] This commit integrates s9e\TextFormatter
This commit integrates s9e\TextFormatter as outlined in http://area51.phpbb.com/phpBB/viewtopic.php?f=108&t=44467 PHPBB3-11768
This commit is contained in:
87
tests/text_processing/decode_message_test.php
Normal file
87
tests/text_processing/decode_message_test.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
|
||||
|
||||
class phpbb_text_processing_decode_message_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* @dataProvider get_legacy_tests
|
||||
*/
|
||||
public function test_legacy($original, $expected, $bbcode_uid = '')
|
||||
{
|
||||
$actual = $original;
|
||||
decode_message($actual, $bbcode_uid);
|
||||
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
public function get_legacy_tests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
"&<>"'",
|
||||
"&<>"'"
|
||||
),
|
||||
array(
|
||||
'<!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) -->',
|
||||
':)'
|
||||
),
|
||||
/**
|
||||
* Fails as per PHPBB3-8420
|
||||
* @link http://tracker.phpbb.com/browse/PHPBB3-8420
|
||||
*
|
||||
array(
|
||||
'[url=http://example.com:2cpxwbdy]<!-- s:arrow: --><img src="{SMILIES_PATH}/icon_arrow.gif" alt=":arrow:" title="Arrow" /><!-- s:arrow: --> here[/url:2cpxwbdy]',
|
||||
'[url=http://example.com] :arrow: here[/url]',
|
||||
'2cpxwbdy'
|
||||
),
|
||||
*/
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_text_formatter_tests
|
||||
*/
|
||||
public function test_text_formatter($original, $expected)
|
||||
{
|
||||
$this->get_test_case_helpers()->set_s9e_services();
|
||||
|
||||
$actual = $original;
|
||||
decode_message($actual);
|
||||
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
public function get_text_formatter_tests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
"<t>&<>\"'",
|
||||
"&<>"'"
|
||||
),
|
||||
array(
|
||||
'<r><E>:)</E></r>',
|
||||
':)'
|
||||
),
|
||||
array(
|
||||
"<t>a<br/>\nb</t>",
|
||||
"a\nb"
|
||||
),
|
||||
/**
|
||||
* @link http://tracker.phpbb.com/browse/PHPBB3-8420
|
||||
*/
|
||||
array(
|
||||
'<r><URL url="http://example.com"><s>[url=http://example.com]</s> <E>:arrow:</E> here<e>[/url]</e></URL></r>',
|
||||
'[url=http://example.com] :arrow: here[/url]'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
3
tests/text_processing/fixtures/empty.xml
Normal file
3
tests/text_processing/fixtures/empty.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
</dataset>
|
443
tests/text_processing/fixtures/smilies.xml
Normal file
443
tests/text_processing/fixtures/smilies.xml
Normal file
@@ -0,0 +1,443 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_smilies">
|
||||
<column>smiley_id</column>
|
||||
<column>code</column>
|
||||
<column>emotion</column>
|
||||
<column>smiley_url</column>
|
||||
<column>smiley_width</column>
|
||||
<column>smiley_height</column>
|
||||
<column>smiley_order</column>
|
||||
<column>display_on_posting</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>:D</value>
|
||||
<value>Very Happy</value>
|
||||
<value>icon_e_biggrin.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>:-D</value>
|
||||
<value>Very Happy</value>
|
||||
<value>icon_e_biggrin.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>:grin:</value>
|
||||
<value>Very Happy</value>
|
||||
<value>icon_e_biggrin.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>4</value>
|
||||
<value>:)</value>
|
||||
<value>Smile</value>
|
||||
<value>icon_e_smile.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>4</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>5</value>
|
||||
<value>:-)</value>
|
||||
<value>Smile</value>
|
||||
<value>icon_e_smile.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>5</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>6</value>
|
||||
<value>:smile:</value>
|
||||
<value>Smile</value>
|
||||
<value>icon_e_smile.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>6</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>7</value>
|
||||
<value>;)</value>
|
||||
<value>Wink</value>
|
||||
<value>icon_e_wink.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>7</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>8</value>
|
||||
<value>;-)</value>
|
||||
<value>Wink</value>
|
||||
<value>icon_e_wink.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>8</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>9</value>
|
||||
<value>:wink:</value>
|
||||
<value>Wink</value>
|
||||
<value>icon_e_wink.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>9</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>10</value>
|
||||
<value>:(</value>
|
||||
<value>Sad</value>
|
||||
<value>icon_e_sad.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>10</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>11</value>
|
||||
<value>:-(</value>
|
||||
<value>Sad</value>
|
||||
<value>icon_e_sad.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>11</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>12</value>
|
||||
<value>:sad:</value>
|
||||
<value>Sad</value>
|
||||
<value>icon_e_sad.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>12</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>13</value>
|
||||
<value>:o</value>
|
||||
<value>Surprised</value>
|
||||
<value>icon_e_surprised.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>13</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>14</value>
|
||||
<value>:-o</value>
|
||||
<value>Surprised</value>
|
||||
<value>icon_e_surprised.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>14</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>15</value>
|
||||
<value>:eek:</value>
|
||||
<value>Surprised</value>
|
||||
<value>icon_e_surprised.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>15</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>16</value>
|
||||
<value>:shock:</value>
|
||||
<value>Shocked</value>
|
||||
<value>icon_eek.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>16</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>17</value>
|
||||
<value>:?</value>
|
||||
<value>Confused</value>
|
||||
<value>icon_e_confused.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>17</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>18</value>
|
||||
<value>:-?</value>
|
||||
<value>Confused</value>
|
||||
<value>icon_e_confused.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>18</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>19</value>
|
||||
<value>:???:</value>
|
||||
<value>Confused</value>
|
||||
<value>icon_e_confused.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>19</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>20</value>
|
||||
<value>8-)</value>
|
||||
<value>Cool</value>
|
||||
<value>icon_cool.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>20</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>21</value>
|
||||
<value>:cool:</value>
|
||||
<value>Cool</value>
|
||||
<value>icon_cool.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>21</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>22</value>
|
||||
<value>:lol:</value>
|
||||
<value>Laughing</value>
|
||||
<value>icon_lol.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>22</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>23</value>
|
||||
<value>:x</value>
|
||||
<value>Mad</value>
|
||||
<value>icon_mad.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>23</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>24</value>
|
||||
<value>:-x</value>
|
||||
<value>Mad</value>
|
||||
<value>icon_mad.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>24</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>25</value>
|
||||
<value>:mad:</value>
|
||||
<value>Mad</value>
|
||||
<value>icon_mad.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>25</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>26</value>
|
||||
<value>:P</value>
|
||||
<value>Razz</value>
|
||||
<value>icon_razz.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>26</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>27</value>
|
||||
<value>:-P</value>
|
||||
<value>Razz</value>
|
||||
<value>icon_razz.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>27</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>28</value>
|
||||
<value>:razz:</value>
|
||||
<value>Razz</value>
|
||||
<value>icon_razz.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>28</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>29</value>
|
||||
<value>:oops:</value>
|
||||
<value>Embarrassed</value>
|
||||
<value>icon_redface.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>29</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>30</value>
|
||||
<value>:cry:</value>
|
||||
<value>Crying or Very Sad</value>
|
||||
<value>icon_cry.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>30</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>31</value>
|
||||
<value>:evil:</value>
|
||||
<value>Evil or Very Mad</value>
|
||||
<value>icon_evil.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>31</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>32</value>
|
||||
<value>:twisted:</value>
|
||||
<value>Twisted Evil</value>
|
||||
<value>icon_twisted.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>32</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>33</value>
|
||||
<value>:roll:</value>
|
||||
<value>Rolling Eyes</value>
|
||||
<value>icon_rolleyes.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>33</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>34</value>
|
||||
<value>:!:</value>
|
||||
<value>Exclamation</value>
|
||||
<value>icon_exclaim.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>34</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>35</value>
|
||||
<value>:?:</value>
|
||||
<value>Question</value>
|
||||
<value>icon_question.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>35</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>36</value>
|
||||
<value>:idea:</value>
|
||||
<value>Idea</value>
|
||||
<value>icon_idea.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>36</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>37</value>
|
||||
<value>:arrow:</value>
|
||||
<value>Arrow</value>
|
||||
<value>icon_arrow.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>37</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>38</value>
|
||||
<value>:|</value>
|
||||
<value>Neutral</value>
|
||||
<value>icon_neutral.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>38</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>39</value>
|
||||
<value>:-|</value>
|
||||
<value>Neutral</value>
|
||||
<value>icon_neutral.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>39</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>40</value>
|
||||
<value>:mrgreen:</value>
|
||||
<value>Mr. Green</value>
|
||||
<value>icon_mrgreen.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>40</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>41</value>
|
||||
<value>:geek:</value>
|
||||
<value>Geek</value>
|
||||
<value>icon_e_geek.gif</value>
|
||||
<value>17</value>
|
||||
<value>17</value>
|
||||
<value>41</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>42</value>
|
||||
<value>:ugeek:</value>
|
||||
<value>Uber Geek</value>
|
||||
<value>icon_e_ugeek.gif</value>
|
||||
<value>17</value>
|
||||
<value>18</value>
|
||||
<value>42</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>43</value>
|
||||
<value>8)</value>
|
||||
<value>8)</value>
|
||||
<value>custom.gif</value>
|
||||
<value>17</value>
|
||||
<value>18</value>
|
||||
<value>42</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
@@ -11,10 +11,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
|
||||
require_once dirname(__FILE__) . '/../mock/user.php';
|
||||
require_once dirname(__FILE__) . '/../mock/cache.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
|
||||
|
||||
class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_case
|
||||
{
|
||||
@@ -24,21 +22,175 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$cache = new phpbb_mock_cache;
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
$config = new \phpbb\config\config(array());
|
||||
set_config(null, null, null, $config);
|
||||
}
|
||||
|
||||
$user = new phpbb_mock_user;
|
||||
/**
|
||||
* @dataProvider get_legacy_tests
|
||||
*/
|
||||
public function test_legacy($original, $expected, $uid = '', $bitfield = '', $flags = 0, $censor_text = true)
|
||||
{
|
||||
global $cache, $user;
|
||||
|
||||
$cache = new phpbb_mock_cache;
|
||||
$user = new \phpbb\user('\\phpbb\\datetime');
|
||||
$user->optionset('viewcensors', true);
|
||||
$user->optionset('viewflash', true);
|
||||
$user->optionset('viewimg', true);
|
||||
$user->optionset('viewsmilies', true);
|
||||
|
||||
$actual = generate_text_for_display($original, $uid, $bitfield, $flags, $censor_text);
|
||||
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
public function get_legacy_tests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'0',
|
||||
'0'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_censor_is_restored()
|
||||
{
|
||||
global $phpbb_container;
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder;
|
||||
|
||||
$user = new \phpbb\user('\\phpbb\\datetime');
|
||||
$user->optionset('viewcensors', false);
|
||||
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
$config = new \phpbb\config\config(array('allow_nocensors' => true));
|
||||
|
||||
$auth = $this->getMock('phpbb\\auth\\auth');
|
||||
$auth->expects($this->any())
|
||||
->method('acl_get')
|
||||
->with('u_chgcensors')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$phpbb_container->set('user', $user);
|
||||
$phpbb_container->set('config', $config);
|
||||
$phpbb_container->set('auth', $auth);
|
||||
|
||||
$this->get_test_case_helpers()->set_s9e_services($phpbb_container);
|
||||
$renderer = $phpbb_container->get('text_formatter.renderer');
|
||||
|
||||
$original = '<r><CENSOR with="banana">apple</CENSOR></r>';
|
||||
|
||||
$renderer->set_viewcensors(false);
|
||||
$this->assertSame('apple', $renderer->render($original));
|
||||
$renderer->set_viewcensors(true);
|
||||
$this->assertSame('banana', $renderer->render($original));
|
||||
$this->assertSame('apple', generate_text_for_display($original, '', '', 0, false));
|
||||
$this->assertSame('banana', $renderer->render($original), 'The original setting was not restored');
|
||||
|
||||
$renderer->set_viewcensors(false);
|
||||
$this->assertSame('apple', $renderer->render($original));
|
||||
$this->assertSame('banana', generate_text_for_display($original, '', '', 0, truee));
|
||||
$this->assertSame('apple', $renderer->render($original), 'The original setting was not restored');
|
||||
}
|
||||
|
||||
public function test_empty_string()
|
||||
/**
|
||||
* @dataProvider get_text_formatter_tests
|
||||
*/
|
||||
public function test_text_formatter($original, $expected, $censor_text = true, $setup = null)
|
||||
{
|
||||
$this->assertSame('', generate_text_for_display('', '', '', 0));
|
||||
global $phpbb_container;
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder;
|
||||
|
||||
if (isset($setup))
|
||||
{
|
||||
$setup($phpbb_container, $this);
|
||||
}
|
||||
|
||||
$this->get_test_case_helpers()->set_s9e_services($phpbb_container);
|
||||
|
||||
$this->assertSame($expected, generate_text_for_display($original, '', '', 0, $censor_text));
|
||||
}
|
||||
|
||||
public function test_zero_string()
|
||||
public function get_text_formatter_tests()
|
||||
{
|
||||
$this->assertSame('0', generate_text_for_display('0', '', '', 0));
|
||||
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>&<>"\'</t>',
|
||||
'&<>"\''
|
||||
),
|
||||
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)
|
||||
{
|
||||
$user = new \phpbb\user('\\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" 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)
|
||||
{
|
||||
$user = new \phpbb\user('\\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>',
|
||||
':)',
|
||||
true,
|
||||
function ($phpbb_container)
|
||||
{
|
||||
$user = new \phpbb\user('\\phpbb\\datetime');
|
||||
$user->optionset('smilies', false);
|
||||
|
||||
$phpbb_container->set('user', $user);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
90
tests/text_processing/generate_text_for_edit_test.php
Normal file
90
tests/text_processing/generate_text_for_edit_test.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
|
||||
require_once __DIR__ . '/../mock/user.php';
|
||||
require_once __DIR__ . '/../mock/cache.php';
|
||||
|
||||
class phpbb_text_processing_generate_text_for_edit_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* @dataProvider get_legacy_tests
|
||||
*/
|
||||
public function test_legacy($original, $expected, $uid = '', $flags = 0)
|
||||
{
|
||||
global $cache, $user, $phpbb_dispatcher;
|
||||
|
||||
$cache = new phpbb_mock_cache;
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
|
||||
$user = new phpbb_mock_user;
|
||||
$user->optionset('viewcensors', false);
|
||||
|
||||
$return = generate_text_for_edit($original, $uid, $flags);
|
||||
|
||||
$this->assertSame($expected, $return['text']);
|
||||
}
|
||||
|
||||
public function get_legacy_tests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'0',
|
||||
'0'
|
||||
),
|
||||
array(
|
||||
'Hello [url=http://example.org:1f4coh9x]world[/url:1f4coh9x] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) -->',
|
||||
'Hello [url=http://example.org]world[/url] :)',
|
||||
'1f4coh9x',
|
||||
0
|
||||
),
|
||||
array(
|
||||
"&<>"'",
|
||||
"&<>"'"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_text_formatter_tests
|
||||
*/
|
||||
public function test_text_formatter($original, $expected)
|
||||
{
|
||||
global $phpbb_dispatcher;
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
$this->get_test_case_helpers()->set_s9e_services();
|
||||
|
||||
$return = generate_text_for_edit($original, '', 0);
|
||||
|
||||
$this->assertSame($expected, $return['text']);
|
||||
}
|
||||
|
||||
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> <E>:)</E></r>',
|
||||
'Hello [url=http://example.org]world[/url] :)'
|
||||
),
|
||||
array(
|
||||
'<t>&<>"\'</t>',
|
||||
"&<>"'"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
70
tests/text_processing/generate_text_for_storage_test.php
Normal file
70
tests/text_processing/generate_text_for_storage_test.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
|
||||
require_once __DIR__ . '/../mock/container_builder.php';
|
||||
|
||||
class phpbb_text_processing_generate_text_for_storage_test extends phpbb_test_case
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
global $config, $phpbb_container, $phpbb_dispatcher;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$config = new \phpbb\config\config(array());
|
||||
set_config(null, null, null, $config);
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder;
|
||||
$phpbb_container->set('config', $config);
|
||||
$this->get_test_case_helpers()->set_s9e_services($phpbb_container);
|
||||
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_text_formatter_tests
|
||||
*/
|
||||
public function test_text_formatter($original, $expected, $allow_bbcode = true, $allow_urls = true, $allow_smilies = true, $setup = null)
|
||||
{
|
||||
$actual = $original;
|
||||
$uid = '';
|
||||
$bitfield = '';
|
||||
$flags = 0;
|
||||
|
||||
if (isset($setup))
|
||||
{
|
||||
$setup();
|
||||
}
|
||||
|
||||
generate_text_for_storage($actual, $uid, $bitfield, $flags, $allow_bbcode, $allow_urls, $allow_smilies);
|
||||
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
public function get_text_formatter_tests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Hello world',
|
||||
'<t>Hello world</t>'
|
||||
),
|
||||
array(
|
||||
'Hello [url=http://example.org]world[/url] :)',
|
||||
'<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL> <E>:)</E></r>'
|
||||
),
|
||||
array(
|
||||
'&<>"\'',
|
||||
'<t>&<>"\'</t>'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
532
tests/text_processing/message_parser_test.php
Normal file
532
tests/text_processing/message_parser_test.php
Normal file
@@ -0,0 +1,532 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../phpBB/includes/bbcode.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/message_parser.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
|
||||
|
||||
class phpbb_text_processing_message_parser_test extends phpbb_test_case
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
// Set up an intercepting proxy for getimagesize() calls
|
||||
stream_wrapper_unregister('http');
|
||||
stream_wrapper_register('http', __CLASS__ . '_proxy');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
parent::tearDownAfterClass();
|
||||
stream_wrapper_restore('http');
|
||||
}
|
||||
|
||||
protected function prepare_s9e_services($setup = null)
|
||||
{
|
||||
global $config, $phpbb_container, $user;
|
||||
|
||||
$config = new \phpbb\config\config(array('max_poll_options' => 999));
|
||||
|
||||
$map = array(
|
||||
array('MAX_FLASH_HEIGHT_EXCEEDED', 123, 'Your flash files may only be up to 123 pixels high.'),
|
||||
array('MAX_FLASH_WIDTH_EXCEEDED', 456, 'Your flash files may only be up to 456 pixels wide.'),
|
||||
array('MAX_FONT_SIZE_EXCEEDED', 120, 'You may only use fonts up to size 120.'),
|
||||
array('MAX_FONT_SIZE_EXCEEDED', 200, 'You may only use fonts up to size 200.'),
|
||||
array('MAX_IMG_HEIGHT_EXCEEDED', 12, 'Your images may only be up to 12 pixels high.'),
|
||||
array('MAX_IMG_WIDTH_EXCEEDED', 34, 'Your images may only be up to 34 pixels wide.'),
|
||||
array('TOO_MANY_SMILIES', 3, 'Your message contains too many smilies. The maximum number of smilies allowed is 3.'),
|
||||
array('TOO_MANY_URLS', 2, 'Your message contains too many URLs. The maximum number of URLs allowed is 2.'),
|
||||
array('UNAUTHORISED_BBCODE', '[flash]', 'You cannot use certain BBCodes: [flash].'),
|
||||
array('UNAUTHORISED_BBCODE', '[img]', 'You cannot use certain BBCodes: [img].'),
|
||||
array('UNAUTHORISED_BBCODE', '[quote]', 'You cannot use certain BBCodes: [quote].'),
|
||||
array('UNAUTHORISED_BBCODE', '[url]', 'You cannot use certain BBCodes: [url].'),
|
||||
);
|
||||
|
||||
$user = $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock();
|
||||
$user->expects($this->any())
|
||||
->method('lang')
|
||||
->will($this->returnValueMap($map));
|
||||
|
||||
$user->lang = array(
|
||||
'NO_POLL_TITLE' => 'You have to enter a poll title.',
|
||||
'POLL_TITLE_TOO_LONG' => 'The poll title must contain fewer than 100 characters.',
|
||||
'POLL_TITLE_COMP_TOO_LONG' => 'The parsed size of your poll title is too large, consider removing BBCodes or smilies.',
|
||||
'TOO_FEW_POLL_OPTIONS' => 'You must enter at least two poll options.',
|
||||
'TOO_MANY_POLL_OPTIONS' => 'You have tried to enter too many poll options.',
|
||||
'TOO_MANY_USER_OPTIONS' => 'You cannot specify more options per user than existing poll options.',
|
||||
'UNABLE_GET_IMAGE_SIZE' => 'It was not possible to determine the dimensions of the image.'
|
||||
);
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder;
|
||||
$phpbb_container->set('user', $user);
|
||||
$phpbb_container->set('config', $config);
|
||||
|
||||
if (isset($setup))
|
||||
{
|
||||
$setup($parser, $phpbb_container, $this);
|
||||
}
|
||||
|
||||
$this->get_test_case_helpers()->set_s9e_services($phpbb_container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_test_polls
|
||||
*/
|
||||
public function test_parse_poll($poll, $expected, $warn_msg = array())
|
||||
{
|
||||
$this->prepare_s9e_services();
|
||||
|
||||
$message_parser = new parse_message('Me[i]s[/i]sage');
|
||||
|
||||
// Add some default values
|
||||
$poll += array(
|
||||
'poll_length' => 123,
|
||||
'poll_start' => 123,
|
||||
'poll_last_vote' => 123,
|
||||
'poll_vote_change' => true,
|
||||
'enable_bbcode' => true,
|
||||
'enable_urls' => true,
|
||||
'enable_smilies' => true,
|
||||
'img_status' => true
|
||||
);
|
||||
|
||||
$message_parser->parse_poll($poll);
|
||||
$this->assertSame($expected, array_intersect_key($poll, $expected));
|
||||
|
||||
$this->assertSame(
|
||||
'<r>Me<I><s>[i]</s>s<e>[/i]</e></I>sage</r>',
|
||||
$message_parser->parse(true, true, true, true, true, true, true, false)
|
||||
);
|
||||
|
||||
$this->assertSame($warn_msg, $message_parser->warn_msg);
|
||||
}
|
||||
|
||||
public function get_test_polls()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'poll_title' => 'foo [b]bar[/b] baz',
|
||||
'poll_option_text' => "[i]foo[/i]\nbar\n[i]baz[/i]",
|
||||
'poll_max_options' => 3,
|
||||
'poll_options_size' => 3
|
||||
),
|
||||
array(
|
||||
'poll_title' => '<r>foo <B><s>[b]</s>bar<e>[/b]</e></B> baz</r>',
|
||||
'poll_option_text' => "<r><I><s>[i]</s>foo<e>[/i]</e></I></r>\n<t>bar</t>\n<r><I><s>[i]</s>baz<e>[/i]</e></I></r>",
|
||||
'poll_options' => array(
|
||||
'<r><I><s>[i]</s>foo<e>[/i]</e></I></r>',
|
||||
'<t>bar</t>',
|
||||
'<r><I><s>[i]</s>baz<e>[/i]</e></I></r>'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'poll_title' => 'xxx',
|
||||
'poll_option_text' => "[quote]quote[/quote]\n:)",
|
||||
'poll_max_options' => 2,
|
||||
'poll_options_size' => 2
|
||||
),
|
||||
array(
|
||||
'poll_title' => '<t>xxx</t>',
|
||||
'poll_option_text' => "<t>[quote]quote[/quote]</t>\n<r><E>:)</E></r>",
|
||||
'poll_options' => array(
|
||||
'<t>[quote]quote[/quote]</t>',
|
||||
'<r><E>:)</E></r>'
|
||||
)
|
||||
),
|
||||
array('You cannot use certain BBCodes: [quote].')
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'poll_title' => 'xxx',
|
||||
'poll_option_text' => "[flash=12,34]http://example.org/x.swf[/flash]\n:)",
|
||||
'poll_max_options' => 2,
|
||||
'poll_options_size' => 2
|
||||
),
|
||||
array(
|
||||
'poll_title' => '<t>xxx</t>',
|
||||
'poll_option_text' => "<t>[flash=12,34]http://example.org/x.swf[/flash]</t>\n<r><E>:)</E></r>",
|
||||
'poll_options' => array(
|
||||
'<t>[flash=12,34]http://example.org/x.swf[/flash]</t>',
|
||||
'<r><E>:)</E></r>'
|
||||
)
|
||||
),
|
||||
array('You cannot use certain BBCodes: [flash].')
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'poll_title' => 'xxx',
|
||||
'poll_option_text' => "[b]x\ny[/b]",
|
||||
'poll_max_options' => 2,
|
||||
'poll_options_size' => 2
|
||||
),
|
||||
array(
|
||||
'poll_title' => '<t>xxx</t>',
|
||||
'poll_option_text' => "<r><B><s>[b]</s>x</B></r>\n<t>y[/b]</t>",
|
||||
'poll_options' => array(
|
||||
'<r><B><s>[b]</s>x</B></r>',
|
||||
'<t>y[/b]</t>',
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_test_cases
|
||||
*/
|
||||
public function test_options($original, $expected, array $args, $setup = null, $warn_msg = array())
|
||||
{
|
||||
$this->prepare_s9e_services($setup);
|
||||
|
||||
$message_parser = new parse_message($original);
|
||||
call_user_func_array(array($message_parser, 'parse'), $args);
|
||||
|
||||
$this->assertSame($expected, $message_parser->message);
|
||||
$this->assertSame($warn_msg, $message_parser->warn_msg);
|
||||
}
|
||||
|
||||
public function get_test_cases()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'[b]bold[/b]',
|
||||
'<r><B><s>[b]</s>bold<e>[/b]</e></B></r>',
|
||||
array(true, true, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
'[b]bold[/b]',
|
||||
'<t>[b]bold[/b]</t>',
|
||||
array(false, true, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
'http://example.org',
|
||||
'<r><URL url="http://example.org">http://example.org</URL></r>',
|
||||
array(true, true, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
'http://example.org',
|
||||
'<t>http://example.org</t>',
|
||||
array(true, false, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
':)',
|
||||
'<r><E>:)</E></r>',
|
||||
array(true, true, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
':)',
|
||||
'<t>:)</t>',
|
||||
array(true, true, false, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
'[url=http://example.org][img]http://example.org/img.png[/img][/url]',
|
||||
'<r><URL url="http://example.org"><s>[url=http://example.org]</s><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG><e>[/url]</e></URL></r>',
|
||||
array(true, true, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
'[url=http://example.org][img]http://example.org/img.png[/img][/url]',
|
||||
'<r><URL url="http://example.org"><s>[url=http://example.org]</s>[img]http://example.org/img.png[/img]<e>[/url]</e></URL></r>',
|
||||
array(true, true, true, false, true, true, true),
|
||||
null,
|
||||
array('You cannot use certain BBCodes: [img].')
|
||||
),
|
||||
array(
|
||||
'[flash=12,34]http://example.org/foo.swf[/flash]',
|
||||
'<r><FLASH height="34" url="http://example.org/foo.swf" width="12"><s>[flash=12,34]</s><URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL><e>[/flash]</e></FLASH></r>',
|
||||
array(true, true, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
'[flash=12,34]http://example.org/foo.swf[/flash]',
|
||||
'<r>[flash=12,34]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>',
|
||||
array(true, true, true, true, false, true, true),
|
||||
null,
|
||||
array('You cannot use certain BBCodes: [flash].')
|
||||
),
|
||||
array(
|
||||
'[quote="foo"]bar :)[/quote]',
|
||||
'<r><QUOTE author="foo"><s>[quote="foo"]</s>bar <E>:)</E><e>[/quote]</e></QUOTE></r>',
|
||||
array(true, true, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
'[quote="foo"]bar :)[/quote]',
|
||||
'<r>[quote="foo"]bar <E>:)</E>[/quote]</r>',
|
||||
array(true, true, true, true, true, false, true),
|
||||
null,
|
||||
array('You cannot use certain BBCodes: [quote].')
|
||||
),
|
||||
array(
|
||||
'[url=http://example.org][img]http://example.org/img.png[/img][/url]',
|
||||
'<r><URL url="http://example.org"><s>[url=http://example.org]</s><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG><e>[/url]</e></URL></r>',
|
||||
array(true, true, true, true, true, true, true)
|
||||
),
|
||||
array(
|
||||
'[url=http://example.org][img]http://example.org/img.png[/img][/url]',
|
||||
'<r>[url=http://example.org]<IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG>[/url]</r>',
|
||||
array(true, true, true, true, true, true, false),
|
||||
null,
|
||||
array('You cannot use certain BBCodes: [url].')
|
||||
),
|
||||
array(
|
||||
'[size=200]200[/size]',
|
||||
'<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_font_size', 200);
|
||||
}
|
||||
),
|
||||
array(
|
||||
'[size=200]200[/size]',
|
||||
'<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_font_size', 0);
|
||||
}
|
||||
),
|
||||
array(
|
||||
'[size=2000]2000[/size]',
|
||||
'<t>[size=2000]2000[/size]</t>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_font_size', 200);
|
||||
},
|
||||
array('You may only use fonts up to size 200.')
|
||||
),
|
||||
array(
|
||||
'[size=0]0[/size]',
|
||||
'<t>[size=0]0[/size]</t>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_font_size', 200);
|
||||
}
|
||||
),
|
||||
array(
|
||||
'[size=200]200[/size]',
|
||||
'<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_sig_font_size', 200);
|
||||
}
|
||||
),
|
||||
array(
|
||||
'[size=200]200[/size]',
|
||||
'<t>[size=200]200[/size]</t>',
|
||||
array(true, true, true, true, true, true, true, true, 'sig'),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_sig_font_size', 120);
|
||||
},
|
||||
array('You may only use fonts up to size 120.')
|
||||
),
|
||||
array(
|
||||
'[img]http://example.org/100x100.png[/img]',
|
||||
'<r>[img]<URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL>[/img]</r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_img_height', 12);
|
||||
},
|
||||
array('Your images may only be up to 12 pixels high.')
|
||||
),
|
||||
array(
|
||||
'[img]http://example.org/100x100.png[/img]',
|
||||
'<r>[img]<URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL>[/img]</r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_img_width', 34);
|
||||
},
|
||||
array('Your images may only be up to 34 pixels wide.')
|
||||
),
|
||||
array(
|
||||
'[img]http://example.org/100x100.png[/img]',
|
||||
'<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_img_height', 0);
|
||||
$phpbb_container->get('config')->set('max_post_img_width', 0);
|
||||
}
|
||||
),
|
||||
array(
|
||||
'[img]http://example.org/100x100.png[/img]',
|
||||
'<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_img_height', 100);
|
||||
$phpbb_container->get('config')->set('max_post_img_width', 100);
|
||||
}
|
||||
),
|
||||
array(
|
||||
'[img]http://example.org/100x100.png[/img]',
|
||||
'<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_sig_img_height', 12);
|
||||
$phpbb_container->get('config')->set('max_sig_img_width', 34);
|
||||
}
|
||||
),
|
||||
array(
|
||||
'[img]http://example.org/404.png[/img]',
|
||||
'<r>[img]<URL url="http://example.org/404.png">http://example.org/404.png</URL>[/img]</r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_img_height', 12);
|
||||
},
|
||||
array('It was not possible to determine the dimensions of the image.')
|
||||
),
|
||||
array(
|
||||
'[flash=999,999]http://example.org/foo.swf[/flash]',
|
||||
'<r>[flash=999,999]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_img_height', 123);
|
||||
},
|
||||
array('Your flash files may only be up to 123 pixels high.')
|
||||
),
|
||||
array(
|
||||
'[flash=999,999]http://example.org/foo.swf[/flash]',
|
||||
'<r>[flash=999,999]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>',
|
||||
array(true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_img_width', 456);
|
||||
},
|
||||
array('Your flash files may only be up to 456 pixels wide.')
|
||||
),
|
||||
array(
|
||||
':) :) :)',
|
||||
'<r><E>:)</E> <E>:)</E> <E>:)</E></r>',
|
||||
array(true, true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_smilies', 3);
|
||||
}
|
||||
),
|
||||
array(
|
||||
':) :) :) :)',
|
||||
'<r><E>:)</E> <E>:)</E> <E>:)</E> :)</r>',
|
||||
array(true, true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_smilies', 3);
|
||||
},
|
||||
array('Your message contains too many smilies. The maximum number of smilies allowed is 3.')
|
||||
),
|
||||
array(
|
||||
':) :) :) :)',
|
||||
'<r><E>:)</E> <E>:)</E> <E>:)</E> <E>:)</E></r>',
|
||||
array(true, true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_smilies', 0);
|
||||
}
|
||||
),
|
||||
array(
|
||||
':) :) :) :)',
|
||||
'<r><E>:)</E> <E>:)</E> <E>:)</E> <E>:)</E></r>',
|
||||
array(true, true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_sig_smilies', 3);
|
||||
}
|
||||
),
|
||||
array(
|
||||
':) :) :) :)',
|
||||
'<r><E>:)</E> <E>:)</E> <E>:)</E> :)</r>',
|
||||
array(true, true, true, true, true, true, true, true, 'sig'),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_sig_smilies', 3);
|
||||
},
|
||||
array('Your message contains too many smilies. The maximum number of smilies allowed is 3.')
|
||||
),
|
||||
array(
|
||||
'http://example.org http://example.org http://example.org',
|
||||
'<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> http://example.org</r>',
|
||||
array(true, true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_urls', 2);
|
||||
},
|
||||
array('Your message contains too many URLs. The maximum number of URLs allowed is 2.')
|
||||
),
|
||||
array(
|
||||
'http://example.org http://example.org http://example.org',
|
||||
'<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL></r>',
|
||||
array(true, true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_post_urls', 0);
|
||||
}
|
||||
),
|
||||
array(
|
||||
'http://example.org http://example.org http://example.org',
|
||||
'<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL></r>',
|
||||
array(true, true, true, true, true, true, true, true),
|
||||
function ($parser, $phpbb_container)
|
||||
{
|
||||
$phpbb_container->get('config')->set('max_sig_urls', 2);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class phpbb_text_processing_message_parser_test_proxy
|
||||
{
|
||||
protected $response;
|
||||
|
||||
public function stream_open($url)
|
||||
{
|
||||
if (strpos($url, '100x100'))
|
||||
{
|
||||
// Return a 100 x 100 PNG image
|
||||
$this->response = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAAAE0lEQVR4AWOgKxgFo2AUjIJRAAAFeAABHs0ozQAAAABJRU5ErkJggg==');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response = '404 not found';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function stream_stat()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function stream_read($len)
|
||||
{
|
||||
$chunk = substr($this->response, 0, $len);
|
||||
$this->response = substr($this->response, $len);
|
||||
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
public function stream_eof()
|
||||
{
|
||||
return ($this->response === false);
|
||||
}
|
||||
}
|
48
tests/text_processing/smilies_test.php
Normal file
48
tests/text_processing/smilies_test.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
|
||||
|
||||
class phpbb_text_processing_smilies_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* @dataProvider get_text_formatter_tests
|
||||
*/
|
||||
public function test_text_formatter($original, $expected)
|
||||
{
|
||||
$container = $this->get_test_case_helpers()->set_s9e_services(null, __DIR__ . '/fixtures/smilies.xml');
|
||||
$parser = $container->get('text_formatter.parser');
|
||||
$renderer = $container->get('text_formatter.renderer');
|
||||
|
||||
$this->assertSame($expected, $renderer->render($parser->parse($original)));
|
||||
}
|
||||
|
||||
public function get_text_formatter_tests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
':) beginning',
|
||||
'<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile"> beginning'
|
||||
),
|
||||
array(
|
||||
'end :)',
|
||||
'end <img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">'
|
||||
),
|
||||
array(
|
||||
':)',
|
||||
'<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">'
|
||||
),
|
||||
array(
|
||||
'xx (18) 8) xx',
|
||||
'xx (18) <img class="smilies" src="phpBB/images/smilies/custom.gif" alt="8)" title="8)"> xx'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
38
tests/text_processing/strip_bbcode_test.php
Normal file
38
tests/text_processing/strip_bbcode_test.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
|
||||
|
||||
class phpbb_text_processing_strip_bbcode_test extends phpbb_test_case
|
||||
{
|
||||
public function test_legacy()
|
||||
{
|
||||
$original = '[b:20m4ill1]bold[/b:20m4ill1]';
|
||||
$expected = ' bold ';
|
||||
|
||||
$actual = $original;
|
||||
strip_bbcode($actual);
|
||||
|
||||
$this->assertSame($expected, $actual, '20m4ill1');
|
||||
}
|
||||
|
||||
public function test_s9e()
|
||||
{
|
||||
$phpbb_container = $this->get_test_case_helpers()->set_s9e_services();
|
||||
|
||||
$original = '<r><B><s>[b]</s>bold<e>[/b]</e></B></r>';
|
||||
$expected = ' bold ';
|
||||
|
||||
$actual = $original;
|
||||
strip_bbcode($actual);
|
||||
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
}
|
2
tests/text_processing/tickets_data/PHPBB3-10002.html
Normal file
2
tests/text_processing/tickets_data/PHPBB3-10002.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<blockquote class="uncited"><div><ul><li>one
|
||||
<blockquote class="uncited"><div><ul><li>two</li></ul></div></blockquote></li></ul></div></blockquote>
|
2
tests/text_processing/tickets_data/PHPBB3-10002.txt
Normal file
2
tests/text_processing/tickets_data/PHPBB3-10002.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
[quote][list][*]one
|
||||
[quote][list][*]two[/list][/quote]
|
3
tests/text_processing/tickets_data/PHPBB3-10425.html
Normal file
3
tests/text_processing/tickets_data/PHPBB3-10425.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">http://ar.wikipedia.org/wiki/الصفحة_الرئيسية</a><br>
|
||||
<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">http://ar.wikipedia.org/wiki/الصفحة_الرئيسية</a><br>
|
||||
<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">link</a>
|
3
tests/text_processing/tickets_data/PHPBB3-10425.txt
Normal file
3
tests/text_processing/tickets_data/PHPBB3-10425.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
http://ar.wikipedia.org/wiki/الصفحة_الرئيسية
|
||||
[url]http://ar.wikipedia.org/wiki/الصفحة_الرئيسية[/url]
|
||||
[url=http://ar.wikipedia.org/wiki/الصفحة_الرئيسية]link[/url]
|
2
tests/text_processing/tickets_data/PHPBB3-10587.html
Normal file
2
tests/text_processing/tickets_data/PHPBB3-10587.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<a href="http://www.tx-gaming.net/warzone/tournament.php?tourney%5Bid%5D=34&action=brackets" class="postlink">http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets</a><br>
|
||||
<a href="http://www.tx-gaming.net/warzone/tournament.php?tourney%5Bid%5D=34&action=brackets" class="postlink">link</a>
|
2
tests/text_processing/tickets_data/PHPBB3-10587.txt
Normal file
2
tests/text_processing/tickets_data/PHPBB3-10587.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
[url]http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets[/url]
|
||||
[url="http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets"]link[/url]
|
1
tests/text_processing/tickets_data/PHPBB3-10922.html
Normal file
1
tests/text_processing/tickets_data/PHPBB3-10922.html
Normal file
@@ -0,0 +1 @@
|
||||
<a href="mailto:user@example.org">user@example.org</a><a href="mailto:user@example.org">...</a>
|
1
tests/text_processing/tickets_data/PHPBB3-10922.txt
Normal file
1
tests/text_processing/tickets_data/PHPBB3-10922.txt
Normal file
@@ -0,0 +1 @@
|
||||
[email]user@example.org[/email][email=user@example.org]...[/email]
|
8
tests/text_processing/tickets_data/PHPBB3-10989.html
Normal file
8
tests/text_processing/tickets_data/PHPBB3-10989.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<blockquote><div><cite>Lorem wrote:</cite>[quote="Lorem"<blockquote class="uncited"><div> Suspendisse iaculis porta tempor. Nulla.</div></blockquote>
|
||||
Nullam a tortor sit amet.</div></blockquote>
|
||||
Proin ac mi eget magna.
|
||||
|
||||
<blockquote><div><cite>Lorem wrote:</cite>Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.</div></blockquote>
|
||||
|
||||
<br>
|
||||
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper.
|
8
tests/text_processing/tickets_data/PHPBB3-10989.txt
Normal file
8
tests/text_processing/tickets_data/PHPBB3-10989.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
[quote="Lorem"][quote="Lorem"[quote] Suspendisse iaculis porta tempor. Nulla.[/quote]
|
||||
Nullam a tortor sit amet.[/quote]
|
||||
Proin ac mi eget magna.
|
||||
|
||||
[quote="Lorem"]Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.[/quote]
|
||||
|
||||
|
||||
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper.
|
1
tests/text_processing/tickets_data/PHPBB3-11153.html
Normal file
1
tests/text_processing/tickets_data/PHPBB3-11153.html
Normal file
@@ -0,0 +1 @@
|
||||
<a href="mailto:user@example.org">...</a>
|
1
tests/text_processing/tickets_data/PHPBB3-11153.txt
Normal file
1
tests/text_processing/tickets_data/PHPBB3-11153.txt
Normal file
@@ -0,0 +1 @@
|
||||
[myemail=user@example.org]...[/myemail]
|
28
tests/text_processing/tickets_data/PHPBB3-11153.xml
Normal file
28
tests/text_processing/tickets_data/PHPBB3-11153.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_bbcodes">
|
||||
<column>bbcode_id</column>
|
||||
<column>bbcode_tag</column>
|
||||
<column>bbcode_helpline</column>
|
||||
<column>display_on_posting</column>
|
||||
<column>bbcode_match</column>
|
||||
<column>bbcode_tpl</column>
|
||||
<column>first_pass_match</column>
|
||||
<column>first_pass_replace</column>
|
||||
<column>second_pass_match</column>
|
||||
<column>second_pass_replace</column>
|
||||
|
||||
<row>
|
||||
<value>13</value>
|
||||
<value>myemail</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>[myemail={EMAIL}]{TEXT}[/myemail]</value>
|
||||
<value><![CDATA[<a href="mailto:{EMAIL}">{TEXT}</a>]]></value>
|
||||
<value><![CDATA[!\[myemail\=(([\w\!\#$\%\&'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%'\*\+\-\/\=\?\^\`{\|\}\~]|&)+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?))\](.*?)\[/myemail\]!ies]]></value>
|
||||
<value><![CDATA['[myemail='.$this->bbcode_specialchars('${1}').':$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${2}')).'[/myemail:$uid]']]></value>
|
||||
<value><![CDATA[!\[myemail\=(([\w\!\#$\%\&'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%'\*\+\-\/\=\?\^\`{\|\}\~]|&)+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)):$uid\](.*?)\[/myemail:$uid\]!s]]></value>
|
||||
<value><![CDATA[<a href="mailto:${1}">${2}</a>]]></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
1
tests/text_processing/tickets_data/PHPBB3-12195.html
Normal file
1
tests/text_processing/tickets_data/PHPBB3-12195.html
Normal file
@@ -0,0 +1 @@
|
||||
<a href="//example.org/" class="postlink"><img src="//example.org/img.png" alt="Image"></a>
|
1
tests/text_processing/tickets_data/PHPBB3-12195.txt
Normal file
1
tests/text_processing/tickets_data/PHPBB3-12195.txt
Normal file
@@ -0,0 +1 @@
|
||||
[url=//example.org/][img]//example.org/img.png[/img][/url]
|
17
tests/text_processing/tickets_data/PHPBB3-3981.before.php
Normal file
17
tests/text_processing/tickets_data/PHPBB3-3981.before.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
function before_assert_phpbb3_3981($vars)
|
||||
{
|
||||
if (!function_exists('idn_to_ascii'))
|
||||
{
|
||||
extract($vars);
|
||||
$test->markTestSkipped('International URLs need idn_to_ascii()');
|
||||
}
|
||||
}
|
1
tests/text_processing/tickets_data/PHPBB3-3981.html
Normal file
1
tests/text_processing/tickets_data/PHPBB3-3981.html
Normal file
@@ -0,0 +1 @@
|
||||
<a href="http://www.xn--ndaaa.com" class="postlink">http://www.ööö.com</a>
|
1
tests/text_processing/tickets_data/PHPBB3-3981.txt
Normal file
1
tests/text_processing/tickets_data/PHPBB3-3981.txt
Normal file
@@ -0,0 +1 @@
|
||||
[url]http://www.ööö.com[/url]
|
1
tests/text_processing/tickets_data/PHPBB3-7187.html
Normal file
1
tests/text_processing/tickets_data/PHPBB3-7187.html
Normal file
@@ -0,0 +1 @@
|
||||
<blockquote class="uncited"><div><img class="smilies" src="phpBB/images/smilies/icon_e_geek.gif" alt=":geek:" title="Geek"> <img class="smilies" src="phpBB/images/smilies/icon_e_ugeek.gif" alt=":ugeek:" title="Uber Geek"></div></blockquote>
|
1
tests/text_processing/tickets_data/PHPBB3-7187.txt
Normal file
1
tests/text_processing/tickets_data/PHPBB3-7187.txt
Normal file
@@ -0,0 +1 @@
|
||||
[quote]:geek: :ugeek:[/quote]
|
33
tests/text_processing/tickets_data/PHPBB3-7187.xml
Normal file
33
tests/text_processing/tickets_data/PHPBB3-7187.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_smilies">
|
||||
<column>smiley_id</column>
|
||||
<column>code</column>
|
||||
<column>emotion</column>
|
||||
<column>smiley_url</column>
|
||||
<column>smiley_width</column>
|
||||
<column>smiley_height</column>
|
||||
<column>smiley_order</column>
|
||||
<column>display_on_posting</column>
|
||||
<row>
|
||||
<value>41</value>
|
||||
<value>:geek:</value>
|
||||
<value>Geek</value>
|
||||
<value>icon_e_geek.gif</value>
|
||||
<value>17</value>
|
||||
<value>17</value>
|
||||
<value>41</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>42</value>
|
||||
<value>:ugeek:</value>
|
||||
<value>Uber Geek</value>
|
||||
<value>icon_e_ugeek.gif</value>
|
||||
<value>17</value>
|
||||
<value>18</value>
|
||||
<value>42</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
15
tests/text_processing/tickets_data/PHPBB3-7275.after.php
Normal file
15
tests/text_processing/tickets_data/PHPBB3-7275.after.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
function after_assert_phpbb3_7275($vars)
|
||||
{
|
||||
extract($vars);
|
||||
decode_message($parsed_text);
|
||||
$test->assertSame($original, $parsed_text);
|
||||
}
|
1
tests/text_processing/tickets_data/PHPBB3-7275.html
Normal file
1
tests/text_processing/tickets_data/PHPBB3-7275.html
Normal file
@@ -0,0 +1 @@
|
||||
<div align="center"><img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile"></div>
|
1
tests/text_processing/tickets_data/PHPBB3-7275.txt
Normal file
1
tests/text_processing/tickets_data/PHPBB3-7275.txt
Normal file
@@ -0,0 +1 @@
|
||||
[center]:)[/center]
|
49
tests/text_processing/tickets_data/PHPBB3-7275.xml
Normal file
49
tests/text_processing/tickets_data/PHPBB3-7275.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_bbcodes">
|
||||
<column>bbcode_id</column>
|
||||
<column>bbcode_tag</column>
|
||||
<column>bbcode_helpline</column>
|
||||
<column>display_on_posting</column>
|
||||
<column>bbcode_match</column>
|
||||
<column>bbcode_tpl</column>
|
||||
<column>first_pass_match</column>
|
||||
<column>first_pass_replace</column>
|
||||
<column>second_pass_match</column>
|
||||
<column>second_pass_replace</column>
|
||||
|
||||
<row>
|
||||
<value>13</value>
|
||||
<value>center</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>[center]{TEXT}[/center]</value>
|
||||
<value><![CDATA[<div align="center">{TEXT}</div>]]></value>
|
||||
<value>!\[center\](.*?)\[/center\]!ies</value>
|
||||
<value><![CDATA['[center:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${1}')).'[/center:$uid]']]></value>
|
||||
<value>!\[center:$uid\](.*?)\[/center:$uid\]!s</value>
|
||||
<value><![CDATA[<div align="center">${1}</div>]]></value>
|
||||
</row>
|
||||
</table>
|
||||
|
||||
<table name="phpbb_smilies">
|
||||
<column>smiley_id</column>
|
||||
<column>code</column>
|
||||
<column>emotion</column>
|
||||
<column>smiley_url</column>
|
||||
<column>smiley_width</column>
|
||||
<column>smiley_height</column>
|
||||
<column>smiley_order</column>
|
||||
<column>display_on_posting</column>
|
||||
<row>
|
||||
<value>4</value>
|
||||
<value>:)</value>
|
||||
<value>Smile</value>
|
||||
<value>icon_e_smile.gif</value>
|
||||
<value>15</value>
|
||||
<value>17</value>
|
||||
<value>4</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
1
tests/text_processing/tickets_data/PHPBB3-9377.html
Normal file
1
tests/text_processing/tickets_data/PHPBB3-9377.html
Normal file
@@ -0,0 +1 @@
|
||||
<span style="color:red">red <span style="color:blue">blue</span> red</span>
|
1
tests/text_processing/tickets_data/PHPBB3-9377.txt
Normal file
1
tests/text_processing/tickets_data/PHPBB3-9377.txt
Normal file
@@ -0,0 +1 @@
|
||||
[red]red [blue]blue[/blue] red[/red]
|
41
tests/text_processing/tickets_data/PHPBB3-9377.xml
Normal file
41
tests/text_processing/tickets_data/PHPBB3-9377.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_bbcodes">
|
||||
<column>bbcode_id</column>
|
||||
<column>bbcode_tag</column>
|
||||
<column>bbcode_helpline</column>
|
||||
<column>display_on_posting</column>
|
||||
<column>bbcode_match</column>
|
||||
<column>bbcode_tpl</column>
|
||||
<column>first_pass_match</column>
|
||||
<column>first_pass_replace</column>
|
||||
<column>second_pass_match</column>
|
||||
<column>second_pass_replace</column>
|
||||
|
||||
<row>
|
||||
<value>13</value>
|
||||
<value>red</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>[red]{TEXT}[/red]</value>
|
||||
<value><span style="color:red">{TEXT}</span></value>
|
||||
<value>!\[red\](.*?)\[/red\]!ies</value>
|
||||
<value>'[red:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/red:$uid]'</value>
|
||||
<value>!\[red:$uid\](.*?)\[/red:$uid\]!s</value>
|
||||
<value><span style="color:red">${1}</span></value>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<value>14</value>
|
||||
<value>blue</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>[blue]{TEXT}[/blue]</value>
|
||||
<value><span style="color:blue">{TEXT}</span></value>
|
||||
<value>!\[blue\](.*?)\[/blue\]!ies</value>
|
||||
<value>'[blue:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/blue:$uid]'</value>
|
||||
<value>!\[blue:$uid\](.*?)\[/blue:$uid\]!s</value>
|
||||
<value><span style="color:blue">${1}</span></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
91
tests/text_processing/tickets_test.php
Normal file
91
tests/text_processing/tickets_test.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
|
||||
require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
|
||||
require_once __DIR__ . '/../mock/container_builder.php';
|
||||
|
||||
class phpbb_text_processing_tickets_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* @dataProvider get_tickets_data
|
||||
*/
|
||||
public function test_tickets($ticket_id, $original, $expected, $fixture, $before_assert, $after_assert)
|
||||
{
|
||||
global $phpbb_container;
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder;
|
||||
|
||||
$this->get_test_case_helpers()->set_s9e_services($phpbb_container, $fixture);
|
||||
|
||||
$parser = $phpbb_container->get('text_formatter.parser');
|
||||
$renderer = $phpbb_container->get('text_formatter.renderer');
|
||||
|
||||
if (isset($before_assert))
|
||||
{
|
||||
$test = $this;
|
||||
$before_assert(get_defined_vars());
|
||||
}
|
||||
|
||||
$parsed_text = $parser->parse($original);
|
||||
|
||||
$this->assertSame($expected, $renderer->render($parsed_text));
|
||||
|
||||
if (isset($after_assert))
|
||||
{
|
||||
$test = $this;
|
||||
$after_assert(get_defined_vars());
|
||||
}
|
||||
}
|
||||
|
||||
public function get_tickets_data()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
foreach (glob(__DIR__ . '/tickets_data/*.txt') as $txt_filename)
|
||||
{
|
||||
$ticket_id = basename($txt_filename, '.txt');
|
||||
$html_filename = substr($txt_filename, 0, -3) . 'html';
|
||||
$xml_filename = substr($txt_filename, 0, -3) . 'xml';
|
||||
$before_filename = substr($txt_filename, 0, -3) . 'before.php';
|
||||
$after_filename = substr($txt_filename, 0, -3) . 'after.php';
|
||||
|
||||
if (!file_exists($xml_filename))
|
||||
{
|
||||
$xml_filename = __DIR__ . '/../fixtures/empty.xml';
|
||||
}
|
||||
|
||||
$before_assert = null;
|
||||
if (file_exists($before_filename))
|
||||
{
|
||||
include($before_filename);
|
||||
$before_assert = 'before_assert_' . strtolower(str_replace('-', '_', $ticket_id));
|
||||
}
|
||||
|
||||
$after_assert = null;
|
||||
if (file_exists($after_filename))
|
||||
{
|
||||
include($after_filename);
|
||||
$after_assert = 'after_assert_' . strtolower(str_replace('-', '_', $ticket_id));
|
||||
}
|
||||
|
||||
$tests[] = array(
|
||||
$ticket_id,
|
||||
file_get_contents($txt_filename),
|
||||
file_get_contents($html_filename),
|
||||
$xml_filename,
|
||||
$before_assert,
|
||||
$after_assert
|
||||
);
|
||||
}
|
||||
|
||||
return $tests;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user