mirror of
https://github.com/friendica/friendica
synced 2025-04-30 17:04:23 +02:00
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
200
tests/src/Util/ACLFormaterTest.php
Normal file
200
tests/src/Util/ACLFormaterTest.php
Normal file
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\src\Util;
|
||||
|
||||
use Friendica\Model\Group;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @brief ACLFormater utility testing class
|
||||
*/
|
||||
class ACLFormaterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 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), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test with a big number
|
||||
*/
|
||||
public function testExpandAclBigNumber()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text='<1><' . PHP_INT_MAX . '><15>';
|
||||
$this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test with a string in it.
|
||||
*
|
||||
* @todo is this valid input? Otherwise: should there be an exception?
|
||||
*/
|
||||
public function testExpandAclString()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<1><279012><tt>";
|
||||
$this->assertEquals(array('1', '279012'), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test with a ' ' in it.
|
||||
*
|
||||
* @todo is this valid input? Otherwise: should there be an exception?
|
||||
*/
|
||||
public function testExpandAclSpace()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<1><279 012><32>";
|
||||
$this->assertEquals(array('1', '32'), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test empty input
|
||||
*/
|
||||
public function testExpandAclEmpty()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="";
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid input, no < at all
|
||||
*
|
||||
* @todo should there be an exception?
|
||||
*/
|
||||
public function testExpandAclNoBrackets()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="According to documentation, that's invalid. "; //should be invalid
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid input, just open <
|
||||
*
|
||||
* @todo should there be an exception?
|
||||
*/
|
||||
public function testExpandAclJustOneBracket1()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<Another invalid string"; //should be invalid
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid input, just close >
|
||||
*
|
||||
* @todo should there be an exception?
|
||||
*/
|
||||
public function testExpandAclJustOneBracket2()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="Another invalid> string"; //should be invalid
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid input, just close >
|
||||
*
|
||||
* @todo should there be an exception?
|
||||
*/
|
||||
public function testExpandAclCloseOnly()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="Another> invalid> string>"; //should be invalid
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid input, just open <
|
||||
*
|
||||
* @todo should there be an exception?
|
||||
*/
|
||||
public function testExpandAclOpenOnly()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<Another< invalid string<"; //should be invalid
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid input, open and close do not match
|
||||
*
|
||||
* @todo should there be an exception?
|
||||
*/
|
||||
public function testExpandAclNoMatching1()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<Another<> invalid <string>"; //should be invalid
|
||||
$this->assertEquals(array(), $aclFormatter->expand($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* test invalid input, empty <>
|
||||
*
|
||||
* @todo should there be an exception? Or array(1, 3)
|
||||
* (This should be array(1,3) - mike)
|
||||
*/
|
||||
public function testExpandAclEmptyMatch()
|
||||
{
|
||||
$aclFormatter = new ACLFormatter();
|
||||
|
||||
$text="<1><><3>";
|
||||
$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>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataAclToString
|
||||
*/
|
||||
public function testAclToString($input, string $assert)
|
||||
{
|
||||
$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