This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/link_scan/test.php

57 lines
2 KiB
PHP
Raw Normal View History

2024-01-16 10:56:53 +00:00
<?php
declare(strict_types=1);
namespace Shimmie2;
class LinkScanTest extends ShimmiePHPUnitTestCase
{
public function testScanPostView(): void
{
global $page;
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "TeStCase");
$image_id_2 = $this->post_image("tests/favicon.png", "TeStCase");
$text = "
2024-01-16 10:56:53 +00:00
Look at http://example.com/post/view/{$image_id_1} there is an image
http://example.com/post/view/{$image_id_2} is another one
2024-01-16 12:47:32 +00:00
But there is no http://example.com/post/view/65432
2024-01-16 10:56:53 +00:00
";
2024-02-10 00:00:02 +00:00
$page = $this->get_page("post/list", ["search" => $text]);
2024-01-16 11:05:10 +00:00
2024-01-16 10:56:53 +00:00
$this->assertEquals(PageMode::REDIRECT, $page->mode);
$this->assertEquals("/test/post/list/id%3D{$image_id_1}%2C{$image_id_2}/1", $page->redirect);
}
public function testScanPostHash(): void
{
global $page;
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "TeStCase");
$image_id_2 = $this->post_image("tests/favicon.png", "TeStCase");
$text = "
2024-01-16 10:56:53 +00:00
Look at http://example.com/_images/feb01bab5698a11dd87416724c7a89e3/foobar.jpg
2024-01-16 12:47:32 +00:00
there is an image or search for e106ea2983e1b77f11e00c0c54e53805 but one that
doesn't exist is e106ea2983e1b77f11e00c0c54e50000 o.o";
2024-02-10 00:00:02 +00:00
$page = $this->get_page("post/list", ["search" => $text]);
2024-01-16 11:05:10 +00:00
2024-01-16 10:56:53 +00:00
$this->assertEquals(PageMode::REDIRECT, $page->mode);
$this->assertEquals("/test/post/list/id%3D{$image_id_1}%2C{$image_id_2}/1", $page->redirect);
}
public function testNotTriggered(): void
{
global $page;
$this->post_image("tests/pbx_screenshot.jpg", "TeStCase");
$this->post_image("tests/favicon.png", "TeStCase");
$text = "Look at feb01bab5698a11dd87416724c7a89e3/foobar.jpg";
2024-02-10 00:00:02 +00:00
$page = $this->get_page("post/list", ["search" => $text]);
$this->assertEquals(PageMode::REDIRECT, $page->mode);
$this->assertEquals("/test/post/list/at%20feb01bab5698a11dd87416724c7a89e3%2Ffoobar.jpg%20Look/1", $page->redirect);
}
2024-01-16 10:56:53 +00:00
}