/** * @param string $subject * @param string $message * @return JSONResponse */ public function add($subject, $message) { $timeStamp = time(); try { $announcement = $this->manager->announce($subject, $message, $this->userId, $timeStamp); } catch (\InvalidArgumentException $e) { return new JSONResponse(['error' => (string) $this->l->t('The subject is too long or empty')], Http::STATUS_BAD_REQUEST); } $this->createPublicity($announcement['id'], $announcement['author'], $timeStamp); $announcement['author_id'] = $announcement['author']; $announcement['author'] = $this->userManager->get($announcement['author_id'])->getDisplayName(); return new JSONResponse($announcement); }
public function testAnnouncement() { $subject = 'subject' . "\n<html>"; $message = 'message' . "\n<html>"; $author = 'author'; $time = time() - 10; $announcement = $this->manager->announce($subject, $message, $author, $time); $this->assertInternalType('int', $announcement['id']); $this->assertGreaterThan(0, $announcement['id']); $this->assertSame('subject <html>', $announcement['subject']); $this->assertSame('message<br /><html>', $announcement['message']); $this->assertSame('author', $announcement['author']); $this->assertSame($time, $announcement['time']); $this->assertEquals($announcement, $this->manager->getAnnouncement($announcement['id'])); $this->assertEquals($announcement, $this->manager->getAnnouncement($announcement['id'])); $this->assertEquals([$announcement], $this->manager->getAnnouncements(1)); $this->manager->delete($announcement['id']); try { $this->manager->getAnnouncement($announcement['id']); $this->fail('Failed to delete the announcement'); } catch (\InvalidArgumentException $e) { $this->assertInstanceOf('InvalidArgumentException', $e); } }