ArticleControllerTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace internship\controller;
  3. use PHPUnit\Framework\TestCase;
  4. use n2n\test\TestEnv;
  5. use internship\test\ArticleTestEnv;
  6. use util\GeneralTestEnv;
  7. use n2n\web\http\StatusException;
  8. class ArticleControllerTest extends TestCase {
  9. private int $article1Id;
  10. private int $article2Id;
  11. private int $article3Id;
  12. function setUp(): void {
  13. GeneralTestEnv::tearDown();
  14. $tx = TestEnv::createTransaction();
  15. $article1 = ArticleTestEnv::setUpArticle('Title 1', 'Loren ipsum 1', 'teaser');
  16. $article2 = ArticleTestEnv::setUpArticle('Title 2', 'Loren ipsum 2', 'news');
  17. $article3 = ArticleTestEnv::setUpArticle('Title 3', 'Loren ipsum 3', 'news');
  18. $tx->commit();
  19. $this->article1Id = $article1->getId();
  20. $this->article2Id = $article2->getId();
  21. $this->article3Id = $article3->getId();
  22. }
  23. /**
  24. * @throws StatusException
  25. */
  26. function testGetDoArticles() {
  27. $response = TestEnv::http()->newRequest()
  28. ->get(['api', 'articles'])
  29. ->exec();
  30. $articleStructs = $response->parseJson();
  31. $this->assertCount(3, $articleStructs);
  32. $this->assertEquals('Title 3', $articleStructs[0]['title']);
  33. $this->assertEquals('Title 2', $articleStructs[1]['title']);
  34. $this->assertEquals('Title 1', $articleStructs[2]['title']);
  35. }
  36. }