/** * @group UserCapabilities */ public function testDefaultCanCommentPermissions() { $viewer = $this->mocks()->getUser(); $owner = $this->mocks()->getUser(); $group = $this->mocks()->getGroup(['owner_guid', $owner->guid]); $object = $this->mocks()->getObject(['owner_guid', $owner->guid]); $entity = $this->getMockBuilder(ElggEntity::class)->setMethods(['__get', 'getDisplayName', 'setDisplayName'])->disableOriginalConstructor()->getMock(); $entity->expects($this->any())->method('__get')->will($this->returnValueMap([['owner_guid', $owner->guid]])); $this->assertFalse($owner->canComment($owner->guid)); $this->assertTrue($object->canComment($owner->guid)); $this->assertFalse($group->canComment($owner->guid)); $this->assertNull($entity->canComment($owner->guid)); $this->assertFalse($owner->canComment($viewer->guid)); $this->assertTrue($object->canComment($viewer->guid)); $this->assertFalse($group->canComment($viewer->guid)); $this->assertNull($entity->canComment($viewer->guid)); // can pass default value $this->assertTrue($object->canComment($viewer->guid, true)); $this->assertFalse($object->canComment($viewer->guid, false)); // can't comment on comment $comment = new \ElggComment(); $comment->owner_guid = $owner->guid; $this->assertFalse($comment->canComment($owner->guid)); }
continue; } $comment = new \ElggComment(); $comment->subtype = 'comment'; $comment->owner_guid = $owner->guid; $comment->container_guid = $entity->guid; $comment->description = $faker->text(rand(25, 1000)); $comment->access_id = $entity->access_id; $comment->time_created = rand($entity->time_created, time()); $comment->__faker = true; if ($comment->save()) { $success++; elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $comment->owner_guid, 'object_guid' => $comment->guid, 'target_guid' => $entity->guid)); for ($k = 0; $k < $reply_count; $k++) { $owner = $users[array_rand($users, 1)]; if ($comment->canComment($owner->guid)) { $reply = new \ElggComment(); $reply->subtype = 'comment'; $reply->owner_guid = $owner->guid; $reply->container_guid = $comment->guid; $reply->description = $faker->text(rand(25, 1000)); $reply->access_id = $entity->access_id; $reply->time_created = rand($comment->time_created, time()); $reply->__faker = true; if ($reply->save()) { $success++; elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $reply->owner_guid, 'object_guid' => $reply->guid, 'target_guid' => $comment->guid)); } else { $error++; } }