-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.5' of https://github.com/sulu/SuluArticleBundle
- Loading branch information
Showing
3 changed files
with
141 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Functional\Markup; | ||
|
||
use ONGR\ElasticsearchBundle\Service\Manager; | ||
use Sulu\Bundle\ArticleBundle\Markup\ArticleLinkProvider; | ||
use Sulu\Bundle\TestBundle\Testing\SuluTestCase; | ||
|
||
class ArticleLinkProviderTest extends SuluTestCase | ||
{ | ||
/** | ||
* @var ArticleLinkProvider | ||
*/ | ||
private $articleLinkProvider; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->initPhpcr(); | ||
|
||
/** @var Manager $manager */ | ||
$manager = $this->getContainer()->get('es.manager.default'); | ||
$manager->dropAndCreateIndex(); | ||
$manager = $this->getContainer()->get('es.manager.live'); | ||
$manager->dropAndCreateIndex(); | ||
|
||
$this->articleLinkProvider = $this->getContainer()->get('sulu_article.markup.link_provider'); | ||
} | ||
|
||
public function testPreload() | ||
{ | ||
$articles = [ | ||
$this->createArticle(), | ||
$this->createAndPublishArticle(), | ||
]; | ||
|
||
$uuids = array_map( | ||
function (array $data) { | ||
return $data['id']; | ||
}, | ||
$articles | ||
); | ||
|
||
$result = $this->articleLinkProvider->preload($uuids, 'de', false); | ||
|
||
$this->assertCount(2, $result); | ||
$this->assertEquals($articles[0]['id'], $result[0]->getId()); | ||
$this->assertFalse($result[0]->isPublished()); | ||
$this->assertEquals($articles[1]['id'], $result[1]->getId()); | ||
$this->assertTrue($result[1]->isPublished()); | ||
} | ||
|
||
public function testPreloadPublished() | ||
{ | ||
$articles = [ | ||
$this->createArticle(), | ||
$this->createAndPublishArticle(), | ||
]; | ||
|
||
$uuids = array_map( | ||
function (array $data) { | ||
return $data['id']; | ||
}, | ||
$articles | ||
); | ||
|
||
$result = $this->articleLinkProvider->preload($uuids, 'de'); | ||
|
||
$this->assertCount(1, $result); | ||
$this->assertEquals($articles[1]['id'], $result[0]->getId()); | ||
} | ||
|
||
private function createArticle($title = 'Test-Article', $template = 'default', $data = []) | ||
{ | ||
$client = $this->createAuthenticatedClient(); | ||
$client->request( | ||
'POST', | ||
'/api/articles?locale=de', | ||
array_merge($data, ['title' => $title, 'template' => $template]) | ||
); | ||
|
||
return json_decode($client->getResponse()->getContent(), true); | ||
} | ||
|
||
private function createAndPublishArticle($title = 'Test-Article', $template = 'default', $data = []) | ||
{ | ||
$client = $this->createAuthenticatedClient(); | ||
$client->request( | ||
'POST', | ||
'/api/articles?locale=de&action=publish', | ||
array_merge($data, ['title' => $title, 'template' => $template]) | ||
); | ||
|
||
return json_decode($client->getResponse()->getContent(), true); | ||
} | ||
} |