Moved API\Notification tests

This commit is contained in:
Philipp 2021-11-12 21:35:21 +01:00
parent f2ca21935e
commit 6725f05ab2
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
8 changed files with 161 additions and 86 deletions

View file

@ -7,8 +7,10 @@ use Friendica\Core\Addon;
use Friendica\Core\Hook;
use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Module\Api\ApiResponse;
use Friendica\Security\Authentication;
use Friendica\Test\FixtureTest;
use Friendica\Test\Util\ApiResponseDouble;
use Friendica\Test\Util\AuthenticationDouble;
class ApiTest extends FixtureTest
@ -18,12 +20,20 @@ class ApiTest extends FixtureTest
parent::setUp(); // TODO: Change the autogenerated stub
$this->dice = $this->dice
->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true]);
->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true])
->addRule(ApiResponse::class, ['instanceOf' => ApiResponseDouble::class, 'shared' => true]);
DI::init($this->dice);
$this->installAuthTest();
}
protected function tearDown(): void
{
ApiResponseDouble::reset();
parent::tearDown();
}
/**
* installs auththest.
*

View file

@ -0,0 +1,60 @@
<?php
namespace Friendica\Test\src\Module\Api\Friendica;
use Friendica\DI;
use Friendica\Module\Api\Friendica\Notification;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest;
use Friendica\Test\Util\ApiResponseDouble;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
class NotificationTest extends ApiTest
{
public function testEmpty()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
$this->expectException(BadRequestException::class);
DI::session()->set('uid', '');
Notification::rawContent();
}
public function testWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
$this->expectException(BadRequestException::class);
DI::session()->set('uid', 41);
Notification::rawContent();
}
public function testWithXmlResult()
{
$date = DateTimeFormat::local('2020-01-01 12:12:02');
$dateRel = Temporal::getRelativeDate('2020-01-01 07:12:02');
$assertXml = <<<XML
<?xml version="1.0"?>
<notes>
<note date="$date" date_rel="$dateRel" id="1" iid="4" link="http://localhost/notification/1" msg="A test reply from an item" msg_cache="A test reply from an item" msg_html="A test reply from an item" msg_plain="A test reply from an item" name="Reply to" name_cache="Reply to" otype="item" parent="" photo="http://localhost/" seen="false" timestamp="1577880722" type="8" uid="42" url="http://localhost/display/1" verb="http://activitystrea.ms/schema/1.0/post"/>
</notes>
XML;
Notification::rawContent(['extension' => 'xml']);
self::assertXmlStringEqualsXmlString($assertXml, ApiResponseDouble::getOutput());
}
public function testWithJsonResult()
{
Notification::rawContent(['parameter' => 'json']);
$result = json_encode(ApiResponseDouble::getOutput());
self::assertJson($result);
}
}

View file

@ -10,7 +10,7 @@ class DeleteTest extends ApiTest
{
public function testEmpty()
{
self::expectException(BadRequestException::class);
$this->expectException(BadRequestException::class);
Delete::rawContent();
}
@ -21,7 +21,7 @@ class DeleteTest extends ApiTest
public function testWrong()
{
self::expectException(BadRequestException::class);
$this->expectException(BadRequestException::class);
Delete::rawContent(['photo_id' => 1]);
}

View file

@ -10,13 +10,13 @@ class DeleteTest extends ApiTest
{
public function testEmpty()
{
self::expectException(BadRequestException::class);
$this->expectException(BadRequestException::class);
Delete::rawContent();
}
public function testWrong()
{
self::expectException(BadRequestException::class);
$this->expectException(BadRequestException::class);
Delete::rawContent(['album' => 'album_name']);
}

View file

@ -10,19 +10,19 @@ class UpdateTest extends ApiTest
{
public function testEmpty()
{
self::expectException(BadRequestException::class);
$this->expectException(BadRequestException::class);
Update::rawContent();
}
public function testTooFewArgs()
{
self::expectException(BadRequestException::class);
$this->expectException(BadRequestException::class);
Update::rawContent(['album' => 'album_name']);
}
public function testWrongUpdate()
{
self::expectException(BadRequestException::class);
$this->expectException(BadRequestException::class);
Update::rawContent(['album' => 'album_name', 'album_new' => 'album_name']);
}