From 6741f9e191811db1cc80c3c6dc3b830a5f759acf Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Thu, 20 Dec 2018 13:22:03 +0100 Subject: [PATCH] #73 initialize test structure --- .gitignore | 9 + .travis.yml | 59 ++ codeception.dist.yml | 7 + .../Configuration/Configuration.php | 14 +- tests/_data/.gitkeep | 0 tests/_envs/local.yml | 0 tests/_envs/travis.yml | 10 + tests/_support/AcceptanceTester.php | 13 + tests/_support/App/Services/.gitkeep | 0 tests/_support/App/TestAppKernel.php | 62 +++ .../MakeServicesPublicPass.php | 30 + .../MonologChannelLoggerPass.php | 27 + tests/_support/FunctionalTester.php | 13 + tests/_support/Helper/Browser/PhpBrowser.php | 236 ++++++++ tests/_support/Helper/Browser/WebDriver.php | 62 +++ tests/_support/Helper/PimcoreAdminJson.php | 58 ++ tests/_support/Helper/PimcoreBackend.php | 514 ++++++++++++++++++ tests/_support/Helper/PimcoreBundleCore.php | 63 +++ tests/_support/Helper/PimcoreCore.php | 163 ++++++ tests/_support/Helper/PimcoreUser.php | 125 +++++ tests/_support/Helper/Unit.php | 16 + tests/_support/Test/DachcomBundleTestCase.php | 34 ++ tests/_support/UnitTester.php | 13 + tests/_support/Util/Autoloader.php | 28 + tests/_support/Util/FileGeneratorHelper.php | 76 +++ tests/_support/Util/MembersHelper.php | 37 ++ tests/_support/Util/VersionHelper.php | 64 +++ tests/bundle_configuration | 21 + tests/bundle_tests/_bootstrap.php | 18 + tests/bundle_tests/acceptance.suite.dist.yml | 19 + tests/bundle_tests/acceptance/_bootstrap.php | 2 + tests/bundle_tests/functional.suite.dist.yml | 14 + tests/bundle_tests/functional/_bootstrap.php | 2 + tests/bundle_tests/unit.suite.dist.yml | 8 + .../unit/Config/ConfigurationTest.php | 32 ++ tests/bundle_tests/unit/_bootstrap.php | 2 + tests/codeception.dist.yml | 17 + tests/etc/config/bundle/appKernel | 16 + .../etc/config/bundle/extensions.template.php | 7 + .../config/bundle/symfony/config_default.yml | 0 tests/etc/config/bundle/system.template.php | 167 ++++++ .../template/controller/DefaultController | 23 + .../etc/config/bundle/template/views/default | 14 + .../etc/config/bundle/template/views/snippet | 6 + tests/etc/config/system/config.yml | 14 + tests/etc/config/system/php.ini | 8 + tests/etc/scripts/codeception | 12 + tests/etc/travis/install | 81 +++ tests/etc/travis/script | 6 + tests/kernelBuilder.php | 19 + 50 files changed, 2233 insertions(+), 8 deletions(-) create mode 100644 .travis.yml create mode 100644 codeception.dist.yml create mode 100644 tests/_data/.gitkeep create mode 100644 tests/_envs/local.yml create mode 100644 tests/_envs/travis.yml create mode 100644 tests/_support/AcceptanceTester.php create mode 100644 tests/_support/App/Services/.gitkeep create mode 100644 tests/_support/App/TestAppKernel.php create mode 100644 tests/_support/DependencyInjection/MakeServicesPublicPass.php create mode 100644 tests/_support/DependencyInjection/MonologChannelLoggerPass.php create mode 100644 tests/_support/FunctionalTester.php create mode 100644 tests/_support/Helper/Browser/PhpBrowser.php create mode 100644 tests/_support/Helper/Browser/WebDriver.php create mode 100644 tests/_support/Helper/PimcoreAdminJson.php create mode 100644 tests/_support/Helper/PimcoreBackend.php create mode 100644 tests/_support/Helper/PimcoreBundleCore.php create mode 100644 tests/_support/Helper/PimcoreCore.php create mode 100644 tests/_support/Helper/PimcoreUser.php create mode 100644 tests/_support/Helper/Unit.php create mode 100644 tests/_support/Test/DachcomBundleTestCase.php create mode 100644 tests/_support/UnitTester.php create mode 100644 tests/_support/Util/Autoloader.php create mode 100644 tests/_support/Util/FileGeneratorHelper.php create mode 100644 tests/_support/Util/MembersHelper.php create mode 100644 tests/_support/Util/VersionHelper.php create mode 100755 tests/bundle_configuration create mode 100644 tests/bundle_tests/_bootstrap.php create mode 100644 tests/bundle_tests/acceptance.suite.dist.yml create mode 100644 tests/bundle_tests/acceptance/_bootstrap.php create mode 100644 tests/bundle_tests/functional.suite.dist.yml create mode 100644 tests/bundle_tests/functional/_bootstrap.php create mode 100644 tests/bundle_tests/unit.suite.dist.yml create mode 100644 tests/bundle_tests/unit/Config/ConfigurationTest.php create mode 100644 tests/bundle_tests/unit/_bootstrap.php create mode 100644 tests/codeception.dist.yml create mode 100644 tests/etc/config/bundle/appKernel create mode 100644 tests/etc/config/bundle/extensions.template.php create mode 100755 tests/etc/config/bundle/symfony/config_default.yml create mode 100755 tests/etc/config/bundle/system.template.php create mode 100644 tests/etc/config/bundle/template/controller/DefaultController create mode 100644 tests/etc/config/bundle/template/views/default create mode 100644 tests/etc/config/bundle/template/views/snippet create mode 100755 tests/etc/config/system/config.yml create mode 100755 tests/etc/config/system/php.ini create mode 100755 tests/etc/scripts/codeception create mode 100755 tests/etc/travis/install create mode 100755 tests/etc/travis/script create mode 100644 tests/kernelBuilder.php diff --git a/.gitignore b/.gitignore index 7c9f4c84..0139f99d 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,12 @@ Vagrantfile .vagrant php-cgi.core .sass-cache + +# codeception (only stage *.dist.yml config files) +/codeception.yml +/tests/codeception.yml +/tests/*.suite.yml +/tests/_output/* +/tests/_data/* +!/tests/_data/.gitkeep +/tests/_support/_generated/* \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..66ff6723 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,59 @@ +sudo: required +language: php +addons: + chrome: stable + mariadb: '10.1' + +env: + global: + - PIMCORE_ENVIRONMENT=test + - DACHCOM_BUNDLE_TEST=1 + - PIMCORE_TEST_URL=http://localhost + - CHROME_DRIVER_VERSION=2.41 + - SELENIUM_VERSION=3.6.0 + - WEBDRIVER_HOST=localhost + - WEBDRIVER_URL="http://localhost:8080/" + - PIMCORE_TEST_DB_DSN="mysql://root@localhost/dachcom_bundle_test" + - SYMFONY_DEPRECATIONS_HELPER=weak +matrix: + include: + - sudo: required + php: 7.1 + env: + # pimcore 5.4.x + - PIMCORE_SKELETON_BRANCH="tags/v1.0.4" + - sudo: required + php: 7.2 + env: + - PIMCORE_SKELETON_BRANCH="tags/v1.0.4" + - sudo: required + php: 7.1 + env: + # pimcore 5.5.x + - PIMCORE_SKELETON_BRANCH="tags/v1.0.5" + - sudo: required + php: 7.2 + env: + - PIMCORE_SKELETON_BRANCH="tags/v1.0.5" + fast_finish: true + +cache: + directories: + - $HOME/.composer/cache + +install: +- tests/etc/travis/install + +after_failure: +- cd $TRAVIS_BUILD_DIR +- cat ./lib/Members/tests/_output/* + +script: +- '$HOME/chromedriver --url-base=/wd/hub &' +- 'php ${TRAVIS_BUILD_DIR}/bin/console server:start 127.0.0.1:8080' +- 'php ${TRAVIS_BUILD_DIR}/bin/console server:status' +- etc/travis/script + +notifications: + email: + - shagspiel@dachcom.ch \ No newline at end of file diff --git a/codeception.dist.yml b/codeception.dist.yml new file mode 100644 index 00000000..ff60cbf4 --- /dev/null +++ b/codeception.dist.yml @@ -0,0 +1,7 @@ +settings: + memory_limit: -1 + colors: true +paths: + log: var/logs +include: + - tests diff --git a/src/MembersBundle/Configuration/Configuration.php b/src/MembersBundle/Configuration/Configuration.php index a73e1122..6e544dee 100644 --- a/src/MembersBundle/Configuration/Configuration.php +++ b/src/MembersBundle/Configuration/Configuration.php @@ -37,14 +37,6 @@ public function setConfig($config = []) $this->config = $config; } - /** - * @return array - */ - public function getConfigNode() - { - return $this->config; - } - /** * @return mixed */ @@ -63,6 +55,12 @@ public function getConfig($slot) return $this->config[$slot]; } + /** + * @param string $slot + * @param null $locale + * + * @return mixed + */ public function getLocalizedPath($slot, $locale = null) { $data = $this->getConfig($slot); diff --git a/tests/_data/.gitkeep b/tests/_data/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tests/_envs/local.yml b/tests/_envs/local.yml new file mode 100644 index 00000000..e69de29b diff --git a/tests/_envs/travis.yml b/tests/_envs/travis.yml new file mode 100644 index 00000000..9d8c54ce --- /dev/null +++ b/tests/_envs/travis.yml @@ -0,0 +1,10 @@ +modules: + config: + \DachcomBundle\Test\Helper\Browser\WebDriver: + browser: chrome + port: 9515 + capabilities: + chromeOptions: + args: ['--headless', '--disable-gpu', '--no-sandbox', '--window-size=1024,768'] + prefs: + download.default_directory: '%TRAVIS_BUILD_DIR%/lib/Members/tests/_data/downloads' \ No newline at end of file diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php new file mode 100644 index 00000000..ed1e3330 --- /dev/null +++ b/tests/_support/AcceptanceTester.php @@ -0,0 +1,13 @@ +load($bundleClass . '/etc/config/bundle/symfony/' . $configName); + } + } + + /** + * {@inheritdoc} + */ + public function registerBundlesToCollection(\Pimcore\HttpKernel\BundleCollection\BundleCollection $collection) + { + if (class_exists('\\AppBundle\\AppBundle')) { + $collection->addBundle(new \AppBundle\AppBundle()); + } + + $collection->addBundle(new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle()); + + $bundleClass = getenv('DACHCOM_BUNDLE_CLASS'); + $collection->addBundle(new $bundleClass()); + } + + /** + * @param ContainerBuilder $container + */ + protected function build(ContainerBuilder $container) + { + $container->addCompilerPass(new \DachcomBundle\Test\DependencyInjection\MakeServicesPublicPass(), + \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, -100000); + $container->addCompilerPass(new \DachcomBundle\Test\DependencyInjection\MonologChannelLoggerPass(), + \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 1); + } + + /** + * {@inheritdoc} + */ + public function boot() + { + parent::boot(); + \Pimcore::setKernel($this); + } +} diff --git a/tests/_support/DependencyInjection/MakeServicesPublicPass.php b/tests/_support/DependencyInjection/MakeServicesPublicPass.php new file mode 100644 index 00000000..13736db2 --- /dev/null +++ b/tests/_support/DependencyInjection/MakeServicesPublicPass.php @@ -0,0 +1,30 @@ +getServiceIds(), function (string $id) use ($prefix) { + return strpos($id, $prefix) === 0; + }); + + foreach ($serviceIds as $serviceId) { + if ($container->hasAlias($serviceId)) { + $container->getAlias($serviceId)->setPublic(true); + } + + $container + ->findDefinition($serviceId) + ->setPublic(true); + } + } +} diff --git a/tests/_support/DependencyInjection/MonologChannelLoggerPass.php b/tests/_support/DependencyInjection/MonologChannelLoggerPass.php new file mode 100644 index 00000000..91f88757 --- /dev/null +++ b/tests/_support/DependencyInjection/MonologChannelLoggerPass.php @@ -0,0 +1,27 @@ +getParameter('monolog.handlers_to_channels'); + foreach ($channelsToHide as $channelToHide) { + $monologHandlers['monolog.handler.console']['elements'][] = $channelToHide; + } + + $container->setParameter('monolog.handlers_to_channels', $monologHandlers); + } +} diff --git a/tests/_support/FunctionalTester.php b/tests/_support/FunctionalTester.php new file mode 100644 index 00000000..862e9c1d --- /dev/null +++ b/tests/_support/FunctionalTester.php @@ -0,0 +1,13 @@ + 'PhpBrowser needs the pimcore core framework to work.' + ]; + } + + /** + * @param PimcoreCore $pimcoreCore + */ + public function _inject($pimcoreCore) + { + $this->pimcoreCore = $pimcoreCore; + } + + /** + * @inheritDoc + */ + public function _initialize() + { + $this->sessionSnapShot = []; + + parent::_initialize(); + } + + /** + * Actor Function to see a page with enabled edit-mode + * + * @param string $page + */ + public function amOnPageInEditMode(string $page) + { + $this->pimcoreCore->amOnPage(sprintf('%s?pimcore_editmode=true', $page)); + } + + /** + * @param string $name + * @param string $type + * @param array $options + * @param null $data + * @param null $selector + */ + public function seeAEditableConfiguration(string $name, string $type, array $options, $data = null, $selector = null) + { + $this->pimcoreCore->see(MembersHelper::generateEditableConfiguration($name, $type, $options, $data), $selector); + } + + /** + * Actor Function to see if given email has been with specified address + * Only works with PhpBrowser (Symfony Client) + * + * @param string $recipient + * @param Email $email + */ + public function seeEmailIsSentTo(string $recipient, Email $email) + { + $collectedMessages = $this->getCollectedEmails($email); + + $recipients = []; + foreach ($collectedMessages as $message) { + if ($email->getSubject() !== $message->getSubject()) { + continue; + } + $recipients = array_merge($recipients, $message->getTo()); + } + + $this->assertContains($recipient, array_keys($recipients)); + + } + + /** + * Actor Function to see if given email has been sent + * + * @param Email $email + * @param string $property + * @param string $value + */ + public function seeSentEmailHasPropertyValue(Email $email, string $property, string $value) + { + $collectedMessages = $this->getCollectedEmails($email); + + $getter = 'get' . ucfirst($property); + foreach ($collectedMessages as $message) { + $getterData = $message->$getter(); + if (is_array($getterData)) { + $this->assertContains($value, array_keys($getterData)); + } else { + $this->assertEquals($value, $getterData); + } + } + } + + /** + * Actor Function to login into Pimcore Backend + * + * @param $username + */ + public function amLoggedInAs($username) + { + $firewallName = 'admin'; + + try { + /** @var PimcoreUser $userModule */ + $userModule = $this->getModule('\\' . PimcoreUser::class); + } catch (ModuleException $pimcoreModule) { + $this->debug('[PIMCORE BUNDLE MODULE] could not load pimcore user module'); + return; + } + + $pimcoreUser = $userModule->getUser($username); + + if (!$pimcoreUser instanceof User) { + $this->debug(sprintf('[PIMCORE BUNDLE MODULE] could not fetch user %s.', $username)); + return; + } + + /** @var Session $session */ + $session = $this->pimcoreCore->getContainer()->get('session'); + + $user = new \Pimcore\Bundle\AdminBundle\Security\User\User($pimcoreUser); + $token = new UsernamePasswordToken($user, null, $firewallName, $pimcoreUser->getRoles()); + $this->pimcoreCore->getContainer()->get('security.token_storage')->setToken($token); + + \Pimcore\Tool\Session::useSession(function (AttributeBagInterface $adminSession) use ($pimcoreUser, $session) { + $session->setId(\Pimcore\Tool\Session::getSessionId()); + $adminSession->set('user', $pimcoreUser); + $adminSession->set('csrfToken', self::PIMCORE_ADMIN_CSRF_TOKEN_NAME); + }); + + // allow re-usage of session in same cest. + if (!empty($this->sessionSnapShot)) { + $cookie = $this->sessionSnapShot; + } else { + $cookie = new Cookie($session->getName(), $session->getId()); + $this->sessionSnapShot = $cookie; + } + + $this->pimcoreCore->client->getCookieJar()->clear(); + $this->pimcoreCore->client->getCookieJar()->set($cookie); + + } + + /** + * Actor Function to send tokenized ajax request in backend + * + * @param string $url + * @param array $params + */ + public function sendTokenAjaxPostRequest(string $url, array $params = []) + { + $params['csrfToken'] = self::PIMCORE_ADMIN_CSRF_TOKEN_NAME; + $this->pimcoreCore->sendAjaxPostRequest($url, $params); + } + + /** + * @param Email $email + * + * @return array + */ + protected function getCollectedEmails(Email $email) + { + $this->assertInstanceOf(Email::class, $email); + + /** @var Profiler $profiler */ + $profiler = $this->pimcoreCore->_getContainer()->get('profiler'); + + $tokens = $profiler->find('', '', 1, 'POST', '', ''); + if (count($tokens) === 0) { + throw new \RuntimeException('No profile found. Is the profiler data collector enabled?'); + } + + $token = $tokens[0]['token']; + /** @var \Symfony\Component\HttpKernel\Profiler\Profile $profile */ + $profile = $profiler->loadProfile($token); + + if (!$profile instanceof Profile) { + throw new \RuntimeException(sprintf('Profile with token "%s" not found.', $token)); + } + + /** @var MessageDataCollector $mailCollector */ + $mailCollector = $profile->getCollector('swiftmailer'); + + $this->assertGreaterThan(0, $mailCollector->getMessageCount()); + + $collectedMessages = $mailCollector->getMessages(); + + $emails = []; + /** @var \Pimcore\Mail $message */ + foreach ($collectedMessages as $message) { + if ($email->getProperty('test_identifier') !== $message->getDocument()->getProperty('test_identifier')) { + continue; + } + $emails[] = $message; + } + + return $emails; + + } +} diff --git a/tests/_support/Helper/Browser/WebDriver.php b/tests/_support/Helper/Browser/WebDriver.php new file mode 100644 index 00000000..de969453 --- /dev/null +++ b/tests/_support/Helper/Browser/WebDriver.php @@ -0,0 +1,62 @@ +amOnPage(sprintf('%s?pimcore_editmode=true', $page)); + } + + /** + * @param null $path + */ + public function setDownloadPathForWebDriver($path = null) + { + if (is_null($path)) { + $path = FileGeneratorHelper::getDownloadPath(); + } + + $url = $this->webDriver->getCommandExecutor()->getAddressOfRemoteServer(); + $uri = '/session/' . $this->webDriver->getSessionID() . '/chromium/send_command'; + $body = [ + 'cmd' => 'Page.setDownloadBehavior', + 'params' => ['behavior' => 'allow', 'downloadPath' => $path] + ]; + + $client = new \GuzzleHttp\Client(); + $response = $client->post($url . $uri, ['body' => json_encode($body)]); + + try { + $responseData = json_decode($response->getBody()->getContents(), true); + } catch (\Exception $e) { + $responseData = []; + } + + $this->assertArrayHasKey('status', $responseData); + $this->assertEquals(0, $responseData['status']); + + } + + /** + * @param string $name + * @param string $type + * @param array $options + * @param null $data + * @param null $selector + */ + public function seeAEditableConfiguration(string $name, string $type, array $options, $data = null, $selector = null) + { + $this->see(MembersHelper::generateEditableConfiguration($name, $type, $options, $data), $selector); + } +} diff --git a/tests/_support/Helper/PimcoreAdminJson.php b/tests/_support/Helper/PimcoreAdminJson.php new file mode 100644 index 00000000..6962e92e --- /dev/null +++ b/tests/_support/Helper/PimcoreAdminJson.php @@ -0,0 +1,58 @@ + 'PimcoreAdminJson needs a valid browser to work.']; + } + + /** + * @param InnerBrowser $connection + */ + public function _inject(InnerBrowser $connection) + { + $this->connectionModule = $connection; + } + + public function seeResponseContainsJson($json = []) + { + \PHPUnit_Framework_Assert::assertThat( + $this->connectionModule->_getResponseContent(), + new JsonContains($json) + ); + } + + public function seeResponseIsJson() + { + $responseContent = $this->connectionModule->_getResponseContent(); + \PHPUnit_Framework_Assert::assertNotEquals('', $responseContent, 'response is empty'); + json_decode($responseContent); + $errorCode = json_last_error(); + $errorMessage = json_last_error_msg(); + \PHPUnit_Framework_Assert::assertEquals( + JSON_ERROR_NONE, + $errorCode, + sprintf( + "Invalid json: %s. System message: %s.", + $responseContent, + $errorMessage + ) + ); + } +} diff --git a/tests/_support/Helper/PimcoreBackend.php b/tests/_support/Helper/PimcoreBackend.php new file mode 100644 index 00000000..57e9bb67 --- /dev/null +++ b/tests/_support/Helper/PimcoreBackend.php @@ -0,0 +1,514 @@ +setParentId(1); + $folder->setKey('members'); + $folder->setLocked(true); + $folder->save(); + } catch (\Exception $e) { + \Codeception\Util\Debug::debug( + sprintf('[MEMBERS ERROR] error while re-creating members object folder. message was: ' . $e->getMessage()) + ); + } + + FileGeneratorHelper::cleanUp(); + + parent::_after($test); + } + + /** + * Actor Function to create a Page Document + * + * @param string $documentKey + * @param null|string $action + * @param null|string $controller + * @param null|string $locale + * + * @return Page + */ + public function haveAPageDocument( + $documentKey = 'members-test', + $action = null, + $controller = null, + $locale = 'en' + ) { + $document = $this->generatePageDocument($documentKey, $action, $controller, $locale); + + try { + $document->save(); + } catch (\Exception $e) { + \Codeception\Util\Debug::debug(sprintf('[MEMBERS ERROR] error while saving document page. message was: ' . $e->getMessage())); + } + + $this->assertInstanceOf(Page::class, Page::getById($document->getId())); + + return $document; + } + + /** + * Actor Function to create a Snippet + * + * @param string $snippetKey + * @param array $elements + * @param string $locale + * + * @return null|Snippet + */ + public function haveASnippetDocument($snippetKey, $elements = [], $locale = 'en') + { + $snippet = $this->generateSnippetDocument($snippetKey, $elements, $locale); + + try { + $snippet->save(); + } catch (\Exception $e) { + \Codeception\Util\Debug::debug(sprintf('[MEMBERS ERROR] error while saving document snippet. message was: ' . $e->getMessage())); + } + + $this->assertInstanceOf(Snippet::class, $snippet); + + return $snippet; + } + + /** + * Actor Function to create a mail document for given type + * + * @param $type + * @param array $mailParams + * @param string $locale + * + * @return Email + */ + public function haveAEmailDocumentForType($type, array $mailParams = [], $locale = 'en') + { + $emailDocument = $mailTemplate = $this->generateEmailDocument(sprintf('email-%s', $type), $mailParams, $locale); + $this->assertInstanceOf(Email::class, $emailDocument); + + return $emailDocument; + } + + /** + * @param $fileName + * @param int $fileSizeInMb Mb + */ + public function haveFile($fileName, $fileSizeInMb = 1) + { + FileGeneratorHelper::generateDummyFile($fileName, $fileSizeInMb); + } + + /** + * @param $fileName + */ + public function seeDownload($fileName) + { + $supportDir = FileGeneratorHelper::getDownloadPath(); + $filePath = $supportDir . $fileName; + + $this->assertTrue(is_file($filePath)); + } + + /** + * Actor Function to place a members area on a document + * + * @param Page $document + */ + public function seeAMembersAreaElementPlacedOnDocument(Page $document) + { + $document->setElements($this->createMembersArea()); + + try { + $document->save(); + } catch (\Exception $e) { + \Codeception\Util\Debug::debug(sprintf('[MEMBERS ERROR] error while saving document. message was: ' . $e->getMessage())); + } + + $this->assertCount(6, $document->getElements()); + } + + /** + * Actor Function to see if given email has been sent + * + * @param Email $email + */ + public function seeEmailIsSent(Email $email) + { + $this->assertInstanceOf(Email::class, $email); + + $foundEmails = $this->getEmailsFromDocumentIds([$email->getId()]); + $this->assertEquals(1, count($foundEmails)); + } + + /** + * Actor Function to see if an email has been sent to admin + * + * @param Email $email + */ + public function seeEmailIsNotSent(Email $email) + { + $this->assertInstanceOf(Email::class, $email); + + $foundEmails = $this->getEmailsFromDocumentIds([$email->getId()]); + $this->assertEquals(0, count($foundEmails)); + } + + /** + * Actor Function to see if admin email contains given properties + * + * @param Email $mail + * @param array $properties + */ + public function seePropertiesInEmail(Email $mail, array $properties) + { + $this->assertInstanceOf(Email::class, $mail); + + $foundEmails = $this->getEmailsFromDocumentIds([$mail->getId()]); + $this->assertGreaterThan(0, count($foundEmails)); + + $serializer = $this->getSerializer(); + + foreach ($foundEmails as $email) { + $params = $serializer->decode($email->getParams(), 'json', ['json_decode_associative' => true]); + foreach ($properties as $propertyKey => $propertyValue) { + $key = array_search($propertyKey, array_column($params, 'key')); + if ($key === false) { + $this->fail(sprintf('Failed asserting that mail params array has the key "%s".', $propertyKey)); + } + + $data = $params[$key]; + $this->assertEquals($propertyValue, $data['data']['value']); + } + } + } + + /** + * Actor Function to see if admin email contains given properties + * + * @param Email $mail + * @param array $properties + */ + public function seePropertyKeysInEmail(Email $mail, array $properties) + { + $this->assertInstanceOf(Email::class, $mail); + + $foundEmails = $this->getEmailsFromDocumentIds([$mail->getId()]); + $this->assertGreaterThan(0, count($foundEmails)); + + $serializer = $this->getSerializer(); + + foreach ($foundEmails as $email) { + $params = $serializer->decode($email->getParams(), 'json', ['json_decode_associative' => true]); + foreach ($properties as $propertyKey) { + $key = array_search($propertyKey, array_column($params, 'key')); + $this->assertNotSame(false, $key); + } + } + } + + /** + * Actor Function to see if admin email not contains given properties + * + * @param Email $mail + * @param array $properties + */ + public function cantSeePropertyKeysInEmail(Email $mail, array $properties) + { + $this->assertInstanceOf(Email::class, $mail); + + $foundEmails = $this->getEmailsFromDocumentIds([$mail->getId()]); + $this->assertGreaterThan(0, count($foundEmails)); + + $serializer = $this->getSerializer(); + + foreach ($foundEmails as $email) { + $params = $serializer->decode($email->getParams(), 'json', ['json_decode_associative' => true]); + foreach ($properties as $propertyKey) { + $this->assertFalse( + array_search( + $propertyKey, + array_column($params, 'key')), + sprintf('Failed asserting that search for "%s" is false.', $propertyKey) + ); + } + } + } + + /** + * @param Email $mail + * @param string $string + */ + public function seeInRenderedEmailBody(Email $mail, string $string) + { + $this->assertInstanceOf(Email::class, $mail); + + $foundEmails = $this->getEmailsFromDocumentIds([$mail->getId()]); + $this->assertGreaterThan(0, count($foundEmails)); + + $serializer = $this->getSerializer(); + + foreach ($foundEmails as $email) { + $params = $serializer->decode($email->getParams(), 'json', ['json_decode_associative' => true]); + + $bodyKey = array_search('body', array_column($params, 'key')); + $this->assertNotSame(false, $bodyKey); + + $data = $params[$bodyKey]; + $this->assertContains($string, $data['data']['value']); + } + } + + /** + * Actor Function to see if a key has been stored in admin translations + * + * @param string $key + * + */ + public function seeKeyInFrontendTranslations(string $key) + { + /** @var Translator $translator */ + $translator = \Pimcore::getContainer()->get('pimcore.translator'); + $this->assertTrue($translator->getCatalogue()->has($key)); + } + + /** + * @param array $documentIds + * + * @return Log[] + */ + protected function getEmailsFromDocumentIds(array $documentIds) + { + $emailLogs = new Log\Listing(); + $emailLogs->addConditionParam(sprintf('documentId IN (%s)', implode(',', $documentIds))); + + return $emailLogs->load(); + } + + /** + * API Function to create a Snippet + * + * @param $snippetKey + * @param array $elements + * @param string $locale + * + * @return null|Snippet + */ + protected function generateSnippetDocument($snippetKey, $elements = [], $locale = 'en') + { + $document = new Snippet(); + $document->setController('default'); + $document->setAction('snippet'); + $document->setType('snippet'); + $document->setElements($elements); + $document->setParentId(1); + $document->setUserOwner(1); + $document->setUserModification(1); + $document->setCreationDate(time()); + $document->setKey($snippetKey); + $document->setProperty('language', 'text', $locale, false, 1); + $document->setPublished(true); + + return $document; + + } + + /** + * @param string $key + * @param null|string $action + * @param null|string $controller + * @param string $locale + * + * @return Page + */ + protected function generatePageDocument($key = 'members-test', $action = null, $controller = null, $locale = 'en') + { + $action = is_null($action) ? 'default' : $action; + $controller = is_null($controller) ? '@AppBundle\Controller\DefaultController' : $controller; + + $document = TestHelper::createEmptyDocumentPage('', false); + $document->setController($controller); + $document->setAction($action); + $document->setKey($key); + $document->setProperty('language', 'text', $locale, false, 1); + + return $document; + } + + /** + * @param string $key + * @param array $params + * + * @return null|Email + */ + protected function generateEmailDocument($key = 'members-test-email', array $params = []) + { + $documentKey = uniqid(sprintf('%s-', $key)); + + $document = new Email(); + $document->setType('email'); + $document->setParentId(1); + $document->setUserOwner(1); + $document->setUserModification(1); + $document->setCreationDate(time()); + $document->setModule('MembersBundle'); + $document->setController('Email'); + $document->setAction('email'); + $document->setKey($documentKey); + + $to = 'recpient@test.org'; + if (isset($params['to'])) { + $to = $params['to']; + } + + $subject = sprintf('MEMBERS EMAIL %s', $documentKey); + if (isset($params['subject'])) { + $subject = $params['subject']; + } + + $document->setTo($to); + $document->setSubject($subject); + + if (isset($params['replyTo'])) { + $document->setReplyTo($params['replyTo']); + } + + if (isset($params['cc'])) { + $document->setCc($params['cc']); + } + + if (isset($params['bcc'])) { + $document->setBcc($params['bcc']); + } + + if (isset($params['from'])) { + $document->setFrom($params['from']); + } + + if (isset($params['properties'])) { + $document->setProperties($params['properties']); + } + + try { + $document->save(); + } catch (\Exception $e) { + \Codeception\Util\Debug::debug(sprintf('[MEMBERS ERROR] error while creating email. message was: ' . $e->getMessage())); + return null; + } + + return $document; + } + + /** + * @return array + */ + protected function createMembersArea() + { + $blockArea = new Areablock(); + $blockArea->setName(MembersHelper::AREA_TEST_NAMESPACE); + + $redirectAfterSuccess = new Href(); + $redirectAfterSuccess->setName(sprintf('%s:1.redirectAfterSuccess', MembersHelper::AREA_TEST_NAMESPACE)); + + $data = [ + 'id' => 1, + 'type' => 'document', + 'subtype' => 'page' + ]; + + $redirectAfterSuccess->setDataFromEditmode($data); + + $hideWhenLoggedIn = new Checkbox(); + $hideWhenLoggedIn->setName(sprintf('%s:1.hideWhenLoggedIn', MembersHelper::AREA_TEST_NAMESPACE)); + $hideWhenLoggedIn->setDataFromEditmode(true); + + $showSnippedWhenLoggedIn = new Href(); + $showSnippedWhenLoggedIn->setName(sprintf('%s:1.showSnippedWhenLoggedIn', MembersHelper::AREA_TEST_NAMESPACE)); + + $data2 = [ + 'id' => 1, + 'type' => 'document', + 'subtype' => 'snippet' + ]; + + $showSnippedWhenLoggedIn->setDataFromEditmode($data2); + + $blockArea->setDataFromEditmode([ + [ + 'key' => '1', + 'type' => 'members_login', + 'hidden' => false + ] + ]); + + return [ + sprintf('%s', MembersHelper::AREA_TEST_NAMESPACE) => $blockArea, + sprintf('%s:1.redirectAfterSuccess', MembersHelper::AREA_TEST_NAMESPACE) => $redirectAfterSuccess, + sprintf('%s:1.hideWhenLoggedIn', MembersHelper::AREA_TEST_NAMESPACE) => $hideWhenLoggedIn, + sprintf('%s:1.showSnippedWhenLoggedIn', MembersHelper::AREA_TEST_NAMESPACE) => $showSnippedWhenLoggedIn, + ]; + + } + + /** + * @return Container + * @throws \Codeception\Exception\ModuleException + */ + protected function getContainer() + { + return $this->getModule('\\' . PimcoreCore::class)->getContainer(); + } + + /** + * @return Serializer + */ + protected function getSerializer() + { + $serializer = null; + + try { + $serializer = $this->getContainer()->get('pimcore_admin.serializer'); + } catch (\Exception $e) { + \Codeception\Util\Debug::debug(sprintf('[MEMBERS ERROR] error while getting pimcore admin serializer. message was: ' . $e->getMessage())); + } + + $this->assertInstanceOf(Serializer::class, $serializer); + + return $serializer; + } +} diff --git a/tests/_support/Helper/PimcoreBundleCore.php b/tests/_support/Helper/PimcoreBundleCore.php new file mode 100644 index 00000000..461cb380 --- /dev/null +++ b/tests/_support/Helper/PimcoreBundleCore.php @@ -0,0 +1,63 @@ +config = array_merge($this->config, [ + 'run_installer' => false + ]); + + parent::__construct($moduleContainer, $config); + } + + /** + * @param array $settings + * + * @throws \Codeception\Exception\ModuleException + */ + public function _beforeSuite($settings = []) + { + parent::_beforeSuite($settings); + + if ($this->config['run_installer'] === true) { + $this->installBundle($settings); + } + } + + /** + * @param $settings + * + * @throws \Codeception\Exception\ModuleException + */ + private function installBundle($settings) + { + /** @var PimcoreCore $pimcoreModule */ + $pimcoreModule = $this->getModule('\\' . PimcoreCore::class); + + $bundleName = getenv('DACHCOM_BUNDLE_NAME'); + $installerClass = getenv('DACHCOM_BUNDLE_INSTALLER_CLASS'); + + if ($installerClass === false) { + return; + } + + $this->debug(sprintf('[%s] Running installer...', strtoupper($bundleName))); + + if ($pimcoreModule->_getContainer()) { + $pimcoreModule->getKernel()->reboot($pimcoreModule->getKernel()->getCacheDir()); + } + + // install dachcom bundle + $installer = $pimcoreModule->getContainer()->get($installerClass); + $installer->install(); + } +} diff --git a/tests/_support/Helper/PimcoreCore.php b/tests/_support/Helper/PimcoreCore.php new file mode 100644 index 00000000..fe30107b --- /dev/null +++ b/tests/_support/Helper/PimcoreCore.php @@ -0,0 +1,163 @@ +config = array_merge($this->config, [ + // set specific configuration file for suite + 'configuration_file' => null + ]); + + parent::__construct($moduleContainer, $config); + } + + /** + * @inheritDoc + */ + public function _after(\Codeception\TestInterface $test) + { + parent::_after($test); + + // config has changed, we need to restore default config before starting a new test! + if ($this->kernelHasCustomConfig === true) { + $this->clearCache(); + $this->bootKernelWithConfiguration(null); + $this->kernelHasCustomConfig = false; + } + } + + /** + * @inheritdoc + */ + public function _afterSuite() + { + $this->clearCache(); + parent::_afterSuite(); + } + + /** + * @inheritdoc + */ + public function _initialize() + { + $this->setPimcoreEnvironment($this->config['environment']); + $this->initializeKernel(); + $this->setupDbConnection(); + $this->setPimcoreCacheAvailability('disabled'); + } + + /** + * @inheritdoc + */ + protected function initializeKernel() + { + $maxNestingLevel = 200; // Symfony may have very long nesting level + $xdebugMaxLevelKey = 'xdebug.max_nesting_level'; + if (ini_get($xdebugMaxLevelKey) < $maxNestingLevel) { + ini_set($xdebugMaxLevelKey, $maxNestingLevel); + } + + $configFile = null; + if ($this->config['configuration_file'] !== null) { + $configFile = $this->config['configuration_file']; + } + + $this->bootKernelWithConfiguration($configFile); + $this->setupPimcoreDirectories(); + } + + /** + * @param $configuration + */ + protected function bootKernelWithConfiguration($configuration) + { + if ($configuration === null) { + $configuration = 'config_default.yml'; + } + + putenv('DACHCOM_BUNDLE_CONFIG_FILE=' . $configuration); + + $this->kernel = require __DIR__ . '/../../kernelBuilder.php'; + $this->getKernel()->boot(); + + $this->client = new SymfonyConnector($this->kernel, $this->persistentServices, $this->config['rebootable_client']); + + if ($this->config['cache_router'] === true) { + $this->persistService('router', true); + } + + // dispatch kernel booted event - will be used from services which need to reset state between tests + $this->kernel->getContainer()->get('event_dispatcher')->dispatch(TestEvents::KERNEL_BOOTED); + } + + /** + * @param bool $force + */ + protected function clearCache($force = true) + { + $fileSystem = new Filesystem(); + + try { + $fileSystem->remove(PIMCORE_PROJECT_ROOT . '/var/cache'); + $fileSystem->mkdir(PIMCORE_PROJECT_ROOT . '/var/cache'); + } catch (\Exception $e) { + //try again later if "directory not empty" error occurs. + if ($force === true) { + sleep(1); + $this->clearCache(false); + } + } + } + + /** + * @param $env + */ + protected function setPimcoreEnvironment($env) + { + Config::setEnvironment($env); + } + + /** + * @param string $state + */ + protected function setPimcoreCacheAvailability($state = 'disabled') + { + if ($state === 'disabled') { + Cache::disable(); + } else { + Cache::enable(); + } + } + + /** + * Actor Function to boot symfony with a specific bundle configuration + * + * @param string $configuration + */ + public function haveABootedSymfonyConfiguration(string $configuration) + { + $this->kernelHasCustomConfig = true; + $this->clearCache(); + $this->bootKernelWithConfiguration($configuration); + } +} + diff --git a/tests/_support/Helper/PimcoreUser.php b/tests/_support/Helper/PimcoreUser.php new file mode 100644 index 00000000..888942d0 --- /dev/null +++ b/tests/_support/Helper/PimcoreUser.php @@ -0,0 +1,125 @@ +createUser($username, false); + $this->assertInstanceOf(User::class, $user); + + return $user; + } + + /** + * Actor Function to create a Admin User + * + * @param $username + * + * @return User + */ + public function haveAUserWithAdminRights($username) + { + $user = $this->createUser($username, true); + $this->assertInstanceOf(User::class, $user); + + return $user; + } + + /** + * API Function to get a User + * + * @param string $username + * + * @return User + */ + public function getUser($username) + { + if (isset($this->users[$username])) { + return $this->users[$username]; + } + + throw new \InvalidArgumentException(sprintf('User %s does not exist', $username)); + } + + /** + * API Function to create a User + * + * @param string $username + * @param bool $admin + * + * @return null|User|User\AbstractUser + */ + protected function createUser($username, $admin = true) + { + if (!TestHelper::supportsDbTests()) { + $this->debug(sprintf('[PIMCORE USER MODULE] Not initializing user %s as DB is not connected', $username)); + return null; + } else { + $this->debug(sprintf('[PIMCORE USER MODULE] Initializing user %s', $username)); + } + + $password = $username; + + $user = null; + + try { + $user = User::getByName($username); + } catch (\Exception $e) { + // fail silently + } + + if ($user instanceof User) { + return $user; + } + + $this->debug(sprintf('[PIMCORE USER MODULE] Creating user %s', $username)); + + $pass = null; + + try { + $pass = Authentication::getPasswordHash($username, $password); + } catch (\Exception $e) { + // fail silently. + } + + $user = User::create([ + 'parentId' => 0, + 'username' => $username, + 'password' => $pass, + 'active' => true, + 'admin' => $admin + ]); + + $this->users[$user->getName()] = $user; + + return $user; + } +} diff --git a/tests/_support/Helper/Unit.php b/tests/_support/Helper/Unit.php new file mode 100644 index 00000000..c698ec26 --- /dev/null +++ b/tests/_support/Helper/Unit.php @@ -0,0 +1,16 @@ +getPimcoreBundle()->getContainer(); + } + + /** + * @return PimcoreCore + * @throws \Codeception\Exception\ModuleException + */ + protected function getPimcoreBundle() + { + return $this->getModule('\\' . PimcoreCore::class); + } +} diff --git a/tests/_support/UnitTester.php b/tests/_support/UnitTester.php new file mode 100644 index 00000000..def75bda --- /dev/null +++ b/tests/_support/UnitTester.php @@ -0,0 +1,13 @@ +exists($dataDir . 'generated')) { + $fs->mkdir($dataDir . 'generated'); + } + + if (!$fs->exists($dataDir . 'downloads')) { + $fs->mkdir($dataDir . 'downloads'); + } + } + + /** + * @return string + */ + public static function getStoragePath() + { + $dataDir = codecept_data_dir() . 'generated' . DIRECTORY_SEPARATOR; + return $dataDir; + } + + /** + * @return string + */ + public static function getDownloadPath() + { + $dataDir = codecept_data_dir() . 'downloads' . DIRECTORY_SEPARATOR; + return $dataDir; + } + + public static function cleanUp() + { + $finder = new Finder(); + $fs = new Filesystem(); + + $dataDir = self::getStoragePath(); + if ($fs->exists($dataDir)) { + $fs->remove($finder->ignoreDotFiles(true)->in($dataDir)); + } + + $downloadDir = self::getDownloadPath(); + if ($fs->exists($downloadDir)) { + $fs->remove($finder->ignoreDotFiles(true)->in($downloadDir)); + } + } +} diff --git a/tests/_support/Util/MembersHelper.php b/tests/_support/Util/MembersHelper.php new file mode 100644 index 00000000..7ae8de55 --- /dev/null +++ b/tests/_support/Util/MembersHelper.php @@ -0,0 +1,37 @@ + sprintf('pimcore_editable_%s%s1%s%s', self::AREA_TEST_NAMESPACE, $colonSuffix, $dotSuffix, $name), + 'name' => sprintf('%s:1.%s', self::AREA_TEST_NAMESPACE, $name), + 'realName' => $name, + 'options' => $options, + 'data' => $data, + 'type' => $type, + 'inherited' => false, + ]; + + $data = sprintf('editableConfigurations.push(%s);', json_encode($editableConfig, ($prettyJson ? JSON_PRETTY_PRINT : JSON_ERROR_NONE))); + + return $data; + } +} diff --git a/tests/_support/Util/VersionHelper.php b/tests/_support/Util/VersionHelper.php new file mode 100644 index 00000000..0af2ebac --- /dev/null +++ b/tests/_support/Util/VersionHelper.php @@ -0,0 +1,64 @@ +'); + } + + /** + * @param string $version + * + * @return mixed + */ + public static function pimcoreVersionIsGreaterOrEqualThan(string $version) + { + return version_compare(self::getPimcoreVersion(), $version, '>='); + } + + /** + * @param string $version + * + * @return mixed + */ + public static function pimcoreVersionIsLowerThan(string $version) + { + return version_compare(self::getPimcoreVersion(), $version, '<'); + } + + /** + * @param string $version + * + * @return mixed + */ + public static function pimcoreVersionIsLowerOrEqualThan(string $version) + { + return version_compare(self::getPimcoreVersion(), $version, '<='); + } + + /** + * @return string + */ + private static function getPimcoreVersion() + { + return preg_replace('/[^0-9.]/', '', \Pimcore\Version::getVersion()); + } +} diff --git a/tests/bundle_configuration b/tests/bundle_configuration new file mode 100755 index 00000000..f4001bbb --- /dev/null +++ b/tests/bundle_configuration @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +export DACHCOM_BUNDLE_HOME=$TRAVIS_BUILD_DIR +export DACHCOM_BUNDLE_NAME="Members" +export DACHCOM_BUNDLE_REPO_NAME="members" +export DACHCOM_BUNDLE_COMMIT=$TRAVIS_COMMIT +export DACHCOM_BUNDLE_BRANCH=$TRAVIS_BRANCH + +export DACHCOM_BUNDLE_CLASS='MembersBundle\MembersBundle' +export DACHCOM_BUNDLE_INSTALLER_CLASS='MembersBundle\Tool\Install' + +declare -A DACHCOM_INSTALL_CONFIG_FILES=( + # system files + ["$DACHCOM_BUNDLE_HOME/etc/config/bundle/extensions.template.php"]="var/config/extensions.php" + ["$DACHCOM_BUNDLE_HOME/etc/config/bundle/system.template.php"]="var/config/system.php" + ["$DACHCOM_BUNDLE_HOME/etc/config/bundle/appKernel"]="app/AppKernel.php" + # template files + ["$DACHCOM_BUNDLE_HOME/etc/config/bundle/template/controller/DefaultController"]="src/AppBundle/Controller/DefaultController.php" + ["$DACHCOM_BUNDLE_HOME/etc/config/bundle/template/views/default"]="app/Resources/views/Default/default.html.twig" + ["$DACHCOM_BUNDLE_HOME/etc/config/bundle/template/views/snippet"]="app/Resources/views/Default/snippet.html.twig" +) \ No newline at end of file diff --git a/tests/bundle_tests/_bootstrap.php b/tests/bundle_tests/_bootstrap.php new file mode 100644 index 00000000..b2e371bb --- /dev/null +++ b/tests/bundle_tests/_bootstrap.php @@ -0,0 +1,18 @@ +getContainer()->get(Configuration::class); + $adminConfig = $configuration->getConfigArray(); + + $this->assertInternalType('array', $adminConfig); + $this->assertArrayHasKey('send_admin_mail_after_register', $adminConfig); + } + + /** + * @throws \Codeception\Exception\ModuleException + */ + public function testConfigSlotGetter() + { + $configuration = $this->getContainer()->get(Configuration::class); + $configSlot = $configuration->getConfig('post_register_type'); + + $this->assertInternalType('string', $configSlot); + } +} diff --git a/tests/bundle_tests/unit/_bootstrap.php b/tests/bundle_tests/unit/_bootstrap.php new file mode 100644 index 00000000..8a885558 --- /dev/null +++ b/tests/bundle_tests/unit/_bootstrap.php @@ -0,0 +1,2 @@ +addBundle(new \AppBundle\AppBundle()); + } + + $collection->addBundle(new \Symfony\Bundle\WebServerBundle\WebServerBundle()); + } +} \ No newline at end of file diff --git a/tests/etc/config/bundle/extensions.template.php b/tests/etc/config/bundle/extensions.template.php new file mode 100644 index 00000000..376123be --- /dev/null +++ b/tests/etc/config/bundle/extensions.template.php @@ -0,0 +1,7 @@ + [ + "MembersBundle\\MembersBundle" => TRUE, + ] +]; diff --git a/tests/etc/config/bundle/symfony/config_default.yml b/tests/etc/config/bundle/symfony/config_default.yml new file mode 100755 index 00000000..e69de29b diff --git a/tests/etc/config/bundle/system.template.php b/tests/etc/config/bundle/system.template.php new file mode 100755 index 00000000..5c8d594f --- /dev/null +++ b/tests/etc/config/bundle/system.template.php @@ -0,0 +1,167 @@ + [ + "timezone" => "Europe/Berlin", + "path_variable" => "", + "domain" => "localhost", + "redirect_to_maindomain" => false, + "language" => "en", + "validLanguages" => "en,de", + "fallbackLanguages" => [ + "en" => "", + "de" => "" + ], + "defaultLanguage" => "", + "loginscreencustomimage" => "", + "disableusagestatistics" => false, + "debug" => true, + "debug_ip" => "", + "http_auth" => [ + "username" => "", + "password" => "" + ], + "debug_admin_translations" => false, + "devmode" => false, + "instanceIdentifier" => "", + "show_cookie_notice" => false + ], + "database" => [ + "adapter" => "Pdo_Mysql", + "params" => [ + "host" => "localhost", + "username" => "root", + "password" => "", + "dbname" => "dachcom_bundle_test", + "port" => "3306" + ] + ], + "documents" => [ + "versions" => [ + "days" => null, + "steps" => 10 + ], + "default_controller" => "Default", + "default_action" => "default", + "error_pages" => [ + "default" => "/error" + ], + "createredirectwhenmoved" => false, + "allowtrailingslash" => "no", + "generatepreview" => true + ], + "objects" => [ + "versions" => [ + "days" => null, + "steps" => 10 + ] + ], + "assets" => [ + "versions" => [ + "days" => null, + "steps" => 10 + ], + "icc_rgb_profile" => "", + "icc_cmyk_profile" => "", + "hide_edit_image" => false, + "disable_tree_preview" => false + ], + "services" => [ + "google" => [ + "client_id" => "", + "email" => "", + "simpleapikey" => "", + "browserapikey" => "" + ] + ], + "cache" => [ + "enabled" => false, + "lifetime" => null, + "excludePatterns" => "", + "excludeCookie" => "" + ], + "outputfilters" => [ + "less" => false, + "lesscpath" => "" + ], + "webservice" => [ + "enabled" => true + ], + "httpclient" => [ + "adapter" => "Zend_Http_Client_Adapter_Socket", + "proxy_host" => "", + "proxy_port" => "", + "proxy_user" => "", + "proxy_pass" => "" + ], + "email" => [ + "sender" => [ + "name" => "pimcore", + "email" => "pimcore@example.com" + ], + "return" => [ + "name" => "pimcore", + "email" => "pimcore@example.com" + ], + "method" => "mail", + "smtp" => [ + "host" => "", + "port" => "", + "ssl" => null, + "name" => "", + "auth" => [ + "method" => "login", + "username" => "", + "password" => "" + ] + ], + "debug" => [ + "emailaddresses" => "" + ], + "bounce" => [ + "type" => "", + "maildir" => "", + "mbox" => "", + "imap" => [ + "host" => "", + "port" => "", + "username" => "", + "password" => "", + "ssl" => false + ] + ] + ], + "newsletter" => [ + "sender" => [ + "name" => "", + "email" => "" + ], + "return" => [ + "name" => "", + "email" => "" + ], + "method" => null, + "smtp" => [ + "host" => "", + "port" => "", + "ssl" => "ssl", + "name" => "", + "auth" => [ + "method" => null, + "username" => "", + "password" => null + ] + ], + "debug" => null, + "usespecific" => true + ], + "applicationlog" => [ + "mail_notification" => [ + "send_log_summary" => false, + "filter_priority" => null, + "mail_receiver" => "" + ], + "archive_treshold" => "30", + "archive_alternative_database" => "" + ] +]; diff --git a/tests/etc/config/bundle/template/controller/DefaultController b/tests/etc/config/bundle/template/controller/DefaultController new file mode 100644 index 00000000..7171050e --- /dev/null +++ b/tests/etc/config/bundle/template/controller/DefaultController @@ -0,0 +1,23 @@ +setViewAutoRender($event->getRequest(), true, 'twig'); + } + + public function defaultAction(Request $request) + { + } + + public function snippetAction(Request $request) + { + } +} diff --git a/tests/etc/config/bundle/template/views/default b/tests/etc/config/bundle/template/views/default new file mode 100644 index 00000000..c5cee92e --- /dev/null +++ b/tests/etc/config/bundle/template/views/default @@ -0,0 +1,14 @@ + + + + + Test Page for Members + + +
+ {% block content %} + {{ pimcore_areablock('dachcomBundleTest') }} + {% endblock %} +
+ + diff --git a/tests/etc/config/bundle/template/views/snippet b/tests/etc/config/bundle/template/views/snippet new file mode 100644 index 00000000..7c7fffe9 --- /dev/null +++ b/tests/etc/config/bundle/template/views/snippet @@ -0,0 +1,6 @@ +
+ {% block content %} +

