added spaces (coding convention)

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-01-27 11:53:56 +01:00 committed by Roland Haeder
parent 951006dd10
commit c2d8738285
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
11 changed files with 336 additions and 330 deletions

View file

@ -1,51 +1,51 @@
<?php
/**
* this test tests the contains_attribute function
*
* @package test.util
*/
/** required, it is the file under test */
require_once('include/text.php');
/**
* TestCase for the contains_attribute function
*
* @author Alexander Kampmann
* @package test.util
*/
/**
* this test tests the contains_attribute function
*
* @package test.util
*/
/** required, it is the file under test */
require_once('include/text.php');
/**
* TestCase for the contains_attribute function
*
* @author Alexander Kampmann
* @package test.util
*/
class ContainsAttributeTest extends PHPUnit_Framework_TestCase {
/**
* test attribute contains
*/
public function testAttributeContains1() {
$testAttr="class1 notclass2 class3";
$this->assertTrue(attribute_contains($testAttr, "class3"));
$this->assertFalse(attribute_contains($testAttr, "class2"));
}
/**
* test attribute contains
*/
public function testAttributeContains2() {
$testAttr="class1 not-class2 class3";
$this->assertTrue(attribute_contains($testAttr, "class3"));
$this->assertFalse(attribute_contains($testAttr, "class2"));
}
/**
* test attribute contains
*/
public function testAttributeContains1() {
$testAttr="class1 notclass2 class3";
$this->assertTrue(attribute_contains($testAttr, "class3"));
$this->assertFalse(attribute_contains($testAttr, "class2"));
}
/**
* test attribute contains
*/
public function testAttributeContains2() {
$testAttr="class1 not-class2 class3";
$this->assertTrue(attribute_contains($testAttr, "class3"));
$this->assertFalse(attribute_contains($testAttr, "class2"));
}
/**
* test with empty input
*/
public function testAttributeContainsEmpty() {
$testAttr="";
$this->assertFalse(attribute_contains($testAttr, "class2"));
}
*/
public function testAttributeContainsEmpty() {
$testAttr="";
$this->assertFalse(attribute_contains($testAttr, "class2"));
}
/**
* test input with special chars
*/
public function testAttributeContainsSpecialChars() {
$testAttr="--... %\$ä() /(=?}";
$this->assertFalse(attribute_contains($testAttr, "class2"));
*/
public function testAttributeContainsSpecialChars() {
$testAttr="--... %\$ä() /(=?}";
$this->assertFalse(attribute_contains($testAttr, "class2"));
}
}

View file

@ -8,141 +8,141 @@
/** required, it is the file under test */
require_once('include/text.php');
/**
* TestCase for the expand_acl function
*
* @author Alexander Kampmann
* @package test.util
*/
/**
* TestCase for the expand_acl function
*
* @author Alexander Kampmann
* @package test.util
*/
class ExpandAclTest extends PHPUnit_Framework_TestCase {
/**
* test expand_acl, perfect input
*/
public function testExpandAclNormal() {
$text='<1><2><3>';
$this->assertEquals(array(1, 2, 3), expand_acl($text));
}
/**
* test expand_acl, perfect input
*/
public function testExpandAclNormal() {
$text='<1><2><3>';
$this->assertEquals(array(1, 2, 3), expand_acl($text));
}
/**
* test with a big number
*/
public function testExpandAclBigNumber() {
$text='<1><'.PHP_INT_MAX.'><15>';
$this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
}
*/
public function testExpandAclBigNumber() {
$text='<1><'.PHP_INT_MAX.'><15>';
$this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
}
/**
* test with a string in it.
*
* TODO: is this valid input? Otherwise: should there be an exception?
*/
public function testExpandAclString() {
$text="<1><279012><tt>";
$this->assertEquals(array(1, 279012), expand_acl($text));
}
*/
public function testExpandAclString() {
$text="<1><279012><tt>";
$this->assertEquals(array(1, 279012), expand_acl($text));
}
/**
* test with a ' ' in it.
*
* TODO: is this valid input? Otherwise: should there be an exception?
*/
public function testExpandAclSpace() {
$text="<1><279 012><32>";
$this->assertEquals(array(1, "279", "32"), expand_acl($text));
}
*/
public function testExpandAclSpace() {
$text="<1><279 012><32>";
$this->assertEquals(array(1, "279", "32"), expand_acl($text));
}
/**
* test empty input
*/
public function testExpandAclEmpty() {
$text="";
$this->assertEquals(array(), expand_acl($text));
}
*/
public function testExpandAclEmpty() {
$text="";
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, no < at all
*
* TODO: should there be an exception?
*/
public function testExpandAclNoBrackets() {
$text="According to documentation, that's invalid. "; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
*/
public function testExpandAclNoBrackets() {
$text="According to documentation, that's invalid. "; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, just open <
*
* TODO: should there be an exception?
*/
public function testExpandAclJustOneBracket1() {
$text="<Another invalid string"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, just open <
*
* TODO: should there be an exception?
*/
public function testExpandAclJustOneBracket1() {
$text="<Another invalid string"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, just close >
*
* TODO: should there be an exception?
*/
public function testExpandAclJustOneBracket2() {
$text="Another invalid> string"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, just close >
*
* TODO: should there be an exception?
*/
public function testExpandAclJustOneBracket2() {
$text="Another invalid> string"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, just close >
*
* TODO: should there be an exception?
*/
public function testExpandAclCloseOnly() {
$text="Another> invalid> string>"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, just close >
*
* TODO: should there be an exception?
*/
public function testExpandAclCloseOnly() {
$text="Another> invalid> string>"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, just open <
*
* TODO: should there be an exception?
*/
public function testExpandAclOpenOnly() {
$text="<Another< invalid string<"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, just open <
*
* TODO: should there be an exception?
*/
public function testExpandAclOpenOnly() {
$text="<Another< invalid string<"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, open and close do not match
*
* TODO: should there be an exception?
*/
public function testExpandAclNoMatching1() {
$text="<Another<> invalid <string>"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, open and close do not match
*
* TODO: should there be an exception?
*/
public function testExpandAclNoMatching1() {
$text="<Another<> invalid <string>"; //should be invalid
$this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, open and close do not match
*
* TODO: should there be an exception?
*/
public function testExpandAclNoMatching2() {
$text="<1>2><3>";
/**
* test invalid input, open and close do not match
*
* TODO: should there be an exception?
*/
public function testExpandAclNoMatching2() {
$text="<1>2><3>";
// The angles are delimiters which aren't important
// the important thing is the numeric content, this returns array(1,2,3) currently
// we may wish to eliminate 2 from the results, though it isn't harmful
// It would be a better test to figure out if there is any ACL input which can
// produce this $text and fix that instead.
// $this->assertEquals(array(), expand_acl($text));
// $this->assertEquals(array(), expand_acl($text));
}
/**
* test invalid input, empty <>
*
* TODO: should there be an exception? Or array(1, 3)
/**
* test invalid input, empty <>
*
* TODO: should there be an exception? Or array(1, 3)
* (This should be array(1,3) - mike)
*/
public function testExpandAclEmptyMatch() {
$text="<1><><3>";
$this->assertEquals(array(1,3), expand_acl($text));
*/
public function testExpandAclEmptyMatch() {
$text="<1><><3>";
$this->assertEquals(array(1,3), expand_acl($text));
}
}

View file

@ -44,23 +44,23 @@ function q($sql) {
$args=func_get_args();
//last parameter is always (in this test) uid, so, it should be 11
if($args[count($args)-1]!=11) {
if ($args[count($args)-1]!=11) {
return;
}
if(3==count($args)) {
if (3==count($args)) {
//first call in handle_body, id only
if($result[0]['id']==$args[1]) {
if ($result[0]['id']==$args[1]) {
return $result;
}
//second call in handle_body, name
if($result[0]['name']===$args[1]) {
if ($result[0]['name']===$args[1]) {
return $result;
}
}
//third call in handle_body, nick or attag
if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
if ($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
return $result;
}
}
@ -108,7 +108,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
$inform='';
$str_tags='';
foreach($tags as $tag) {
foreach ($tags as $tag) {
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
}
@ -197,7 +197,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
$inform='';
$str_tags='';
foreach($tags as $tag) {
foreach ($tags as $tag) {
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
}
@ -257,7 +257,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
$inform='';
$str_tags='';
foreach($tags as $tag) {
foreach ($tags as $tag) {
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
}

View file

@ -1,11 +1,11 @@
<?php
/**
* this file contains tests for the template engine
*
* @package test.util
*/
/** required, it is the file under test */
/**
* this file contains tests for the template engine
*
* @package test.util
*/
/** required, it is the file under test */
require_once('include/template_processor.php');
require_once('include/text.php');
@ -13,30 +13,30 @@ class TemplateMockApp {
public $theme_info=array();
}
if(!function_exists('current_theme')) {
function current_theme() {
return 'clean';
if (!function_exists('current_theme')) {
function current_theme() {
return 'clean';
}
}
if(!function_exists('x')) {
if (!function_exists('x')) {
function x($s,$k = NULL) {
return false;
}
}
if(!function_exists('get_app')) {
if (!function_exists('get_app')) {
function get_app() {
return new TemplateMockApp();
}
}
/**
* TestCase for the template engine
*
* @author Alexander Kampmann
* @package test.util
*/
/**
* TestCase for the template engine
*
* @author Alexander Kampmann
* @package test.util
*/
class TemplateTest extends PHPUnit_Framework_TestCase {
public function setUp() {
@ -58,167 +58,167 @@ class TemplateTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Hello Anna!', $text);
}
public function testSimpleVariableInt() {
$tpl='There are $num new messages!';
$text=replace_macros($tpl, array('$num'=>172));
$this->assertEquals('There are 172 new messages!', $text);
public function testSimpleVariableInt() {
$tpl='There are $num new messages!';
$text=replace_macros($tpl, array('$num'=>172));
$this->assertEquals('There are 172 new messages!', $text);
}
public function testConditionalElse() {
$tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
public function testConditionalElse() {
$tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
$text1=replace_macros($tpl, array('$num'=>1));
$text22=replace_macros($tpl, array('$num'=>22));
$text22=replace_macros($tpl, array('$num'=>22));
$this->assertEquals('There is 1 new message!', $text1);
$this->assertEquals('There are 22 new messages!', $text22);
$this->assertEquals('There are 22 new messages!', $text22);
}
public function testConditionalNoElse() {
$tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}';
$text0=replace_macros($tpl, array('$num'=>0));
$text22=replace_macros($tpl, array('$num'=>22));
$this->assertEquals('', $text0);
$this->assertEquals('There are 22 new messages!', $text22);
public function testConditionalNoElse() {
$tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}';
$text0=replace_macros($tpl, array('$num'=>0));
$text22=replace_macros($tpl, array('$num'=>22));
$this->assertEquals('', $text0);
$this->assertEquals('There are 22 new messages!', $text22);
}
public function testConditionalFail() {
$tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
$text1=replace_macros($tpl, array());
//$this->assertEquals('There is 1 new message!', $text1);
public function testConditionalFail() {
$tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
$text1=replace_macros($tpl, array());
//$this->assertEquals('There is 1 new message!', $text1);
}
public function testSimpleFor() {
$tpl='{{ for $messages as $message }} $message {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2')));
$this->assertEquals(' message 1 message 2 ', $text);
public function testSimpleFor() {
$tpl='{{ for $messages as $message }} $message {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2')));
$this->assertEquals(' message 1 message 2 ', $text);
}
public function testFor() {
$tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike'))));
$this->assertEquals(' from: Mike to Alex from: Alex to Mike ', $text);
public function testFor() {
$tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike'))));
$this->assertEquals(' from: Mike to Alex from: Alex to Mike ', $text);
}
public function testKeyedFor() {
$tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike')));
$this->assertEquals(' from: Mike to Alex from: Sven to Mike ', $text);
public function testKeyedFor() {
$tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike')));
$this->assertEquals(' from: Mike to Alex from: Sven to Mike ', $text);
}
public function testForEmpty() {
$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array()));
$this->assertEquals('messages: ', $text);
public function testForEmpty() {
$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array()));
$this->assertEquals('messages: ', $text);
}
public function testForWrongType() {
$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>11));
$this->assertEquals('messages: ', $text);
public function testForWrongType() {
$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>11));
$this->assertEquals('messages: ', $text);
}
public function testForConditional() {
$tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}';
public function testForConditional() {
$tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}';
$text=replace_macros($tpl, array('$messages'=>array(
array('new'=>true, 'text'=>'new message'),
array('new'=>false, 'text'=>'old message'))));
$this->assertEquals('new messages: new message', $text);
array('new'=>false, 'text'=>'old message'))));
$this->assertEquals('new messages: new message', $text);
}
public function testConditionalFor() {
$tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}';
public function testConditionalFor() {
$tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}';
$text=replace_macros($tpl, array('$enabled'=>true,
'$messages'=>array(
array('new'=>true, 'text'=>'new message'),
array('new'=>false, 'text'=>'old message'))));
$this->assertEquals('new messages: new message old message', $text);
'$messages'=>array(
array('new'=>true, 'text'=>'new message'),
array('new'=>false, 'text'=>'old message'))));
$this->assertEquals('new messages: new message old message', $text);
}
public function testFantasy() {
$tpl='Fantasy: {{fantasy $messages}}';
$text=replace_macros($tpl, array('$messages'=>'no no'));
$this->assertEquals('Fantasy: {{fantasy no no}}', $text);
public function testFantasy() {
$tpl='Fantasy: {{fantasy $messages}}';
$text=replace_macros($tpl, array('$messages'=>'no no'));
$this->assertEquals('Fantasy: {{fantasy no no}}', $text);
}
public function testInc() {
$tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}';
$text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help')));
public function testInc() {
$tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}';
$text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help')));
$this->assertEquals(" \n"
." <div class='field input'>\n"
." <label for='id_myfield'>label</label>\n"
." <input name='myfield' id='id_myfield' value=\"value\">\n"
." <span class='field_help'>help</span>\n"
." </div>\n", $text);
." </div>\n", $text);
}
public function testIncNoVar() {
$tpl='{{inc field_input.tpl }}{{ endinc }}';
$text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help')));
$this->assertEquals(" \n <div class='field input'>\n <label for='id_myfield'>label</label>\n"
." <input name='myfield' id='id_myfield' value=\"value\">\n"
." <span class='field_help'>help</span>\n"
." </div>\n", $text);
public function testIncNoVar() {
$tpl='{{inc field_input.tpl }}{{ endinc }}';
$text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help')));
$this->assertEquals(" \n <div class='field input'>\n <label for='id_myfield'>label</label>\n"
." <input name='myfield' id='id_myfield' value=\"value\">\n"
." <span class='field_help'>help</span>\n"
." </div>\n", $text);
}
public function testDoubleUse() {
$tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}';
$text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false));
public function testDoubleUse() {
$tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}';
$text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false));
$this->assertEquals('Hello Anna! ', $text);
$tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}';
$text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true));
$this->assertEquals('Hey Max! I hate you! ', $text);
$tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}';
$text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true));
$this->assertEquals('Hey Max! I hate you! ', $text);
}
public function testIncDouble() {
public function testIncDouble() {
$tpl='{{inc field_input.tpl with $field=$var1}}{{ endinc }}'
.'{{inc field_input.tpl with $field=$var2}}{{ endinc }}';
.'{{inc field_input.tpl with $field=$var2}}{{ endinc }}';
$text=replace_macros($tpl, array('$var1'=>array('myfield', 'label', 'value', 'help'),
'$var2'=>array('myfield2', 'label2', 'value2', 'help2')));
$this->assertEquals(" \n"
." <div class='field input'>\n"
." <label for='id_myfield'>label</label>\n"
." <input name='myfield' id='id_myfield' value=\"value\">\n"
." <span class='field_help'>help</span>\n"
'$var2'=>array('myfield2', 'label2', 'value2', 'help2')));
$this->assertEquals(" \n"
." <div class='field input'>\n"
." <label for='id_myfield'>label</label>\n"
." <input name='myfield' id='id_myfield' value=\"value\">\n"
." <span class='field_help'>help</span>\n"
." </div>\n"
." \n"
." <div class='field input'>\n"
." <label for='id_myfield2'>label2</label>\n"
." <input name='myfield2' id='id_myfield2' value=\"value2\">\n"
." <span class='field_help'>help2</span>\n"
." </div>\n", $text);
." </div>\n", $text);
}
}

View file

@ -33,13 +33,13 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($text, $retext);
}
/**
* xmlify and put in a document
*/
public function testXmlifyDocument() {
$tag="<tag>I want to break</tag>";
/**
* xmlify and put in a document
*/
public function testXmlifyDocument() {
$tag="<tag>I want to break</tag>";
$xml=xmlify($tag);
$text='<text>'.$xml.'</text>';
$text='<text>'.$xml.'</text>';
$xml_parser=xml_parser_create();
//should be possible to parse it
@ -48,10 +48,10 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(array('TEXT'=>array(0)),
$index);
$this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
$this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
$values);
xml_parser_free($xml_parser);
xml_parser_free($xml_parser);
}
/**