commit(); $this->article1Id = $article1->getId(); $this->article2Id = $article2->getId(); $this->article3Id = $article3->getId(); } function testGetDoArticles() { $response = TestEnv::http()->newRequest() ->get(['api', 'articles']) ->exec(); $articleStructs = $response->parseJson(); $this->assertCount(3, $articleStructs); $this->assertEquals('Title 3', $articleStructs[0]['title']); $this->assertEquals('Title 2', $articleStructs[1]['title']); $this->assertEquals('Title 1', $articleStructs[2]['title']); } function testGetDoArticlesByCategoryName() { $response = TestEnv::http()->newRequest() ->get(['api', 'articles', 'sport']) ->exec(); $articleStructs = $response->parseJson(); $this->assertCount(1, $articleStructs); $this->assertEquals('Title 1', $articleStructs[0]['title']); $response = TestEnv::http()->newRequest() ->get(['api', 'articles', 'national']) ->exec(); $articleStructs = $response->parseJson(); $this->assertCount(2, $articleStructs); $this->assertEquals('Title 3', $articleStructs[0]['title']); $this->assertEquals('Title 2', $articleStructs[1]['title']); } function testGetDoArticle() { $response = TestEnv::http()->newRequest() ->get(['api', 'article', '1']) ->exec(); $articleStructs = $response->parseJson(); $this->assertCount(4, $articleStructs); $this->assertEquals('Title 1', $articleStructs['title']); $this->assertEquals('Loren ipsum 1', $articleStructs['text']); $this->assertEquals('sport', $articleStructs['categoryName']); $this->assertEquals('1', $articleStructs['id']); } function testGetDoArticlePageNotFound() { $this->expectException(PageNotFoundException::class); TestEnv::http()->newRequest() ->get(['api', 'article', '4']) ->exec(); } function testPostDoNewArticleBadCategory() { $this->expectException(BadRequestException::class); TestEnv::http()->newRequest() ->post(['api', 'newarticle']) ->bodyJson(['title' => 'Title 5', 'categoryName' => 'news', 'text' => 'Loren ipsum 5']) ->exec(); } function testPostDoNewArticle() { $response = TestEnv::http()->newRequest() ->post(['api', 'newarticle']) ->bodyJson(['title' => 'Title 4', 'categoryName' => 'international', 'text' => 'Loren ipsum 4']) ->exec(); $articleStruct = $response->parseJson(); $article = TestEnv::em()->find(Article::getClass(), $articleStruct['id']); $this->assertEquals('Title 4', $article->getTitle()); $this->assertEquals('Loren ipsum 4', $article->getText()); $this->assertEquals('international', $article->getCategoryName()); $this->assertEquals($articleStruct['id'], $article->getId()); $response = TestEnv::http()->newRequest() ->get(['api', 'articles']) ->exec(); $articleStructs = $response->parseJson(); $this->assertCount(4, $articleStructs); } function testPutDoArticle() { TestEnv::http()->newRequest() ->put(['api', 'article', '1']) ->bodyJson(['title' => 'Title 4', 'categoryName' => 'international', 'text' => 'Loren ipsum 4']) ->exec(); $response = TestEnv::http()->newRequest() ->get(['api', 'article', '1']) ->exec(); $articleStructs = $response->parseJson(); $this->assertCount(4, $articleStructs); $this->assertEquals('Title 4', $articleStructs['title']); $this->assertEquals('Loren ipsum 4', $articleStructs['text']); $this->assertEquals('international', $articleStructs['categoryName']); $this->assertEquals('1', $articleStructs['id']); } function testDeleteDoArticle() { TestEnv::http()->newRequest() ->delete(['api', 'article', '1']) ->exec(); $response = TestEnv::http()->newRequest() ->get(['api', 'articles']) ->exec(); $articleStructs = $response->parseJson(); $this->assertCount(2, $articleStructs); $this->expectException(PageNotFoundException::class); TestEnv::http()->newRequest() ->get(['api', 'article', '1']) ->exec(); } }