snippet content with id {{ document.getId() }}

+ {{ pimcore_areablock('dachcomBundleTest') }} + {% endblock %} +
\ No newline at end of file diff --git a/tests/etc/config/system/config.yml b/tests/etc/config/system/config.yml new file mode 100755 index 00000000..686ce681 --- /dev/null +++ b/tests/etc/config/system/config.yml @@ -0,0 +1,14 @@ +imports: + - { resource: parameters.yml } + - { resource: security.yml } + - { resource: services.yml } + - { resource: 'local/' } + +# don't send real emails in functional tests +swiftmailer: + disable_delivery: true + +framework: + profiler: + enabled: true + collect: false \ No newline at end of file diff --git a/tests/etc/config/system/php.ini b/tests/etc/config/system/php.ini new file mode 100755 index 00000000..36357587 --- /dev/null +++ b/tests/etc/config/system/php.ini @@ -0,0 +1,8 @@ + +; extensions +;extension="memcache.so" +;extension="memcached.so" + +; custom php settings +memory_limit = 1G +date.timezone = Europe/Berlin \ No newline at end of file diff --git a/tests/etc/scripts/codeception b/tests/etc/scripts/codeception new file mode 100755 index 00000000..41b6c4f5 --- /dev/null +++ b/tests/etc/scripts/codeception @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +echo "START CODECEPTION TESTS FOR $DACHCOM_BUNDLE_NAME" + +CMD="vendor/bin/codecept run -c lib/$DACHCOM_BUNDLE_NAME --env travis" + +# generate json result file +CMD="$CMD --json" + +echo $CMD +eval $CMD diff --git a/tests/etc/travis/install b/tests/etc/travis/install new file mode 100755 index 00000000..8ef8d8d0 --- /dev/null +++ b/tests/etc/travis/install @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +set -e + + +## include global bundle test configuration + +source $TRAVIS_BUILD_DIR/tests/bundle_configuration + + +## setup php + +phpenv config-add $DACHCOM_BUNDLE_HOME/tests/etc/config/system/php.ini + + +# Install chrome driver + +wget -c -nc --retry-connrefused --tries=0 "https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip" -O chromedriver_linux64.zip +unzip -o -q chromedriver_linux64.zip -d $HOME + + +## setup mysql + +mysql --version +mysql -e "SET GLOBAL innodb_file_format=Barracuda;" +mysql -e "SET GLOBAL innodb_large_prefix=1;" +mysql -e "CREATE DATABASE dachcom_bundle_test CHARSET=utf8mb4;" + + +## move bundle temporarily and clean dir in order to install pimcore + +mkdir -p $DACHCOM_BUNDLE_HOME/../lib/$DACHCOM_BUNDLE_NAME +mv $DACHCOM_BUNDLE_HOME/{.[!.],}* $DACHCOM_BUNDLE_HOME/../lib/$DACHCOM_BUNDLE_NAME +rm -rf $DACHCOM_BUNDLE_HOME/{.[!.],}* + + +## clone pimcore + +git clone https://github.com/pimcore/skeleton.git $DACHCOM_BUNDLE_HOME +git checkout ${PIMCORE_SKELETON_BRANCH} $DACHCOM_BUNDLE_HOME + + +## move bundle back into lib/$DACHCOM_BUNDLE_NAME + +mv $DACHCOM_BUNDLE_HOME/../lib $DACHCOM_BUNDLE_HOME + + +## copy etc dir to root dir + +cp -r $DACHCOM_BUNDLE_HOME/lib/$DACHCOM_BUNDLE_NAME/tests/bundle_configuration $DACHCOM_BUNDLE_HOME/bundle_configuration +cp -r $DACHCOM_BUNDLE_HOME/lib/$DACHCOM_BUNDLE_NAME/tests/etc $DACHCOM_BUNDLE_HOME/etc +chmod -R +x $DACHCOM_BUNDLE_HOME/etc + + +## create download dir + +mkdir $DACHCOM_BUNDLE_HOME/lib/$DACHCOM_BUNDLE_NAME/tests/_data/downloads + + +## add config templates + +mkdir -p $DACHCOM_BUNDLE_HOME/var/config +cp $DACHCOM_BUNDLE_HOME/etc/config/system/config.yml app/config/config.yml +cp app/config/parameters.example.yml app/config/parameters.yml + +for K in "${!DACHCOM_INSTALL_CONFIG_FILES[@]}" +do + cp $K ${DACHCOM_INSTALL_CONFIG_FILES[$K]}; +done + +## install composer dependencies + +COMPOSER_MEMORY_LIMIT=-1 composer install --no-scripts + +## install $DACHCOM_BUNDLE_NAME dependencies + +COMPOSER_MEMORY_LIMIT=-1 composer require symfony/phpunit-bridge:^3 dachcom-digital/$DACHCOM_BUNDLE_REPO_NAME:dev-$DACHCOM_BUNDLE_BRANCH#$DACHCOM_BUNDLE_COMMIT + + +## clear cache + +rm -rf var/cache diff --git a/tests/etc/travis/script b/tests/etc/travis/script new file mode 100755 index 00000000..e8e5168a --- /dev/null +++ b/tests/etc/travis/script @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e + +source $TRAVIS_BUILD_DIR/bundle_configuration + +$DACHCOM_BUNDLE_HOME/etc/scripts/codeception \ No newline at end of file diff --git a/tests/kernelBuilder.php b/tests/kernelBuilder.php new file mode 100644 index 00000000..728d8563 --- /dev/null +++ b/tests/kernelBuilder.php @@ -0,0 +1,19 @@ +activatesKernelDebugMode($environment); + +if ($debug) { + Debug::enable(); + @ini_set('display_errors', 'On'); +} + +$kernel = new \DachcomBundle\Test\App\TestAppKernel($environment, $debug); + +return $kernel;