commit(); $this->article1Id = $article1->getId(); $this->article2Id = $article2->getId(); $this->article3Id = $article3->getId(); } /** * @throws StatusException */ function testGetDoArticlesBy() { $response = TestEnv::http()->newRequest() ->get(['api', 'articles']) ->exec(); $articleStruct = $response->parseJson(); $this->assertCount(3, $articleStruct); $this->assertEquals('Title 3', $articleStruct[0]['title']); $this->assertEquals('Title 2', $articleStruct[1]['title']); $this->assertEquals('Title 1', $articleStruct[2]['title']); } function testGetDoArticlesWithCategory() { $response = TestEnv::http()->newRequest() ->get(['api', 'articles', 'teaser']) ->exec(); $articleStruct = $response->parseJson(); $this->assertCount(1, $articleStruct); $this->assertEquals('Title 2', $articleStruct[0]['title']); } function testGetDoArticlesWithCategory2() { $response = TestEnv::http()->newRequest() ->get(['api', 'articles', 'news']) ->exec(); $articleStruct = $response->parseJson(); $this->assertCount(2, $articleStruct); $this->assertEquals('Title 3', $articleStruct[0]['title']); $this->assertEquals('Title 1', $articleStruct[1]['title']); } function testGetDoArticlesExpectExceptionBecauseCategoryNotFound() { $this->expectException(PageNotFoundException::class); $this->expectExceptionMessage('Category abc not found'); TestEnv::http()->newRequest() ->get(['api', 'articles', 'abc']) ->exec(); } function testGetDoArticle() { $response = TestEnv::http()->newRequest() ->get(['api', 'article', $this->article1Id]) ->exec(); $articleStruct = $response->parseJson(); $this->assertCount(4, $articleStruct); $this->assertEquals('Title 1', $articleStruct['title']); $this->assertEquals('Loren ipsum 1', $articleStruct['text']); $this->assertEquals('news', $articleStruct['categoryName']); } function testGetDoArticleExpectExceptionBecauseArticleNotFound() { $this->expectException(PageNotFoundException::class); $this->expectExceptionMessage('Article not found with ID:25436857'); TestEnv::http()->newRequest() ->get(['api', 'article', 25436857]) ->exec(); } function testPostDoArticle() { $response = TestEnv::http()->newRequest() ->post(['api', 'article']) ->bodyJson([ 'title' => 'title1', 'categoryName' => 'sport', 'text' => 'text1' ]) ->exec(); $articleStruct = $response->parseJson(); $this->assertEquals(4,TestEnv::emUtil()->count(Article::class)); $this->assertCount(4, $articleStruct); $this->assertEquals('title1', $articleStruct['title']); $this->assertEquals('text1', $articleStruct['text']); $this->assertEquals('sport', $articleStruct['categoryName']); } function testPostDoArticleExpectExceptionBecauseCategoryNotFound() { $this->expectException(BadRequestException::class); $this->expectExceptionMessage('The Category must be international, national or sport'); TestEnv::http()->newRequest() ->post(['api', 'article']) ->bodyJson([ 'title' => 'title1', 'categoryName' => 'abc', 'text' => 'text1' ]) ->exec(); } function testPutDoArticle() { $response = TestEnv::http()->newRequest() ->put(['api', 'article',$this->article1Id]) ->bodyJson([ 'title' => 'title1', 'categoryName' => 'sport', 'text' => 'text1' ]) ->exec(); $articleStruct = $response->parseJson(); $this->assertCount(4, $articleStruct); $this->assertEquals('title1', $articleStruct['title']); $this->assertEquals('text1', $articleStruct['text']); $this->assertEquals('sport', $articleStruct['categoryName']); } function testPutDoArticle1() { $response = TestEnv::http()->newRequest() ->put(['api', 'article',$this->article1Id]) ->bodyJson([ 'title' => 'title1', ]) ->exec(); $articleStruct = $response->parseJson(); $this->assertCount(4, $articleStruct); $this->assertEquals('title1', $articleStruct['title']); $this->assertEquals('Loren ipsum 1', $articleStruct['text']); $this->assertEquals('news', $articleStruct['categoryName']); } function testPutDoArticle2() { $response = TestEnv::http()->newRequest() ->put(['api', 'article',$this->article1Id]) ->bodyJson([ 'categoryName' => 'sport', ]) ->exec(); $articleStruct = $response->parseJson(); $this->assertCount(4, $articleStruct); $this->assertEquals('Title 1', $articleStruct['title']); $this->assertEquals('Loren ipsum 1', $articleStruct['text']); $this->assertEquals('sport', $articleStruct['categoryName']); } function testPutDoArticle3() { $response = TestEnv::http()->newRequest() ->put(['api', 'article',$this->article1Id]) ->bodyJson([ 'text' => 'text1', ]) ->exec(); $articleStruct = $response->parseJson(); $this->assertCount(4, $articleStruct); $this->assertEquals('Title 1', $articleStruct['title']); $this->assertEquals('text1', $articleStruct['text']); $this->assertEquals('news', $articleStruct['categoryName']); } function testPutDoArticleExpectExceptionBecauseCategoryNotFound() { $this->expectException(BadRequestException::class); $this->expectExceptionMessage('The Category must be international, national or sport'); TestEnv::http()->newRequest() ->put(['api', 'article',$this->article1Id]) ->bodyJson([ 'title' => 'title1', 'categoryName' => 'abc', 'text' => 'text1' ]) ->exec(); } function testPutDoArticleExpectExceptionBecauseArticleNotFound() { $this->expectException(PageNotFoundException::class); $this->expectExceptionMessage('Article not found'); TestEnv::http()->newRequest() ->put(['api', 'article', 25436857]) ->bodyJson([ 'title' => 'title1', 'categoryName' => 'abc', 'text' => 'text1' ]) ->exec(); } function testDeleteDoArticle() { $response = TestEnv::http()->newRequest() ->delete(['api', 'article',$this->article1Id]) ->exec(); $tx = TestEnv::createTransaction(); $this->assertEquals(2,TestEnv::temUtil()->count(Article::class)); $tx->commit(); } }