Skip to content

Commit

Permalink
refresh test
Browse files Browse the repository at this point in the history
  • Loading branch information
veolys-nanne committed Mar 31, 2017
1 parent 72d498b commit 453de28
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 177 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,28 @@ public function setUp()

/**
* @param string $name
* @param bool $published
*
* @dataProvider provideStatusName
*/
public function testChangeContentStatus($name, $published)
public function testChangeContentStatus($name)
{
$this->markTestSkipped('To reactivate when API roles will be implemented');

$content = $this->contentRepository->findOneByLanguageAndVersion('206_3_portes', 'fr', 2);
$content = $this->contentRepository->findOneByLanguageAndVersion('206_3_portes', 'fr', '2');
$newStatus = $this->statusRepository->findOneByName($name);
$newStatusId = $newStatus->getId();

$content->setStatus($newStatus);
$this->client->request(
'POST',
'/api/content/' . $content->getId() . '/update',
'PUT',
'/api/content/update-status',
array(),
array(),
array(),
json_encode(array('status_id' => $newStatusId))
static::$kernel->getContainer()->get('jms_serializer')->serialize($content, 'json')
);

$this->assertSame(200, $this->client->getResponse()->getStatusCode());

$newContent = $this->contentRepository->findOneByLanguageAndVersion('206_3_portes', 'fr', 2);
$this->assertSame($published, $newContent->getStatus()->isPublishedState());
$newContent = $this->contentRepository->findOneByLanguageAndVersion('206_3_portes', 'fr', '2');
$this->assertSame($name, $newContent->getStatus()->getName());
}

/**
Expand All @@ -66,9 +63,9 @@ public function testChangeContentStatus($name, $published)
public function provideStatusName()
{
return array(
array('draft', false),
array('pending', false),
array('published', true),
array('draft'),
array('pending'),
array('published'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,28 @@ public function tearDown()
*/
public function testDeleteAction()
{
$this->markTestSkipped('To reactivate when API roles will be implemented');
$nodes = $this->nodeRepository->findByNodeId('fixture_page_contact');
$autoUnpublishTo = $this->statusRepository->findOnebyAutoUnpublishTo();
$currentStatuses = array();

$node = $this->nodeRepository->findOnePublished('fixture_page_contact','fr','2');
$node->getStatus()->setPublishedState(false);
foreach ($nodes as $node) {
$currentStatuses[$node->getId()] = $node->getStatus()->getName();
$node->setStatus($autoUnpublishTo);
}
static::$kernel->getContainer()->get('object_manager')->flush();

$nbNode = count($this->nodeRepository->findLastVersionByType('2'));
$this->client->request('DELETE', '/api/node/fixture_page_contact/delete');
$this->client->request('DELETE', '/api/node/delete/fixture_page_contact');
$nodesDelete = $this->nodeRepository->findLastVersionByType('2');

$this->assertCount($nbNode - 1, $nodesDelete);

foreach ($nodes as $node) {
$status = $this->statusRepository->findOneByName($currentStatuses[$node->getId()]);
$node->setStatus($status);
}
$this->undeleteNodes($nodes);
static::$kernel->getContainer()->get('object_manager')->flush();
}

/**
Expand All @@ -93,37 +104,12 @@ protected function republishNodes($nodes)
/**
* Test node new version and references
*/
public function testNewVersioneNode()
public function testNewVersionNode()
{
$this->markTestSkipped('To reactivate when API roles will be implemented');

$node = $this->nodeRepository
->findInLastVersion('fixture_page_community', 'fr', '2');
$this->client->request('POST', '/api/node/fixture_page_community/new-version?language=fr');

$nodeLastVersion = $this->nodeRepository
->findInLastVersion('fixture_page_community', 'fr', '2');
$countVersion = count($this->nodeRepository->findByNodeId('fixture_page_community'));
$this->client->request('POST', '/api/node/new-version/fixture_page_community/fr/1');

$this->assertSame($node->getVersion()+1, $nodeLastVersion->getVersion());
}

/**
* Test creation of new language for a node
*/
public function testCreateNewLanguageNode()
{
$this->markTestSkipped('To reactivate when API roles will be implemented');

$this->client->request('GET', '/api/node/root/show-or-create', array('language' => 'de'));

$node = $this->nodeRepository
->findInLastVersion('root', 'de', '2');

$this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node);
$this->assertSame(1, $node->getVersion());
$this->assertSame('de', $node->getLanguage());
static::$kernel->getContainer()->get('object_manager')->remove($node);
static::$kernel->getContainer()->get('object_manager')->flush();
$this->assertSame($countVersion + 1, count($this->nodeRepository->findByNodeId('fixture_page_community')));
}

