Merge pull request #7765 from nupplaphil/task/move_text
Move include/text.php to class structure
This commit is contained in:
commit
9f460c6797
32 changed files with 734 additions and 453 deletions
13
tests/src/Content/ItemTest.php
Normal file
13
tests/src/Content/ItemTest.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\src\Content;
|
||||
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ItemTest extends MockedTest
|
||||
{
|
||||
public function testDetermineCategoriesTerms()
|
||||
{
|
||||
$this->markTestIncomplete('Test data needed.');
|
||||
}
|
||||
}
|
43
tests/src/Content/Text/BBCode/VideoTest.php
Normal file
43
tests/src/Content/Text/BBCode/VideoTest.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Content\Text\BBCode;
|
||||
|
||||
use Friendica\Content\Text\BBCode\Video;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class VideoTest extends MockedTest
|
||||
{
|
||||
public function dataVideo()
|
||||
{
|
||||
return [
|
||||
'youtube' => [
|
||||
'input' => '[video]https://youtube.link/4523[/video]',
|
||||
'assert' => '[youtube]https://youtube.link/4523[/youtube]',
|
||||
],
|
||||
'youtu.be' => [
|
||||
'input' => '[video]https://youtu.be.link/4523[/video]',
|
||||
'assert' => '[youtube]https://youtu.be.link/4523[/youtube]',
|
||||
],
|
||||
'vimeo' => [
|
||||
'input' => '[video]https://vimeo.link/2343[/video]',
|
||||
'assert' => '[vimeo]https://vimeo.link/2343[/vimeo]',
|
||||
],
|
||||
'mixed' => [
|
||||
'input' => '[video]https://vimeo.link/2343[/video] With other [b]string[/b] [video]https://youtu.be/blaa[/video]',
|
||||
'assert' => '[vimeo]https://vimeo.link/2343[/vimeo] With other [b]string[/b] [youtube]https://youtu.be/blaa[/youtube]',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the BBCode is successfully transformed for video links
|
||||
*
|
||||
* @dataProvider dataVideo
|
||||
*/
|
||||
public function testTransform(string $input, string $assert)
|
||||
{
|
||||
$bbCodeVideo = new Video();
|
||||
|
||||
$this->assertEquals($assert, $bbCodeVideo->transform($input));
|
||||
}
|
||||
}
|
|
@ -339,9 +339,6 @@ class InstallerTest extends MockedTest
|
|||
// Mocking that we can use CURL
|
||||
$this->setFunctions(['curl_init' => true]);
|
||||
|
||||
// needed because of "normalise_link"
|
||||
require_once __DIR__ . '/../../../include/text.php';
|
||||
|
||||
$install = new Installer();
|
||||
|
||||
$this->assertTrue($install->checkHtAccess('https://test'));
|
||||
|
|
57
tests/src/Protocol/ActivityTest.php
Normal file
57
tests/src/Protocol/ActivityTest.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Protocol;
|
||||
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ActivityTest extends MockedTest
|
||||
{
|
||||
public function dataMatch()
|
||||
{
|
||||
return [
|
||||
'empty' => [
|
||||
'haystack' => '',
|
||||
'needle' => '',
|
||||
'assert' => true,
|
||||
],
|
||||
'simple' => [
|
||||
'haystack' => ACTIVITY_OBJ_TAGTERM,
|
||||
'needle' => ACTIVITY_OBJ_TAGTERM,
|
||||
'assert' => true,
|
||||
],
|
||||
'withNamespace' => [
|
||||
'haystack' => 'tagterm',
|
||||
'needle' => NAMESPACE_ACTIVITY_SCHEMA . ACTIVITY_OBJ_TAGTERM,
|
||||
'assert' => true,
|
||||
],
|
||||
'invalidSimple' => [
|
||||
'haystack' => 'tagterm',
|
||||
'needle' => '',
|
||||
'assert' => false,
|
||||
],
|
||||
'invalidWithOutNamespace' => [
|
||||
'haystack' => 'tagterm',
|
||||
'needle' => ACTIVITY_OBJ_TAGTERM,
|
||||
'assert' => false,
|
||||
],
|
||||
'withSubPath' => [
|
||||
'haystack' => 'tagterm',
|
||||
'needle' => NAMESPACE_ACTIVITY_SCHEMA . '/bla/' . ACTIVITY_OBJ_TAGTERM,
|
||||
'assert' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the different, possible matchings
|
||||
*
|
||||
* @dataProvider dataMatch
|
||||
*/
|
||||
public function testMatch(string $haystack, string $needle, bool $assert)
|
||||
{
|
||||
$activity = new Activity();
|
||||
|
||||
$this->assertEquals($assert, $activity->match($haystack, $needle));
|
||||
}
|
||||
}
|
|
@ -1,63 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* TextTest class.
|
||||
*/
|
||||
|
||||
namespace Friendica\Test;
|
||||
namespace Friendica\Test\src\Util;
|
||||
|
||||
use Friendica\Model\Group;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests for text functions.
|
||||
* @brief ACLFormater utility testing class
|
||||
*/
|
||||
class TextTest extends TestCase
|
||||
class ACLFormaterTest extends 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 with empty input
|
||||
*/
|
||||
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"));
|
||||
}
|
||||
|
||||
/**
|
||||
* test expand_acl, perfect input
|
||||
*/
|
||||
public function testExpandAclNormal()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text='<1><2><3><' . Group::FOLLOWERS . '><' . Group::MUTUALS . '>';
|
||||
$this->assertEquals(array('1', '2', '3', Group::FOLLOWERS, Group::MUTUALS), expand_acl($text));
|
||||
$this->assertEquals(array('1', '2', '3', Group::FOLLOWERS, Group::MUTUALS), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,8 +27,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclBigNumber()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text='<1><' . PHP_INT_MAX . '><15>';
|
||||
$this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), expand_acl($text));
|
||||
$this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,8 +40,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclString()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<1><279012><tt>";
|
||||
$this->assertEquals(array('1', '279012'), expand_acl($text));
|
||||
$this->assertEquals(array('1', '279012'), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,8 +53,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclSpace()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<1><279 012><32>";
|
||||
$this->assertEquals(array('1', '32'), expand_acl($text));
|
||||
$this->assertEquals(array('1', '32'), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,8 +64,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclEmpty()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="";
|
||||
$this->assertEquals(array(), expand_acl($text));
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,8 +77,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclNoBrackets()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="According to documentation, that's invalid. "; //should be invalid
|
||||
$this->assertEquals(array(), expand_acl($text));
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,8 +90,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclJustOneBracket1()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<Another invalid string"; //should be invalid
|
||||
$this->assertEquals(array(), expand_acl($text));
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,8 +103,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclJustOneBracket2()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="Another invalid> string"; //should be invalid
|
||||
$this->assertEquals(array(), expand_acl($text));
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,8 +116,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclCloseOnly()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="Another> invalid> string>"; //should be invalid
|
||||
$this->assertEquals(array(), expand_acl($text));
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,8 +129,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclOpenOnly()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<Another< invalid string<"; //should be invalid
|
||||
$this->assertEquals(array(), expand_acl($text));
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,8 +142,10 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclNoMatching1()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<Another<> invalid <string>"; //should be invalid
|
||||
$this->assertEquals(array(), expand_acl($text));
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,18 +156,45 @@ class TextTest extends TestCase
|
|||
*/
|
||||
public function testExpandAclEmptyMatch()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<1><><3>";
|
||||
$this->assertEquals(array('1', '3'), expand_acl($text));
|
||||
$this->assertEquals(array('1', '3'), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
public function dataAclToString()
|
||||
{
|
||||
return [
|
||||
'empty' => [
|
||||
'input' => '',
|
||||
'assert' => '',
|
||||
],
|
||||
'string' => [
|
||||
'input' => '1,2,3,4',
|
||||
'assert' => '<1><2><3><4>',
|
||||
],
|
||||
'array' => [
|
||||
'input' => [1, 2, 3, 4],
|
||||
'assert' => '<1><2><3><4>',
|
||||
],
|
||||
'invalid' => [
|
||||
'input' => [1, 'a', 3, 4],
|
||||
'assert' => '<1><3><4>',
|
||||
],
|
||||
'invalidString' => [
|
||||
'input' => 'a,bsd23,4',
|
||||
'assert' => '<4>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test hex2bin and reverse
|
||||
* @dataProvider dataAclToString
|
||||
*/
|
||||
public function testHex2Bin()
|
||||
public function testAclToString($input, string $assert)
|
||||
{
|
||||
$this->assertEquals(-3, hex2bin(bin2hex(-3)));
|
||||
$this->assertEquals(0, hex2bin(bin2hex(0)));
|
||||
$this->assertEquals(12, hex2bin(bin2hex(12)));
|
||||
$this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX)));
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$this->assertEquals($assert, $aclFormatter->toString($input));
|
||||
}
|
||||
}
|
61
tests/src/Util/DateTimeFormatTest.php
Normal file
61
tests/src/Util/DateTimeFormatTest.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\src\Util;
|
||||
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
class DateTimeFormatTest extends MockedTest
|
||||
{
|
||||
public function dataYearMonth()
|
||||
{
|
||||
return [
|
||||
'validNormal' => [
|
||||
'input' => '1990-10',
|
||||
'assert' => true,
|
||||
],
|
||||
'validOneCharMonth' => [
|
||||
'input' => '1990-1',
|
||||
'assert' => true,
|
||||
],
|
||||
'validTwoCharMonth' => [
|
||||
'input' => '1990-01',
|
||||
'assert' => true,
|
||||
],
|
||||
'invalidFormat' => [
|
||||
'input' => '199-11',
|
||||
'assert' => false,
|
||||
],
|
||||
'invalidFormat2' => [
|
||||
'input' => '1990-15',
|
||||
'assert' => false,
|
||||
],
|
||||
'invalidFormat3' => [
|
||||
'input' => '99-101',
|
||||
'assert' => false,
|
||||
],
|
||||
'invalidFormat4' => [
|
||||
'input' => '11-1990',
|
||||
'assert' => false,
|
||||
],
|
||||
'invalidFuture' => [
|
||||
'input' => '3030-12',
|
||||
'assert' => false,
|
||||
],
|
||||
'invalidYear' => [
|
||||
'input' => '-100-10',
|
||||
'assert' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataYearMonth
|
||||
*/
|
||||
public function testIsYearMonth(string $input, bool $assert)
|
||||
{
|
||||
$dtFormat = new DateTimeFormat();
|
||||
|
||||
$this->assertEquals($assert, $dtFormat->isYearMonth($input));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue