From a94b1dce78b433af3f39495db92b49212527f084 Mon Sep 17 00:00:00 2001 From: itkg-nanne Date: Tue, 31 Jan 2017 10:34:29 +0100 Subject: [PATCH] refresh test (#1136) * refresh test * add command tests * use trait * add use * change backOffice to backoffice * refresh tests * refresh composer * refresh composer --- composer.lock | 42 +++++----- .../OrchestraPublishContentCommandTest.php | 51 +++++++++++++ .../OrchestraPublishNodeCommandTest.php | 32 ++------ .../OrchestraUnpublishContentCommandTest.php | 51 +++++++++++++ .../OrchestraUnpublishNodeCommandTest.php | 30 ++------ .../Command/PublishElementCommandTrait.php | 76 +++++++++++++++++++ .../Controller/ContentTypeControllerTest.php | 8 +- .../FormControllersSecurityTest.php | 4 +- .../Repository/ContentRepositoryTest.php | 32 ++++++++ 9 files changed, 248 insertions(+), 78 deletions(-) create mode 100644 src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraPublishContentCommandTest.php create mode 100644 src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraUnpublishContentCommandTest.php create mode 100644 src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/PublishElementCommandTrait.php diff --git a/composer.lock b/composer.lock index 1a3f97b82..d26ce0dac 100644 --- a/composer.lock +++ b/composer.lock @@ -2689,12 +2689,12 @@ "source": { "type": "git", "url": "https://github.com/open-orchestra/open-orchestra-cms-bundle.git", - "reference": "166795e1776d56b14d017a960bcbaca634e3869f" + "reference": "37a0b6657bd1071e46b1fe30f3a82469feefaf59" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/open-orchestra/open-orchestra-cms-bundle/zipball/166795e1776d56b14d017a960bcbaca634e3869f", - "reference": "166795e1776d56b14d017a960bcbaca634e3869f", + "url": "https://api.github.com/repos/open-orchestra/open-orchestra-cms-bundle/zipball/37a0b6657bd1071e46b1fe30f3a82469feefaf59", + "reference": "37a0b6657bd1071e46b1fe30f3a82469feefaf59", "shasum": "" }, "require": { @@ -2793,7 +2793,7 @@ } ], "description": "This bundle provide the Back Office part of Open Orchestra", - "time": "2017-01-30 17:22:08" + "time": "2017-01-31 09:08:30" }, { "name": "open-orchestra/open-orchestra-display-bundle", @@ -3182,12 +3182,12 @@ "source": { "type": "git", "url": "https://github.com/open-orchestra/open-orchestra-model-bundle.git", - "reference": "82f7dea431fce8adb7547f0d7ab095ebe9517008" + "reference": "a6f1527703f5c97039d153585f7436fc8d99bd5d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/open-orchestra/open-orchestra-model-bundle/zipball/82f7dea431fce8adb7547f0d7ab095ebe9517008", - "reference": "82f7dea431fce8adb7547f0d7ab095ebe9517008", + "url": "https://api.github.com/repos/open-orchestra/open-orchestra-model-bundle/zipball/a6f1527703f5c97039d153585f7436fc8d99bd5d", + "reference": "a6f1527703f5c97039d153585f7436fc8d99bd5d", "shasum": "" }, "require": { @@ -3222,7 +3222,7 @@ } ], "description": "A MongoDB implemantation of the Open Orchestra Model Interface", - "time": "2017-01-30 16:16:00" + "time": "2017-01-31 08:30:58" }, { "name": "open-orchestra/open-orchestra-model-interface", @@ -3230,12 +3230,12 @@ "source": { "type": "git", "url": "https://github.com/open-orchestra/open-orchestra-model-interface.git", - "reference": "29ec17a8f9399054f4bef58ca5adb0097f655b44" + "reference": "8430d76dc39f93710ea1d82fe56836470160f13a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/open-orchestra/open-orchestra-model-interface/zipball/29ec17a8f9399054f4bef58ca5adb0097f655b44", - "reference": "29ec17a8f9399054f4bef58ca5adb0097f655b44", + "url": "https://api.github.com/repos/open-orchestra/open-orchestra-model-interface/zipball/8430d76dc39f93710ea1d82fe56836470160f13a", + "reference": "8430d76dc39f93710ea1d82fe56836470160f13a", "shasum": "" }, "require": { @@ -3267,7 +3267,7 @@ } ], "description": "Describe all entity and repository to implement for the whole OpenOrchestra project", - "time": "2017-01-30 15:54:12" + "time": "2017-01-31 08:16:08" }, { "name": "open-orchestra/open-orchestra-mongo-libs", @@ -3275,12 +3275,12 @@ "source": { "type": "git", "url": "https://github.com/open-orchestra/open-orchestra-mongo-libs.git", - "reference": "21a205dca516d1af37a050cdf187673d5b03d507" + "reference": "f724def53b32e3683e569cc9974d437d7336b53b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/open-orchestra/open-orchestra-mongo-libs/zipball/21a205dca516d1af37a050cdf187673d5b03d507", - "reference": "21a205dca516d1af37a050cdf187673d5b03d507", + "url": "https://api.github.com/repos/open-orchestra/open-orchestra-mongo-libs/zipball/f724def53b32e3683e569cc9974d437d7336b53b", + "reference": "f724def53b32e3683e569cc9974d437d7336b53b", "shasum": "" }, "require": { @@ -3317,7 +3317,7 @@ } ], "description": "Some libraries to use MongoDB in Open Orchestra", - "time": "2017-01-25 15:59:03" + "time": "2017-01-31 08:14:21" }, { "name": "open-orchestra/open-orchestra-user-bundle", @@ -3325,12 +3325,12 @@ "source": { "type": "git", "url": "https://github.com/open-orchestra/open-orchestra-user-bundle.git", - "reference": "41d25ca4f39f993acb61a946cb3f4e64e4dd22a3" + "reference": "ace78927fc5ca29d234ac667ebc8ec0bf7cb430d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/open-orchestra/open-orchestra-user-bundle/zipball/41d25ca4f39f993acb61a946cb3f4e64e4dd22a3", - "reference": "41d25ca4f39f993acb61a946cb3f4e64e4dd22a3", + "url": "https://api.github.com/repos/open-orchestra/open-orchestra-user-bundle/zipball/ace78927fc5ca29d234ac667ebc8ec0bf7cb430d", + "reference": "ace78927fc5ca29d234ac667ebc8ec0bf7cb430d", "shasum": "" }, "require": { @@ -3370,7 +3370,7 @@ } ], "description": "An override of FosUserBundle to provide authentication on Open Orchestra", - "time": "2017-01-20 08:22:03" + "time": "2017-01-31 08:17:21" }, { "name": "paragonie/random_compat", @@ -5952,7 +5952,7 @@ "compare", "equality" ], - "time": "2017-01-29T09:50:25+00:00" + "time": "2017-01-29 09:50:25" }, { "name": "sebastian/diff", diff --git a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraPublishContentCommandTest.php b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraPublishContentCommandTest.php new file mode 100644 index 000000000..b1e3f4bcc --- /dev/null +++ b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraPublishContentCommandTest.php @@ -0,0 +1,51 @@ +application = new Application($client->getKernel()); + $this->application->setAutoExit(false); + $this->application->add(new OrchestraPublishContentCommand()); + } + + /** + * Test the command + * + * @param string $siteId + * + * @dataProvider provideSiteId + */ + public function testExecute($siteId) + { + $this->executePublish($siteId, 'orchestra:publish:content', 'open_orchestra_model.repository.content', 'content'); + } + + /** + * Provide site id + */ + public function provideSiteId() + { + return array( + array('2'), + ); + } +} diff --git a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraPublishNodeCommandTest.php b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraPublishNodeCommandTest.php index c037e38a4..7ecbec6d5 100644 --- a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraPublishNodeCommandTest.php +++ b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraPublishNodeCommandTest.php @@ -1,17 +1,19 @@ application->find('orchestra:publish:node'); - $commandTester = new CommandTester($command); - - $site = static::$kernel->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId); - $fromStatus = static::$kernel->getContainer()->get('open_orchestra_model.repository.status') - ->findByAutoPublishFrom(); - $nodes = static::$kernel->getContainer()->get('open_orchestra_model.repository.node') - ->findNodeToAutoPublish($site->getSiteId(), $fromStatus); - - $commandTester->execute(array('command' => $command->getName())); - $this->assertRegExp( - '/Publishing nodes for siteId ' . $siteId . '/', - $commandTester->getDisplay() - ); - - foreach ($nodes as $node) { - $this->assertRegExp( - '/-> ' . $node->getName() . ' \(v' . $node->getVersion() . ' ' . $node->getLanguage() . '\) published/', - $commandTester->getDisplay() - ); - } - - $this->assertRegExp('/Done./', $commandTester->getDisplay()); + $this->executePublish($siteId, 'orchestra:publish:node', 'open_orchestra_model.repository.node', 'node'); } /** diff --git a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraUnpublishContentCommandTest.php b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraUnpublishContentCommandTest.php new file mode 100644 index 000000000..e3768de44 --- /dev/null +++ b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraUnpublishContentCommandTest.php @@ -0,0 +1,51 @@ +application = new Application($client->getKernel()); + $this->application->setAutoExit(false); + $this->application->add(new OrchestraUnpublishContentCommand()); + } + + /** + * Test the command + * + * @param string $siteId + * + * @dataProvider provideSiteId + */ + public function testExecute($siteId) + { + $this->executeUnpublish($siteId, 'orchestra:unpublish:content', 'open_orchestra_model.repository.content', 'content'); + } + + /** + * Provide site id + */ + public function provideSiteId() + { + return array( + array('2'), + ); + } +} diff --git a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraUnpublishNodeCommandTest.php b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraUnpublishNodeCommandTest.php index 870291a3b..4d7797b45 100644 --- a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraUnpublishNodeCommandTest.php +++ b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/OrchestraUnpublishNodeCommandTest.php @@ -1,17 +1,19 @@ application->find('orchestra:unpublish:node'); - $commandTester = new CommandTester($command); - - $site = static::$kernel->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId); - $publishedStatus = static::$kernel->getContainer()->get('open_orchestra_model.repository.status') - ->findOneByPublished(); - $nodes = static::$kernel->getContainer()->get('open_orchestra_model.repository.node') - ->findNodeToAutoUnpublish($site->getSiteId(), $publishedStatus); - - $commandTester->execute(array('command' => $command->getName())); - $this->assertRegExp( - '/Unpublishing nodes for siteId ' . $siteId . '/', - $commandTester->getDisplay() - ); - - foreach ($nodes as $node) { - $this->assertRegExp( - '/-> ' . $node->getName(). ' \(v' . $node->getVersion() . ' ' . $node->getLanguage() . '\) unpublished/', - $commandTester->getDisplay() - ); - } - - $this->assertRegExp('/Done./', $commandTester->getDisplay()); + $this->executeUnpublish($siteId, 'orchestra:unpublish:node', 'open_orchestra_model.repository.node', 'node'); } /** diff --git a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/PublishElementCommandTrait.php b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/PublishElementCommandTrait.php new file mode 100644 index 000000000..75470f152 --- /dev/null +++ b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Command/PublishElementCommandTrait.php @@ -0,0 +1,76 @@ +application->find($commandName); + $commandTester = new CommandTester($command); + + $site = static::$kernel->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId); + $fromStatus = static::$kernel->getContainer()->get('open_orchestra_model.repository.status') + ->findByAutoPublishFrom(); + $elements = static::$kernel->getContainer()->get($repositoryName) + ->findElementToAutoPublish($site->getSiteId(), $fromStatus); + + $commandTester->execute(array('command' => $command->getName())); + $this->assertRegExp( + '/Publishing '.$entityName.'s for siteId ' . $siteId . '/', + $commandTester->getDisplay() + ); + + foreach ($elements as $element) { + $this->assertRegExp( + '/-> ' . $element->getName() . ' \(v' . $element->getVersion() . ' ' . $element->getLanguage() . '\) published/', + $commandTester->getDisplay() + ); + } + + $this->assertRegExp('/Done./', $commandTester->getDisplay()); + } + /** + * @param string $siteId + * @param string $commandName + * @param string $repositoryName + * @param string $entityName + */ + public function executeUnpublish($siteId, $commandName, $repositoryName, $entityName) + { + $command = $this->application->find($commandName); + $commandTester = new CommandTester($command); + + $site = static::$kernel->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId); + $fromStatus = static::$kernel->getContainer()->get('open_orchestra_model.repository.status') + ->findOneByPublished(); + $elements = static::$kernel->getContainer()->get($repositoryName) + ->findElementToAutoUnpublish($site->getSiteId(), $fromStatus); + + $commandTester->execute(array('command' => $command->getName())); + $this->assertRegExp( + '/Unpublishing '.$entityName.'s for siteId ' . $siteId . '/', + $commandTester->getDisplay() + ); + + foreach ($elements as $element) { + $this->assertRegExp( + '/-> ' . $element->getName() . ' \(v' . $element->getVersion() . ' ' . $element->getLanguage() . '\) unpublished/', + $commandTester->getDisplay() + ); + } + + $this->assertRegExp('/Done./', $commandTester->getDisplay()); + } +} diff --git a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Controller/ContentTypeControllerTest.php b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Controller/ContentTypeControllerTest.php index b83ff670b..a7a549505 100644 --- a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Controller/ContentTypeControllerTest.php +++ b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Controller/ContentTypeControllerTest.php @@ -19,7 +19,7 @@ class ContentTypeControllerTest extends AbstractFormTest protected $username = 'developer'; protected $password = 'developer'; - + /** * Set up the test */ @@ -51,7 +51,7 @@ public function testFormController() */ public function testEditContent() { - $url = '/admin/content/form/welcome?language=fr'; + $url = '/admin/content/form/welcome/fr'; $crawler = $this->client->request('GET', $url); $this->assertNotContains('has-error', $this->client->getResponse()->getContent()); $contentForm = $crawler->selectButton('Save')->form(); @@ -63,7 +63,7 @@ public function testEditContent() $this->submitForm($form); - $url = '/admin/content/form/welcome?language=fr'; + $url = '/admin/content/form/welcome/fr'; $this->client->request('GET', $url); $this->assertNotContains('has-error', $this->client->getResponse()->getContent()); } @@ -73,7 +73,7 @@ public function testEditContent() */ public function testNewContent() { - $url = '/admin/content/new/news'; + $url = '/admin/content/new/news/en'; $this->client->request('GET', $url); $this->assertNotContains('has-error', $this->client->getResponse()->getContent()); } diff --git a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Controller/FormControllersSecurityTest.php b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Controller/FormControllersSecurityTest.php index 9197bd75a..92f27b932 100644 --- a/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Controller/FormControllersSecurityTest.php +++ b/src/OpenOrchestra/Tests/Functional/BackofficeBundle/Controller/FormControllersSecurityTest.php @@ -42,8 +42,8 @@ public function provideApiUrl() 9 => array('/admin/keyword/new'), 10 => array('/admin/group/new'), 11 => array('/admin/group/form/group-id'), - 12 => array('/admin/content/form/root'), - 13 => array('/admin/content/new/root'), + 12 => array('/admin/content/form/welcome/fr'), + 13 => array('/admin/content/new/news/en'), 14 => array('/admin/redirection/form/redirection-id'), 15 => array('/admin/redirection/new'), 18 => array('/admin/status/form/root'), diff --git a/src/OpenOrchestra/Tests/Functional/ModelBundle/Repository/ContentRepositoryTest.php b/src/OpenOrchestra/Tests/Functional/ModelBundle/Repository/ContentRepositoryTest.php index be98c07b6..a54b0dc58 100644 --- a/src/OpenOrchestra/Tests/Functional/ModelBundle/Repository/ContentRepositoryTest.php +++ b/src/OpenOrchestra/Tests/Functional/ModelBundle/Repository/ContentRepositoryTest.php @@ -582,6 +582,38 @@ public function testHasStatusedElement() $this->assertFalse($this->repository->hasStatusedElement($status)); } + /** + * Test findAllCurrentlyPublishedByContentId + */ + public function testFindAllCurrentlyPublishedByContentId() + { + $contents = $this->repository->findAllCurrentlyPublishedByContentId('bien_vivre_en_france'); + + $this->assertEquals(1, count($contents)); + } + + /** + * Test findElementToAutoPublish + */ + public function testFindElementToAutoPublish() + { + $fromStatus = $this->statusRepository->findByAutoPublishFrom(); + $contents = $this->repository->findElementToAutoPublish('2', $fromStatus); + + $this->assertEquals(0, count($contents)); + } + + /** + * Test findElementToAutoUnpublish + */ + public function testFindElementToAutoUnpublish() + { + $publishedStatus = $this->statusRepository->findOneByPublished(); + $contents = $this->repository->findElementToAutoUnpublish('2', $publishedStatus); + + $this->assertEquals(0, count($contents)); + } + /** * @param string $condition *