userManager = $this->createMock(IUserManager::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->url = $this->createMock(IURLGenerator::class); $this->provider = $this->getMockBuilder(Base::class) ->setConstructorArgs([ $this->userManager, $this->groupManager, $this->url, ]) ->onlyMethods(['parse']) ->getMock(); } public static function dataSetSubjects(): array { return [ ['abc', []], ['{actor} created {calendar}', ['actor' => ['name' => 'abc'], 'calendar' => ['name' => 'xyz']]], ]; } #[\PHPUnit\Framework\Attributes\DataProvider('dataSetSubjects')] public function testSetSubjects(string $subject, array $parameters): void { $event = $this->createMock(IEvent::class); $event->expects($this->once()) ->method('setRichSubject') ->with($subject, $parameters) ->willReturnSelf(); $event->expects($this->never()) ->method('setParsedSubject'); $this->invokePrivate($this->provider, 'setSubjects', [$event, $subject, $parameters]); } public static function dataGenerateCalendarParameter(): array { return [ [['id' => 23, 'uri' => 'foo', 'name' => 'bar'], 'bar'], [['id' => 42, 'uri' => 'foo', 'name' => 'Personal'], 'Personal'], [['id' => 42, 'uri' => 'personal', 'name' => 'bar'], 'bar'], [['id' => 42, 'uri' => 'personal', 'name' => 'Personal'], 't(Personal)'], ]; } #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateCalendarParameter')] public function testGenerateCalendarParameter(array $data, string $name): void { $l = $this->createMock(IL10N::class); $l->expects($this->any()) ->method('t') ->willReturnCallback(function ($string, $args) { return 't(' . vsprintf($string, $args) . ')'; }); $this->assertEquals([ 'type' => 'calendar', 'id' => $data['id'], 'name' => $name, ], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$data, $l])); } public static function dataGenerateLegacyCalendarParameter(): array { return [ [23, 'c1'], [42, 'c2'], ]; } #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateLegacyCalendarParameter')] public function testGenerateLegacyCalendarParameter(int $id, string $name): void { $this->assertEquals([ 'type' => 'calendar', 'id' => $id, 'name' => $name, ], $this->invokePrivate($this->provider, 'generateLegacyCalendarParameter', [$id, $name])); } public static function dataGenerateGroupParameter(): array { return [ ['g1'], ['g2'], ]; } #[\PHPUnit\Framework\Attributes\DataProvider('dataGenerateGroupParameter')] public function testGenerateGroupParameter(string $gid): void { $this->assertEquals([ 'type' => 'user-group', 'id' => $gid, 'name' => $gid, ], $this->invokePrivate($this->provider, 'generateGroupParameter', [$gid])); } }