Skip to content

Commit

Permalink
revise api journal article file controller tests according to new tes…
Browse files Browse the repository at this point in the history
…t logic
  • Loading branch information
behram committed Jul 10, 2016
1 parent dc58fbc commit c303a8d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 55 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ script:
- phpunit -c app src/Ojs/JournalBundle/
- phpunit -c app src/Ojs/SiteBundle/
- phpunit -c app src/Ojs/UserBundle/
- phpunit -c app src/Ojs/ApiBundle/Tests/Controller/InstitutionRestControllerTest.php
- phpunit -c app src/Ojs/ApiBundle/Tests/Controller/JournalArticleAuthorRestControllerTest.php
- phpunit -c app src/Ojs/ApiBundle/Tests/Controller/JournalArticleCitationRestControllerTest.php
- phpunit -c app src/Ojs/ApiBundle/Tests/Controller/JournalArticleFileRestControllerTest.php

notifications:
slack: bulutyazilim:8GtvUiq3935dZRc1SObHJVcR#ojs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ public function __construct()
$this->sampleArticleFileEncoded = base64_encode(file_get_contents($articleFileCacheDir.'sampleArticleFile'));
}

public function testNewAuthorsAction()
{
$client = $this->client;
$client->request('GET', '/api/v1/journal/1/article/1/files/new?apikey='.$this->apikey);

$this->assertStatusCode(200, $client);
}

public function testGetFilesAction()
{
$routeParameters = $this->getRouteParams([
'journalId' => 1,
'articleId' => 1,
]);
$url = $this->router->generate('api_1_article_get_files', $routeParameters);
$this->client->request('GET', $url);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$client = $this->client;
$client->request('GET', '/api/v1/journal/1/article/1/files?apikey='.$this->apikey);

$this->assertStatusCode(200, $client);
}

public function testPostFileAction()
Expand All @@ -48,34 +52,23 @@ public function testPostFileAction()
'title' => 'PHPUnit Test Title',
'description' => 'PHPUnit Test Title',
];
$routeParameters = $this->getRouteParams([
'journalId' => 1,
'articleId' => 1,
]);
$url = $this->router->generate('api_1_article_post_file', $routeParameters);
$this->client->request(
'POST',
$url,
'/api/v1/journal/1/article/1/files?apikey='.$this->apikey,
[],
[],
['CONTENT_TYPE' => 'application/json'],
json_encode($content)
);
$response = $this->client->getResponse();
$this->assertEquals(201, $response->getStatusCode());
$this->assertStatusCode(201, $this->client);
}

public function testGetFileAction()
{
$routeParameters = $this->getRouteParams([
'journalId' => 1,
'id' => 1,
'articleId' => 1,
]);
$url = $this->router->generate('api_1_article_get_file', $routeParameters);
$this->client->request('GET', $url);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$client = $this->client;
$client->request('GET', '/api/v1/journal/1/article/1/files/1?apikey='.$this->apikey);

$this->assertStatusCode(200, $client);
}

public function testPutFileAction()
Expand All @@ -90,22 +83,15 @@ public function testPutFileAction()
'title' => 'PHPUnit Test Title Put',
'description' => 'PHPUnit Test description Put',
];
$routeParameters = $this->getRouteParams([
'journalId' => 1,
'id' => 550,
'articleId' => 1,
]);
$url = $this->router->generate('api_1_article_put_file', $routeParameters);
$this->client->request(
'PUT',
$url,
'/api/v1/journal/1/article/1/files/550?apikey='. $this->apikey,
[],
[],
['CONTENT_TYPE' => 'application/json'],
json_encode($content)
);
$response = $this->client->getResponse();
$this->assertEquals(201, $response->getStatusCode());
$this->assertStatusCode(201, $this->client);
}

public function testPatchFileAction()
Expand All @@ -117,37 +103,24 @@ public function testPatchFileAction()
],
'title' => 'PHPUnit Test Title Patch',
];
$routeParameters = $this->getRouteParams([
'journalId' => 1,
'id' => 1,
'articleId' => 1,
]);
$url = $this->router->generate('api_1_article_patch_file', $routeParameters);
$this->client->request(
'PATCH',
$url,
'/api/v1/journal/1/article/1/files/1?apikey='. $this->apikey,
[],
[],
['CONTENT_TYPE' => 'application/json'],
json_encode($content)
);
$response = $this->client->getResponse();
$this->assertEquals(204, $response->getStatusCode());
$this->assertStatusCode(204, $this->client);
}

public function testDeleteFileAction()
{
$routeParameters = $this->getRouteParams([
'id' => 1,
'journalId' => 1,
'articleId' => 1,
]);
$url = $this->router->generate('api_1_article_delete_file', $routeParameters);
$entityId = $this->sampleObjectLoader->loadArticleFile();
$this->client->request(
'DELETE',
$url
'/api/v1/journal/1/article/1/files/'.$entityId.'?apikey='. $this->apikey
);
$response = $this->client->getResponse();
$this->assertEquals(204, $response->getStatusCode());
$this->assertStatusCode(204, $this->client);
}
}
11 changes: 11 additions & 0 deletions src/Ojs/CoreBundle/Service/SampleObjectLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,15 @@ public function loadArticleCitation()

return $objects['article_citation']->getId();
}

/**
* @return int
*/
public function loadArticleFile()
{
$objects = $this->aliceManager->loadFiles([$this->fixturesRoot.'article_file.yml']);
$this->aliceManager->persist($objects, false);

return $objects['article_file']->getId();
}
}
9 changes: 9 additions & 0 deletions src/Ojs/CoreBundle/Tests/DataFixtures/ORM/article_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Ojs\JournalBundle\Entity\ArticleFile:
article_file:
article: 1
type: 0
version: 1
keywords: "help,ojs,getting started"
title: "Demo File"
description: Sample file
langCode: en

0 comments on commit c303a8d

Please sign in to comment.