/**
Expand All @@ -143,45 +129,36 @@ public function countAreaRef(NodeInterface $node)

/**
* @param string $name
* @param int $publishedVersion
*
* @dataProvider provideStatusNameAndPublishedVersion
* @dataProvider provideStatusName
*/
public function testChangeNodeStatus($name, $publishedVersion)
public function testChangeNodeStatus($name)
{
$this->markTestSkipped('To reactivate when change status embed is fixed');

$node = $this->nodeRepository->findInLastVersion('root', 'fr', '2');
$newStatus = $this->statusRepository->findOneByName($name);
$requestContent = json_encode(array(
'id' => $node->getId(),
'status' => array(
'id' => $newStatus->getId()
)
));
$node->setStatus($newStatus);
$this->client->request(
'PUT',
'/api/node/update-status',
array(),
array(),
array(),
$requestContent
static::$kernel->getContainer()->get('jms_serializer')->serialize($node, 'json')
);

$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$newNode = $this->nodeRepository->findOnePublished('root', 'fr', '2');
$this->assertEquals($publishedVersion, $newNode->getVersion());
$this->assertEquals($name, $newNode->getStatus()->getName());
}

/**
* @return array
*/
public function provideStatusNameAndPublishedVersion()
public function provideStatusName()
{
return array(
array('pending', 1),
array('published', 2),
array('draft', 1),
array('published'),
array('draft'),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function testNodeForms()
*/
public function testNewNodePageHome()
{
$this->markTestSkipped('To reactivate when API roles will be implemented');
$this->markTestSkipped();

$crawler = $this->client->request('GET', '/admin/node/new/fixture_page_community');
$crawler = $this->client->request('GET', '/admin/node/new/2/fr/fixture_page_news/1');

$formNode = $crawler->selectButton('Save')->form();

Expand All @@ -80,7 +80,8 @@ public function testNewNodePageHome()

$this->submitForm($formNode);

$this->client->request('GET', '/api/node/' . $nodeName);
$node = static::$kernel->getContainer()->get('open_orchestra_model.repository.node')->findOneByName($nodeName);
$this->client->request('GET', '/api/node/show/' . $node->getNodeId() . '/' . $node->getSiteId() . '/' . $node->getLanguage() . '/' . $node->getVersion());
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));
$node = json_decode($this->client->getResponse()->getContent());
Expand All @@ -92,13 +93,15 @@ public function testNewNodePageHome()
$statuses[1] = $statusRepository->findOneBy(array("name" => "published"));
$statuses[2] = $statusRepository->findOneBy(array("name" => "pending"));

$this->assertEquals(1, count($this->redirectionRepository->findAll()));
$autoUnpublishTo = $statusRepository->findOnebyAutoUnpublishTo();

$routeDocumentCount = count($this->routeDocumentRepository->findAll());
$redirectionCount = count($this->redirectionRepository->findAll());

$this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[2], 1, $routeDocumentCount);
$this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[1], 1, $routeDocumentCount + 2);
$this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[2], $redirectionCount, $routeDocumentCount);
$this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[1], $redirectionCount, $routeDocumentCount + 2);

$this->client->request('POST', '/api/node/' . $nodeName . '/new-version/1?language=' . $node->language, array());
$this->client->request('POST', '/api/node/new-version/' . $nodeName . '/fr/' . $node->version, array());
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));

Expand All @@ -107,12 +110,19 @@ public function testNewNodePageHome()
$this->documentManager->persist($newNode);
$this->documentManager->flush($newNode);

$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[2], 1, $routeDocumentCount + 2);
$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[1], 3, $routeDocumentCount + 6);
$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[0], 1, $routeDocumentCount + 2);
$this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[0], 1, $routeDocumentCount);
$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[2], $redirectionCount, $routeDocumentCount + 2);
$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[1], $redirectionCount + 2, $routeDocumentCount + 6);
$this->changeNodeStatusWithRouteRedirectionTest($newNode->getId(), $statuses[0], $redirectionCount, $routeDocumentCount + 2);
$this->changeNodeStatusWithRouteRedirectionTest($nodeId, $statuses[0], $redirectionCount, $routeDocumentCount);

$nodes = $this->nodeRepository->findByNodeId($nodeName);
foreach ($nodes as $node) {
var_dump($node->getId());
$node->setStatus($autoUnpublishTo);
}
static::$kernel->getContainer()->get('object_manager')->flush();

$this->client->request('DELETE', '/api/node/' . $nodeName . '/delete');
$this->client->request('DELETE', '/api/node/delete/' . $nodeName);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());

$this->assertEquals(1, count($this->redirectionRepository->findAll()));
Expand All @@ -129,8 +139,12 @@ public function testNewNodePageHome()
*/
protected function changeNodeStatusWithRouteRedirectionTest($nodeId, StatusInterface $status, $redirectionNumber, $routeNumber)
{
$this->client->request('POST', '/api/node/' . $nodeId . '/update',
array(), array(), array(), '{"status_id": "'. $status->getId() .'"}');
$node = $this->nodeRepository->find($nodeId);
$node->setStatus($status);
$this->client->request('PUT', '/api/node/update-status',
array(), array(), array(), static::$kernel->getContainer()->get('jms_serializer')->serialize($node, 'json'));


$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));
$this->assertEquals($redirectionNumber, count($this->redirectionRepository->findAll()));
Expand Down
Loading

0 comments on commit 453de28

Please sign in to comment.