[ENTITY][TESTS] Fix Note->isVisibleTo with and associated test
This commit is contained in:
parent
eb3c848fc8
commit
cf05d3dbb0
|
@ -98,8 +98,8 @@ class CoreFixtures extends Fixture
|
||||||
}
|
}
|
||||||
|
|
||||||
$group_notes = [];
|
$group_notes = [];
|
||||||
$group_notes[] = $public_group_note = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'group note', 'scope' => VisibilityScope::GROUP, 'content_type' => 'text/plain', 'is_local' => true]);
|
$group_notes[] = $public_group_note = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'group note public', 'scope' => VisibilityScope::EVERYWHERE, 'content_type' => 'text/plain', 'is_local' => true]);
|
||||||
$group_notes[] = $private_group_note = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'group note', 'scope' => VisibilityScope::GROUP, 'content_type' => 'text/plain', 'is_local' => true]);
|
$group_notes[] = $private_group_note = Note::create(['actor_id' => $actors['taken_user']->getId(), 'content' => 'group note private', 'scope' => VisibilityScope::GROUP, 'content_type' => 'text/plain', 'is_local' => true]);
|
||||||
foreach ($group_notes as $note) {
|
foreach ($group_notes as $note) {
|
||||||
$manager->persist($note);
|
$manager->persist($note);
|
||||||
$activity = Activity::create(['actor_id' => $actors['taken_user']->getId(), 'verb' => 'create', 'object_type' => 'note', 'object_id' => $note->getId(), 'source' => 'auto-test']);
|
$activity = Activity::create(['actor_id' => $actors['taken_user']->getId(), 'verb' => 'create', 'object_type' => 'note', 'object_id' => $note->getId(), 'source' => 'auto-test']);
|
||||||
|
|
|
@ -32,6 +32,7 @@ use App\Core\Log;
|
||||||
use App\Core\Router\Router;
|
use App\Core\Router\Router;
|
||||||
use App\Core\VisibilityScope;
|
use App\Core\VisibilityScope;
|
||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
|
use App\Util\Exception\BugFoundException;
|
||||||
use App\Util\Exception\ClientException;
|
use App\Util\Exception\ClientException;
|
||||||
use App\Util\Exception\NoSuchNoteException;
|
use App\Util\Exception\NoSuchNoteException;
|
||||||
use App\Util\Formatting;
|
use App\Util\Formatting;
|
||||||
|
@ -468,19 +469,18 @@ class Note extends Entity
|
||||||
// Either is a Public Group OR
|
// Either is a Public Group OR
|
||||||
!($in->getRoles() & ActorLocalRoles::PRIVATE_GROUP)
|
!($in->getRoles() & ActorLocalRoles::PRIVATE_GROUP)
|
||||||
// Both the actor and the note are elements that concern the group
|
// Both the actor and the note are elements that concern the group
|
||||||
|| DB::dql( // TODO: Fix this query, @see NoteTest.php
|
|| DB::dql(
|
||||||
<<<'EOF'
|
<<<'EOF'
|
||||||
SELECT m FROM \Component\Group\Entity\GroupMember m
|
SELECT m FROM \Component\Group\Entity\GroupMember m
|
||||||
JOIN \Component\Notification\Entity\Notification att WITH m.group_id = att.target_id
|
JOIN \Component\Notification\Entity\Notification att WITH m.group_id = att.target_id
|
||||||
JOIN \App\Entity\Activity a WITH att.activity_id = a.id
|
JOIN \App\Entity\Activity a WITH att.activity_id = a.id
|
||||||
WHERE a.object_type = 'note' AND a.object_id = :note_id AND m.actor_id = :actor_id
|
WHERE a.object_type = 'note' AND a.object_id = :note_id AND m.group_id = :group_id AND m.actor_id = :actor_id
|
||||||
EOF,
|
EOF,
|
||||||
['note_id' => $this->id, 'actor_id' => $in->getId()]
|
['note_id' => $this->getId(), 'group_id' => $in->getId(), 'actor_id' => $actor->getId()]
|
||||||
) !== []
|
) !== []
|
||||||
);
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Log::error("Unknown scope found: {$this->getScope()->value}.");
|
throw new BugFoundException("Unknown scope found: {$this->getScope()->value}");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,29 +50,25 @@ class NoteTest extends GNUsocialTestCase
|
||||||
|
|
||||||
public function testIsVisibleTo()
|
public function testIsVisibleTo()
|
||||||
{
|
{
|
||||||
$actor1 = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']);
|
static::bootKernel();
|
||||||
|
$actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']);
|
||||||
$private_group = DB::findOneBy(Actor::class, ['nickname' => 'taken_private_group']);
|
$private_group = DB::findOneBy(Actor::class, ['nickname' => 'taken_private_group']);
|
||||||
$private_group_member = DB::findOneBy(Actor::class, ['nickname' => 'some_user']);
|
$private_group_member = DB::findOneBy(Actor::class, ['nickname' => 'some_user']);
|
||||||
$public_group = DB::findOneBy(Actor::class, ['nickname' => 'taken_public_group']);
|
$public_group = DB::findOneBy(Actor::class, ['nickname' => 'taken_public_group']);
|
||||||
$actor2 = DB::findOneBy(Actor::class, ['nickname' => 'some_user']);
|
|
||||||
|
|
||||||
$note_visible_to_1 = DB::findBy(Note::class, ['actor_id' => $actor1->getId(), 'content' => 'private note', 'scope' => VisibilityScope::MESSAGE->value], limit: 1)[0];
|
$note_visible_to_1 = DB::findBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'private note', 'scope' => VisibilityScope::MESSAGE->value], limit: 1)[0];
|
||||||
static::assertTrue($note_visible_to_1->isVisibleTo($actor1));
|
static::assertTrue($note_visible_to_1->isVisibleTo($actor));
|
||||||
static::assertFalse($note_visible_to_1->isVisibleTo($actor2));
|
|
||||||
static::assertFalse($note_visible_to_1->isVisibleTo($private_group));
|
static::assertFalse($note_visible_to_1->isVisibleTo($private_group));
|
||||||
static::assertFalse($note_visible_to_1->isVisibleTo($private_group_member));
|
static::assertFalse($note_visible_to_1->isVisibleTo($private_group_member));
|
||||||
|
|
||||||
$note_public = DB::findBy(Note::class, ['actor_id' => $actor1->getId(), 'content' => 'some other content'], limit: 1)[0];
|
$note_public = DB::findBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'some other content'], limit: 1)[0];
|
||||||
static::assertTrue($note_public->isVisibleTo($actor1));
|
static::assertTrue($note_public->isVisibleTo($actor));
|
||||||
static::assertTrue($note_public->isVisibleTo($actor2));
|
|
||||||
static::assertTrue($note_public->isVisibleTo($private_group));
|
static::assertTrue($note_public->isVisibleTo($private_group));
|
||||||
static::assertTrue($note_public->isVisibleTo($private_group_member));
|
static::assertTrue($note_public->isVisibleTo($private_group_member));
|
||||||
|
|
||||||
$group_note = DB::findBy(Note::class, ['actor_id' => $actor1->getId(), 'content' => 'group note', 'scope' => VisibilityScope::GROUP->value], limit: 1)[0];
|
$group_note = DB::findBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'group note private', 'scope' => VisibilityScope::GROUP->value], limit: 1)[0];
|
||||||
// TODO: Fix group query, @see Note->isVisibleTo
|
static::assertTrue($group_note->isVisibleTo($private_group_member, in: $private_group));
|
||||||
//static::assertTrue($group_note->isVisibleTo($private_group_member, in: $private_group));
|
static::assertFalse($group_note->isVisibleTo($actor, in: $private_group));
|
||||||
static::assertFalse($group_note->isVisibleTo($actor1, in: $private_group));
|
|
||||||
static::assertFalse($group_note->isVisibleTo($private_group, in: $private_group));
|
static::assertFalse($group_note->isVisibleTo($private_group, in: $private_group));
|
||||||
static::assertFalse($group_note->isVisibleTo($actor2, in: $private_group));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user