@@ -2,10 +2,11 @@
use \Podlove\Modules\SlackShownotes\Message ;
class SlackMessageTest extends WP_UnitTestCase {
public function testExtractLinkMatchedWithAttachment ()
{
$data = <<< EOT
class SlackMessageTest extends WP_UnitTestCase
{
public function testExtractLinkMatchedWithAttachment ()
{
$data = <<< EOT
{
"client_msg_id": "a651c38b-2bc3-4ce3-8a48-2b131af24887",
"type": "message",
@@ -31,18 +32,18 @@ public function testExtractLinkMatchedWithAttachment()
}
EOT ;
$message = json_decode ($data , true );
$result = Message :: extract_links($message );
$message = json_decode ($data , true );
$result = Message :: extract_links($message );
$this -> assertEquals(count ($result ), 1 );
$this -> assertEquals($result [0 ][' link' ], " https://freakshow.fm/fs228-letty-im-datenteich" );
$this -> assertEquals($result [0 ][' title' ], " FS228 Letty im Datenteich" );
$this -> assertEquals($result [0 ][' source' ], " Freak Show" );
}
$this -> assertEquals(count ($result ), 1 );
$this -> assertEquals($result [0 ][' link' ], " https://freakshow.fm/fs228-letty-im-datenteich" );
$this -> assertEquals($result [0 ][' title' ], " FS228 Letty im Datenteich" );
$this -> assertEquals($result [0 ][' source' ], " Freak Show" );
}
public function testLinkWithMissingAttachment ()
{
$data = <<< EOT
public function testLinkWithMissingAttachment ()
{
$data = <<< EOT
{
"client_msg_id": "5510681d-1c33-41aa-a0ee-62779cd9e8ad",
"type": "message",
@@ -52,18 +53,41 @@ public function testLinkWithMissingAttachment()
}
EOT ;
$message = json_decode ($data , true );
$result = Message :: extract_links($message );
$message = json_decode ($data , true );
$result = Message :: extract_links($message );
$this -> assertEquals(count ($result ), 1 );
$this -> assertEquals($result [0 ][' link' ], " http://www.spiegel.de/politik/ausland/kongos-regierung-kappt-das-internet-nach-praesidentenwahl-a-1245955.html" );
$this -> assertEquals($result [0 ][' title' ], null );
$this -> assertEquals($result [0 ][' source' ], ' spiegel.de' );
}
public function testLinkWithPipes ()
{
// when Slack detects something that looks like an URL it makes a canonical version
// for example: golem.de is expanded to <https://golem.de|golem.de>
$data = <<< EOT
{
"client_msg_id": "5510681d-1c33-41aa-a0ee-62779cd9e8ad",
"type": "message",
"text": "Link mit pipe <https://golem.de|golem.de>",
"user": "UF53JT12T",
"ts": "1546266336.001000"
}
EOT ;
$message = json_decode ($data , true );
$result = Message :: extract_links($message );
$this -> assertEquals(count ($result ), 1 );
$this -> assertEquals($result [0 ][' link' ], " http ://www.spiegel.de/politik/ausland/kongos-regierung-kappt-das-internet-nach-praesidentenwahl-a-1245955.html " );
$this -> assertEquals($result [0 ][' title' ], NULL );
$this -> assertEquals($result [0 ][' source' ], ' spiegel .de' );
}
$this -> assertEquals(count ($result ), 1 );
$this -> assertEquals($result [0 ][' link' ], " https ://golem.de " );
$this -> assertEquals($result [0 ][' title' ], null );
$this -> assertEquals($result [0 ][' source' ], ' golem .de' );
}
public function testMultipleLinksWithAttachments ()
{
$data = <<< EOT
public function testMultipleLinksWithAttachments ()
{
$data = <<< EOT
{
"client_msg_id": "7b5c8c33-be8f-4974-84ea-14ccbc4bc4aa",
"type": "message",
@@ -103,13 +127,13 @@ public function testMultipleLinksWithAttachments()
}
EOT ;
$message = json_decode ($data , true );
$result = Message :: extract_links($message );
$message = json_decode ($data , true );
$result = Message :: extract_links($message );
$this -> assertEquals(count ($result ), 2 );
$this -> assertEquals($result [0 ][' link' ], " https://www.zeit.de/gesellschaft/zeitgeschehen/2018-12/vatikan-papst-franziskus-sprecher-ruecktritt" );
$this -> assertEquals($result [0 ][' title' ], " Vatikan: Sprecher von Papst Franziskus treten zurück" );
$this -> assertEquals($result [1 ][' link' ], " https://www.zeit.de/2019/01/demokratieverdrossenheit-misstrauen-aufschwung-buerger-generationenkonflikt" );
$this -> assertEquals($result [1 ][' title' ], " Demokratieverdrossenheit: Warum trauen so viele der Demokratie nicht, obwohl wir einen Aufschwung erleben?" );
}
$this -> assertEquals(count ($result ), 2 );
$this -> assertEquals($result [0 ][' link' ], " https://www.zeit.de/gesellschaft/zeitgeschehen/2018-12/vatikan-papst-franziskus-sprecher-ruecktritt" );
$this -> assertEquals($result [0 ][' title' ], " Vatikan: Sprecher von Papst Franziskus treten zurück" );
$this -> assertEquals($result [1 ][' link' ], " https://www.zeit.de/2019/01/demokratieverdrossenheit-misstrauen-aufschwung-buerger-generationenkonflikt" );
$this -> assertEquals($result [1 ][' title' ], " Demokratieverdrossenheit: Warum trauen so viele der Demokratie nicht, obwohl wir einen Aufschwung erleben?" );
}
}
0 comments on commit
b08ec53