mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Tests for removing subscriptions
This commit is contained in:
parent
98c950de58
commit
acbb254bfb
2 changed files with 33 additions and 3 deletions
|
@ -367,7 +367,6 @@ class User {
|
||||||
|
|
||||||
protected function autoProvision(string $user, string $password = null, array $properties = null, int $rights = 0): string {
|
protected function autoProvision(string $user, string $password = null, array $properties = null, int $rights = 0): string {
|
||||||
// temporarily disable authorization checks, to avoid potential problems
|
// temporarily disable authorization checks, to avoid potential problems
|
||||||
$authz = $this->authorizationEnabled();
|
|
||||||
$this->authorizationEnabled(false);
|
$this->authorizationEnabled(false);
|
||||||
// create the user
|
// create the user
|
||||||
$out = Data::$db->userAdd($user, $password);
|
$out = Data::$db->userAdd($user, $password);
|
||||||
|
@ -384,7 +383,7 @@ class User {
|
||||||
Data::$db->userPropertiesSet($user, $properties);
|
Data::$db->userPropertiesSet($user, $properties);
|
||||||
}
|
}
|
||||||
// re-enable authorization and return
|
// re-enable authorization and return
|
||||||
$this->authorizationEnabled($authz);
|
$this->authorizationEnabled(true);
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -32,6 +32,7 @@ trait SeriesSubscription {
|
||||||
],
|
],
|
||||||
'rows' => [
|
'rows' => [
|
||||||
[1,"john.doe@example.com",2,null],
|
[1,"john.doe@example.com",2,null],
|
||||||
|
[2,"jane.doe@example.com",2,null],
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
@ -103,11 +104,41 @@ trait SeriesSubscription {
|
||||||
Data::$db->subscriptionAdd($user, $url);
|
Data::$db->subscriptionAdd($user, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testAddAFeedWithoutAuthority() {
|
function testAddASubscriptionWithoutAuthority() {
|
||||||
$user = "john.doe@example.com";
|
$user = "john.doe@example.com";
|
||||||
$url = "http://example.com/feed1";
|
$url = "http://example.com/feed1";
|
||||||
Phake::when(Data::$user)->authorize->thenReturn(false);
|
Phake::when(Data::$user)->authorize->thenReturn(false);
|
||||||
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
||||||
Data::$db->subscriptionAdd($user, $url);
|
Data::$db->subscriptionAdd($user, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testRemoveASubscription() {
|
||||||
|
$user = "john.doe@example.com";
|
||||||
|
$this->assertTrue(Data::$db->subscriptionRemove($user, 1));
|
||||||
|
Phake::verify(Data::$user)->authorize($user, "subscriptionRemove");
|
||||||
|
$state = $this->primeExpectations($this->data, [
|
||||||
|
'arsse_feeds' => ['id','url','username','password'],
|
||||||
|
'arsse_subscriptions' => ['id','owner','feed'],
|
||||||
|
]);
|
||||||
|
array_shift($state['arsse_subscriptions']['rows']);
|
||||||
|
$this->compareExpectations($state);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testRemoveAMissingSubscription() {
|
||||||
|
$user = "john.doe@example.com";
|
||||||
|
$this->assertException("idMissing", "Db", "ExceptionInput");
|
||||||
|
Data::$db->subscriptionRemove($user, 2112);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testRemoveASubscriptionForTheWrongOwner() {
|
||||||
|
$user = "jane.doe@example.com";
|
||||||
|
$this->assertException("idMissing", "Db", "ExceptionInput");
|
||||||
|
Data::$db->subscriptionRemove($user, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testRemoveASubscriptionWithoutAuthority() {
|
||||||
|
Phake::when(Data::$user)->authorize->thenReturn(false);
|
||||||
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
||||||
|
Data::$db->subscriptionRemove("john.doe@example.com", 1);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue