From aafa1de4d56b0791c4d367aa530587082c833faf Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 17 Dec 2016 12:11:17 -0500 Subject: Handle username with dots in user mentions --- tests/units/Helper/TextHelperTest.php | 93 +++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 27 deletions(-) (limited to 'tests/units/Helper/TextHelperTest.php') diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index a54c5780..5c8a10f6 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -5,12 +5,13 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\TextHelper; use Kanboard\Model\ProjectModel; use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\UserModel; class TextHelperTest extends Base { public function testMarkdownTaskLink() { - $helper = new TextHelper($this->container); + $textHelper = new TextHelper($this->container); $projectModel = new ProjectModel($this->container); $taskCreationModel = new TaskCreationModel($this->container); @@ -19,26 +20,26 @@ class TextHelperTest extends Base $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1))); $project = $projectModel->getById(1); - $this->assertEquals('

Test

', $helper->markdown('Test')); + $this->assertEquals('

Test

', $textHelper->markdown('Test')); $this->assertEquals( '

Task #123

', - $helper->markdown('Task #123') + $textHelper->markdown('Task #123') ); $this->assertEquals( '

Task #123

', - $helper->markdown('Task #123', true) + $textHelper->markdown('Task #123', true) ); $this->assertEquals( '

Task #1

', - $helper->markdown('Task #1', true) + $textHelper->markdown('Task #1', true) ); $this->assertEquals( '

Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

', - $helper->markdown( + $textHelper->markdown( 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454' ) ); @@ -46,44 +47,82 @@ class TextHelperTest extends Base public function testMarkdownUserLink() { - $h = new TextHelper($this->container); - $this->assertEquals('

Text @admin @notfound

', $h->markdown('Text @admin @notfound')); - $this->assertEquals('

Text @admin,

', $h->markdown('Text @admin,')); - $this->assertEquals('

Text @admin!

', $h->markdown('Text @admin!')); - $this->assertEquals('

Text @admin?

', $h->markdown('Text @admin? ')); - $this->assertEquals('

Text @admin.

', $h->markdown('Text @admin.')); - $this->assertEquals('

Text @admin: test

', $h->markdown('Text @admin: test')); - $this->assertEquals('

Text @admin @notfound

', $h->markdown('Text @admin @notfound', true)); + $textHelper = new TextHelper($this->container); + $userModel = new UserModel($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'firstname.lastname', 'name' => 'Firstname Lastname'))); + + $this->assertEquals( + '

Text @admin @notfound

', + $textHelper->markdown('Text @admin @notfound') + ); + + $this->assertEquals( + '

Text @admin,

', + $textHelper->markdown('Text @admin,') + ); + + $this->assertEquals( + '

Text @admin!

', + $textHelper->markdown('Text @admin!') + ); + + $this->assertEquals( + '

Text @admin?

', + $textHelper->markdown('Text @admin? ') + ); + + $this->assertEquals( + '

Text @admin.

', + $textHelper->markdown('Text @admin.') + ); + + $this->assertEquals( + '

Text @admin: test

', + $textHelper->markdown('Text @admin: test') + ); + + $this->assertEquals( + '

Text @admin: test

', + $textHelper->markdown('Text @admin: test') + ); + + $this->assertEquals( + '

Text @firstname.lastname. test

', + $textHelper->markdown('Text @firstname.lastname. test') + ); + + $this->assertEquals('

Text @admin @notfound

', $textHelper->markdown('Text @admin @notfound', true)); } public function testMarkdownAttribute() { - $helper = new TextHelper($this->container); - $this->assertEquals('<p>Ça marche</p>', $helper->markdownAttribute('Ça marche')); - $this->assertEquals('<p>Test with &quot;double quotes&quot;</p>', $helper->markdownAttribute('Test with "double quotes"')); - $this->assertEquals('<p>Test with 'single quotes'</p>', $helper->markdownAttribute("Test with 'single quotes'")); + $textHelper = new TextHelper($this->container); + $this->assertEquals('<p>Ça marche</p>', $textHelper->markdownAttribute('Ça marche')); + $this->assertEquals('<p>Test with &quot;double quotes&quot;</p>', $textHelper->markdownAttribute('Test with "double quotes"')); + $this->assertEquals('<p>Test with 'single quotes'</p>', $textHelper->markdownAttribute("Test with 'single quotes'")); } public function testFormatBytes() { - $h = new TextHelper($this->container); + $textHelper = new TextHelper($this->container); - $this->assertEquals('1k', $h->bytes(1024)); - $this->assertEquals('33.71k', $h->bytes(34520)); + $this->assertEquals('1k', $textHelper->bytes(1024)); + $this->assertEquals('33.71k', $textHelper->bytes(34520)); } public function testContains() { - $h = new TextHelper($this->container); + $textHelper = new TextHelper($this->container); - $this->assertTrue($h->contains('abc', 'b')); - $this->assertFalse($h->contains('abc', 'd')); + $this->assertTrue($textHelper->contains('abc', 'b')); + $this->assertFalse($textHelper->contains('abc', 'd')); } public function testInList() { - $h = new TextHelper($this->container); - $this->assertEquals('?', $h->in('a', array('b' => 'c'))); - $this->assertEquals('c', $h->in('b', array('b' => 'c'))); + $textHelper = new TextHelper($this->container); + $this->assertEquals('?', $textHelper->in('a', array('b' => 'c'))); + $this->assertEquals('c', $textHelper->in('b', array('b' => 'c'))); } } -- cgit v1.2.3