diff --git a/public/index.php b/public/index.php index b28a5fa..d634200 100644 --- a/public/index.php +++ b/public/index.php @@ -2,12 +2,14 @@ use DanielSiepmann\FediverseFeedWrappers\RequestHandler; use DanielSiepmann\FediverseFeedWrappers\WrapperRegistry; +use DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage; use DanielSiepmann\FediverseFeedWrappers\Wrapper\GitHubTypo3; require_once __DIR__ . '/../vendor/autoload.php'; (new RequestHandler( new WrapperRegistry([ + '' => Frontpage::class, 'GitHubTypo3' => GitHubTypo3::class, ]) ))->handleRequest(); diff --git a/src/RequestHandler.php b/src/RequestHandler.php index 63e5602..84deb53 100644 --- a/src/RequestHandler.php +++ b/src/RequestHandler.php @@ -38,8 +38,8 @@ class RequestHandler */ public function handleRequest(): void { - $content = $this->wrapperRegistry->get($_GET['feed'] ?? '')->handle(); - header('content-type: application/xml;charset=utf-8'); - echo $content; + $wrapper = $this->wrapperRegistry->get($_GET['feed'] ?? ''); + header('content-type: ' . $wrapper->contentType() . ';charset=utf-8'); + echo $wrapper->content(); } } diff --git a/src/Wrapper/Frontpage.php b/src/Wrapper/Frontpage.php new file mode 100644 index 0000000..06dc3e8 --- /dev/null +++ b/src/Wrapper/Frontpage.php @@ -0,0 +1,40 @@ + + + + + Fediverse Wrapper by Daniel Siepmann + + +

Fediverse Wrapper by Daniel Siepmann

+

This is a small project that allows to wrap other sources to be used by the Fediverse.

+

I use it myself in order to mirror the wrapped feeds from my friendi.ca instance.

+

A list of the TYPO3 mirror accounts is available at: https://daniel-siepmann.de/typo3-fediverse-news-accounts.html.

+

The repository of the source code is available here: https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers.

+ + + '; + + $content = str_replace(' ', '', $content); + $content = trim($content); + + return $content . PHP_EOL; + } +} diff --git a/src/Wrapper/GitHubTypo3.php b/src/Wrapper/GitHubTypo3.php index ef2037a..9ab9571 100644 --- a/src/Wrapper/GitHubTypo3.php +++ b/src/Wrapper/GitHubTypo3.php @@ -36,13 +36,18 @@ class GitHubTypo3 implements WrapperInterface $this->url = $url; } + public function contentType(): string + { + return 'application/xml'; + } + /** * We don't want the full commit messag within each feed item. * * Instead we are only interested in first row. * Interested people can head over to the actual URL for full info. */ - public function handle(): string + public function content(): string { $content = new DOMDocument(); $content->loadXML(file_get_contents($this->url)); diff --git a/src/WrapperInterface.php b/src/WrapperInterface.php index bb2ba0a..e3818de 100644 --- a/src/WrapperInterface.php +++ b/src/WrapperInterface.php @@ -25,5 +25,6 @@ namespace DanielSiepmann\FediverseFeedWrappers; interface WrapperInterface { - public function handle(): string; + public function contentType(): string; + public function content(): string; } diff --git a/tests/Unit/Wrapper/Assertions/Frontpage.html b/tests/Unit/Wrapper/Assertions/Frontpage.html new file mode 100644 index 0000000..21275e9 --- /dev/null +++ b/tests/Unit/Wrapper/Assertions/Frontpage.html @@ -0,0 +1,14 @@ + + + + +Fediverse Wrapper by Daniel Siepmann + + +

Fediverse Wrapper by Daniel Siepmann

+

This is a small project that allows to wrap other sources to be used by the Fediverse.

+

I use it myself in order to mirror the wrapped feeds from my friendi.ca instance.

+

A list of the TYPO3 mirror accounts is available at: https://daniel-siepmann.de/typo3-fediverse-news-accounts.html.

+

The repository of the source code is available here: https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers.

+ + diff --git a/tests/Unit/Wrapper/FrontpageTest.php b/tests/Unit/Wrapper/FrontpageTest.php new file mode 100644 index 0000000..86308a6 --- /dev/null +++ b/tests/Unit/Wrapper/FrontpageTest.php @@ -0,0 +1,86 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +namespace DanielSiepmann\FediverseFeedWrappers\Tests\Unit\Wrapper; + +use DanielSiepmann\FediverseFeedWrappers\WrapperInterface; +use DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage; +use PHPUnit\Framework\TestCase; + +/** + * @covers \DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage + */ +class FrontpageTest extends TestCase +{ + /** + * @test + */ + public function canBeCreated(): void + { + $subject = new Frontpage(); + + self::assertInstanceOf( + Frontpage::class, + $subject + ); + } + + /** + * @test + */ + public function isInstanceOfWrapperInterface(): void + { + $subject = new Frontpage(); + + self::assertInstanceOf( + WrapperInterface::class, + $subject + ); + } + + /** + * @test + */ + public function returnsContentType(): void + { + $subject = new Frontpage(); + + self::assertSame( + 'text/html', + $subject->contentType() + ); + } + + /** + * @test + */ + public function returnsContent(): void + { + $subject = new Frontpage(); + + self::assertStringEqualsFile( + __DIR__ . '/Assertions/Frontpage.html', + $subject->content() + ); + } +} diff --git a/tests/Unit/Wrapper/GitHubTypo3Test.php b/tests/Unit/Wrapper/GitHubTypo3Test.php index c5bdf77..af60981 100644 --- a/tests/Unit/Wrapper/GitHubTypo3Test.php +++ b/tests/Unit/Wrapper/GitHubTypo3Test.php @@ -58,6 +58,19 @@ class GitHubTypo3Test extends TestCase ); } + /** + * @test + */ + public function returnsContentType(): void + { + $subject = new GitHubTypo3(); + + self::assertSame( + 'application/xml', + $subject->contentType() + ); + } + /** * @test */ @@ -69,7 +82,7 @@ class GitHubTypo3Test extends TestCase self::assertStringEqualsFile( __DIR__ . '/Assertions/GitHubTypo3.atom', - $subject->handle() + $subject->content() ); } }