mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-10 17:14:26 +02:00
Deprecate page_info functions to new PageInfo class
- Add tests for parts not using remote requests - Add scheme requirement for page info URLs - Add policy to keep label from stripped Page Info links
This commit is contained in:
parent
eba964ec12
commit
f3323aff5e
4 changed files with 457 additions and 185 deletions
38
tests/src/Content/PageInfoMock.php
Normal file
38
tests/src/Content/PageInfoMock.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Content;
|
||||
|
||||
/**
|
||||
* Class PageInfoMock
|
||||
*
|
||||
* Exposes protected methods for test in the inherited class
|
||||
*
|
||||
* @method static string|null getRelevantUrlFromBody(string $body, $searchNakedUrls = false)
|
||||
* @method static string stripTrailingUrlFromBody(string $body, string $url)
|
||||
*/
|
||||
class PageInfoMock extends \Friendica\Content\PageInfo
|
||||
{
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
return self::$name(...$arguments);
|
||||
}
|
||||
}
|
125
tests/src/Content/PageInfoTest.php
Normal file
125
tests/src/Content/PageInfoTest.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Content;
|
||||
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class PageInfoTest extends MockedTest
|
||||
{
|
||||
public function dataGetRelevantUrlFromBody()
|
||||
{
|
||||
return [
|
||||
'end-of-content' => [
|
||||
'expected' => 'http://example.com/end-of-content',
|
||||
'body' => 'Content[url]http://example.com/end-of-content[/url]',
|
||||
],
|
||||
'tag-no-attr' => [
|
||||
'expected' => 'http://example.com/tag-no-attr',
|
||||
'body' => '[url]http://example.com/tag-no-attr[/url]',
|
||||
],
|
||||
'tag-attr' => [
|
||||
'expected' => 'http://example.com/tag-attr',
|
||||
'body' => '[url=http://example.com/tag-attr]Example.com[/url]',
|
||||
],
|
||||
'mention' => [
|
||||
'expected' => null,
|
||||
'body' => '@[url=http://example.com/mention]Mention[/url]',
|
||||
],
|
||||
'mention-exclusive' => [
|
||||
'expected' => null,
|
||||
'body' => '@[url=http://example.com/mention-exclusive]Mention Exclusive[/url]',
|
||||
],
|
||||
'hashtag' => [
|
||||
'expected' => null,
|
||||
'body' => '#[url=http://example.com/hashtag]hashtag[/url]',
|
||||
],
|
||||
'naked-url-unexpected' => [
|
||||
'expected' => null,
|
||||
'body' => 'http://example.com/naked-url-unexpected',
|
||||
],
|
||||
'naked-url-expected' => [
|
||||
'expected' => 'http://example.com/naked-url-expected',
|
||||
'body' => 'http://example.com/naked-url-expected',
|
||||
'searchNakedUrls' => true,
|
||||
],
|
||||
'naked-url-end-of-content-unexpected' => [
|
||||
'expected' => null,
|
||||
'body' => 'Contenthttp://example.com/naked-url-end-of-content-unexpected',
|
||||
'searchNakedUrls' => true,
|
||||
],
|
||||
'naked-url-end-of-content-expected' => [
|
||||
'expected' => 'http://example.com/naked-url-end-of-content-expected',
|
||||
'body' => 'Content http://example.com/naked-url-end-of-content-expected',
|
||||
'searchNakedUrls' => true,
|
||||
],
|
||||
'bug-8781-schemeless-link' => [
|
||||
'expected' => null,
|
||||
'body' => '[url]/posts/2576978090fd0138ee4c005056264835[/url]',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetRelevantUrlFromBody
|
||||
*
|
||||
* @param string|null $expected
|
||||
* @param string $body
|
||||
* @param bool $searchNakedUrls
|
||||
*/
|
||||
public function testGetRelevantUrlFromBody($expected, string $body, bool $searchNakedUrls = false)
|
||||
{
|
||||
$this->assertSame($expected, PageInfoMock::getRelevantUrlFromBody($body, $searchNakedUrls));
|
||||
}
|
||||
|
||||
public function dataStripTrailingUrlFromBody()
|
||||
{
|
||||
return [
|
||||
'naked-url-append' => [
|
||||
'expected' => 'content',
|
||||
'body' => 'contenthttps://example.com',
|
||||
'url' => 'https://example.com',
|
||||
],
|
||||
'naked-url-not-at-the-end' => [
|
||||
'expected' => 'https://example.comcontent',
|
||||
'body' => 'https://example.comcontent',
|
||||
'url' => 'https://example.com',
|
||||
],
|
||||
'bug-8781-labeled-link' => [
|
||||
'expected' => 'link label',
|
||||
'body' => '[url=https://example.com]link label[/url]',
|
||||
'url' => 'https://example.com',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataStripTrailingUrlFromBody
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $body
|
||||
* @param string $url
|
||||
*/
|
||||
public function testStripTrailingUrlFromBody(string $expected, string $body, string $url)
|
||||
{
|
||||
$this->assertSame($expected, PageInfoMock::stripTrailingUrlFromBody($body, $url));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue