commit
0c4c7ae818
10 changed files with 270 additions and 103 deletions
|
@ -256,7 +256,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
|
|||
$link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/');
|
||||
|
||||
$this->assertNotEquals(false, $link);
|
||||
$this->assertEquals(
|
||||
$this->assertContains(
|
||||
'A free software media publishing platform',
|
||||
$link['description']
|
||||
);
|
||||
|
@ -293,6 +293,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
|
|||
// The DB contains a link with `sTuff` and another one with `stuff` tag.
|
||||
// They need to be grouped with the first case found (`sTuff`).
|
||||
'sTuff' => 2,
|
||||
'hashtag' => 2,
|
||||
),
|
||||
self::$publicLinkDB->allTags()
|
||||
);
|
||||
|
@ -315,6 +316,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
|
|||
'sTuff' => 2,
|
||||
'-exclude' => 1,
|
||||
'.hidden' => 1,
|
||||
'hashtag' => 2,
|
||||
),
|
||||
self::$privateLinkDB->allTags()
|
||||
);
|
||||
|
|
|
@ -387,4 +387,30 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
|
|||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter links by #hashtag.
|
||||
*/
|
||||
public function testFilterByHashtag()
|
||||
{
|
||||
$hashtag = 'hashtag';
|
||||
$this->assertEquals(
|
||||
3,
|
||||
count(self::$linkFilter->filter(
|
||||
LinkFilter::$FILTER_TAG,
|
||||
$hashtag
|
||||
))
|
||||
);
|
||||
|
||||
$hashtag = 'private';
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count(self::$linkFilter->filter(
|
||||
LinkFilter::$FILTER_TAG,
|
||||
$hashtag,
|
||||
false,
|
||||
true
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,4 +93,92 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
|
|||
$refDB = new ReferenceLinkDB();
|
||||
$this->assertEquals($refDB->countPrivateLinks(), count_private($refDB->getLinks()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test text2clickable without a redirector being set.
|
||||
*/
|
||||
public function testText2clickableWithoutRedirector()
|
||||
{
|
||||
$text = 'stuff http://hello.there/is=someone#here otherstuff';
|
||||
$expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff';
|
||||
$processedText = text2clickable($text, '');
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test text2clickable a redirector set.
|
||||
*/
|
||||
public function testText2clickableWithRedirector()
|
||||
{
|
||||
$text = 'stuff http://hello.there/is=someone#here otherstuff';
|
||||
$redirector = 'http://redirector.to';
|
||||
$expectedText = 'stuff <a href="'.
|
||||
$redirector .
|
||||
urlencode('http://hello.there/is=someone#here') .
|
||||
'">http://hello.there/is=someone#here</a> otherstuff';
|
||||
$processedText = text2clickable($text, $redirector);
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test testSpace2nbsp.
|
||||
*/
|
||||
public function testSpace2nbsp()
|
||||
{
|
||||
$text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?';
|
||||
$expectedText = ' Are you thrilled by flags ?'. PHP_EOL .' Really?';
|
||||
$processedText = space2nbsp($text);
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test hashtags auto-link.
|
||||
*/
|
||||
public function testHashtagAutolink()
|
||||
{
|
||||
$index = 'http://domain.tld/';
|
||||
$rawDescription = '#hashtag\n
|
||||
# nothashtag\n
|
||||
test#nothashtag #hashtag \#nothashtag\n
|
||||
test #hashtag #hashtag test #hashtag.test\n
|
||||
#hashtag #hashtag-nothashtag #hashtag_hashtag\n
|
||||
What is #ашок anyway?\n
|
||||
カタカナ #カタカナ」カタカナ\n';
|
||||
$autolinkedDescription = hashtag_autolink($rawDescription, $index);
|
||||
|
||||
$this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription);
|
||||
$this->assertNotContains(' #hashtag', $autolinkedDescription);
|
||||
$this->assertNotContains('>#nothashtag', $autolinkedDescription);
|
||||
$this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription);
|
||||
$this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription);
|
||||
$this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription);
|
||||
$this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test hashtags auto-link without index URL.
|
||||
*/
|
||||
public function testHashtagAutolinkNoIndex()
|
||||
{
|
||||
$rawDescription = 'blabla #hashtag x#nothashtag';
|
||||
$autolinkedDescription = hashtag_autolink($rawDescription);
|
||||
|
||||
$this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription);
|
||||
$this->assertNotContains(' #hashtag', $autolinkedDescription);
|
||||
$this->assertNotContains('>#nothashtag', $autolinkedDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Util function to build an hashtag link.
|
||||
*
|
||||
* @param string $hashtag Hashtag name.
|
||||
* @param string $index Index URL.
|
||||
*
|
||||
* @return string HTML hashtag link.
|
||||
*/
|
||||
private function getHashtagLink($hashtag, $index = '')
|
||||
{
|
||||
$hashtagLink = '<a href="'. $index .'?addtag=$1" title="Hashtag $1">#$1</a>';
|
||||
return str_replace('$1', $hashtag, $hashtagLink);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,41 +253,4 @@ class UtilsTest extends PHPUnit_Framework_TestCase
|
|||
is_session_id_valid('c0ZqcWF3VFE2NmJBdm1HMVQ0ZHJ3UmZPbTFsNGhkNHI=')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test text2clickable without a redirector being set.
|
||||
*/
|
||||
public function testText2clickableWithoutRedirector()
|
||||
{
|
||||
$text = 'stuff http://hello.there/is=someone#here otherstuff';
|
||||
$expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff';
|
||||
$processedText = text2clickable($text, '');
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test text2clickable a redirector set.
|
||||
*/
|
||||
public function testText2clickableWithRedirector()
|
||||
{
|
||||
$text = 'stuff http://hello.there/is=someone#here otherstuff';
|
||||
$redirector = 'http://redirector.to';
|
||||
$expectedText = 'stuff <a href="'.
|
||||
$redirector .
|
||||
urlencode('http://hello.there/is=someone#here') .
|
||||
'">http://hello.there/is=someone#here</a> otherstuff';
|
||||
$processedText = text2clickable($text, $redirector);
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test testSpace2nbsp.
|
||||
*/
|
||||
public function testSpace2nbsp()
|
||||
{
|
||||
$text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?';
|
||||
$expectedText = ' Are you thrilled by flags ?'. PHP_EOL .' Really?';
|
||||
$processedText = space2nbsp($text);
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class ReferenceLinkDB
|
|||
$this->addLink(
|
||||
'Link title: @website',
|
||||
'?WDWyig',
|
||||
'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this.',
|
||||
'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag',
|
||||
0,
|
||||
'20150310_114651',
|
||||
'sTuff'
|
||||
|
@ -27,25 +27,25 @@ class ReferenceLinkDB
|
|||
$this->addLink(
|
||||
'Free as in Freedom 2.0 @website',
|
||||
'https://static.fsf.org/nosvn/faif-2.0.pdf',
|
||||
'Richard Stallman and the Free Software Revolution. Read this.',
|
||||
'Richard Stallman and the Free Software Revolution. Read this. #hashtag',
|
||||
0,
|
||||
'20150310_114633',
|
||||
'free gnu software stallman -exclude stuff'
|
||||
'free gnu software stallman -exclude stuff hashtag'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
'MediaGoblin',
|
||||
'http://mediagoblin.org/',
|
||||
'A free software media publishing platform',
|
||||
'A free software media publishing platform #hashtagOther',
|
||||
0,
|
||||
'20130614_184135',
|
||||
'gnu media web .hidden'
|
||||
'gnu media web .hidden hashtag'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
'w3c-markup-validator',
|
||||
'https://dvcs.w3.org/hg/markup-validator/summary',
|
||||
'Mercurial repository for the W3C Validator',
|
||||
'Mercurial repository for the W3C Validator #private',
|
||||
1,
|
||||
'20141125_084734',
|
||||
'css html w3c web Mercurial'
|
||||
|
@ -54,7 +54,7 @@ class ReferenceLinkDB
|
|||
$this->addLink(
|
||||
'UserFriendly - Web Designer',
|
||||
'http://ars.userfriendly.org/cartoons/?id=20121206',
|
||||
'Naming conventions...',
|
||||
'Naming conventions... #private',
|
||||
0,
|
||||
'20121206_142300',
|
||||
'dev cartoon web'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue