diff --git a/.travis.yml b/.travis.yml index 6b279a9..eaab3d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ script: - ./www/bin/phpcs --standard=symfony2 www/src - ./www/bin/phpunit -c www/app/ - php ./scripts/coverage-checker.php www/var/logs/clover.xml 56 +- ./scripts/runSeleniumTests.sh install: - if [[ $MONGOEXTENSION == "mongo.so" ]]; then composer --working-dir="www" remove alcaeus/mongo-php-adapter mongodb/mongodb; fi diff --git a/files/nginx/default b/files/nginx/default index f19f1fe..ff92e87 100644 --- a/files/nginx/default +++ b/files/nginx/default @@ -20,7 +20,7 @@ server { } # pass the PHP scripts to FastCGI server listening socket - location ~ ^/(app|app_dev)\.php(/|$) { + location ~ ^/(app|app_dev|app_selenium)\.php(/|$) { fastcgi_pass unix://var/run/php5-fpm.sock; fastcgi_keep_conn on; fastcgi_split_path_info ^(.+\.php)(/.*)$; diff --git a/scripts/runSeleniumTests.sh b/scripts/runSeleniumTests.sh new file mode 100755 index 0000000..ed01e84 --- /dev/null +++ b/scripts/runSeleniumTests.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +cd ./www/ + +php bin/console server:start -v +bin/phantomjs --webdriver=8910 --webdriver-loglevel=ERROR & +bin/console assetic:dump --env=selenium +bin/console cache:warmup --env=selenium -q + +bin/phpunit -c app/phpunitselenium.xml +RETURNVALUEPHPUNIT=$? + +pkill -f 'bin/phantomjs --webdriver=8910' +php bin/console server:stop -q + +exit $RETURNVALUEPHPUNIT \ No newline at end of file diff --git a/www/app/AppKernel.php b/www/app/AppKernel.php index 2c452cc..570acab 100644 --- a/www/app/AppKernel.php +++ b/www/app/AppKernel.php @@ -21,12 +21,13 @@ public function registerBundles() new AdminBundle\AdminBundle(), ); - if (in_array($this->getEnvironment(), array('dev', 'test'))) { + if (in_array($this->getEnvironment(), array('dev', 'test', 'selenium'))) { $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); $bundles[] = new Apoutchika\LoremIpsumBundle\ApoutchikaLoremIpsumBundle(); + $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(); } return $bundles; diff --git a/www/app/config/config_selenium.yml b/www/app/config/config_selenium.yml new file mode 100644 index 0000000..211dcaf --- /dev/null +++ b/www/app/config/config_selenium.yml @@ -0,0 +1,7 @@ +imports: + - { resource: config_dev.yml } + - { resource: parameters_selenium.yml} + +web_profiler: + toolbar: false + intercept_redirects: false \ No newline at end of file diff --git a/www/app/config/parameters_selenium.yml b/www/app/config/parameters_selenium.yml new file mode 100644 index 0000000..974ab03 --- /dev/null +++ b/www/app/config/parameters_selenium.yml @@ -0,0 +1,15 @@ +# This file is auto-generated during the composer install +parameters: + database_host: localhost + database_port: 27017 + database_name: dbselenium + mailer_transport: smtp + mailer_host: 127.0.0.1 + mailer_user: null + mailer_password: null + secret: ThisTokenIsNotSoSecretChangeIt + piwik_host: //piwik.waszulesen.de/ + piwik_id: 2 + locale: de + features.login_enabled: true + features.login_needed: true diff --git a/www/app/phpunitselenium.xml b/www/app/phpunitselenium.xml new file mode 100644 index 0000000..4e2a8ee --- /dev/null +++ b/www/app/phpunitselenium.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + ../selenium + + + + diff --git a/www/composer.json b/www/composer.json index f056361..3376fb4 100644 --- a/www/composer.json +++ b/www/composer.json @@ -34,7 +34,10 @@ "symfony/phpunit-bridge": "^3.0", "escapestudios/symfony2-coding-standard": "~2.0", "apoutchika/loremipsum-bundle": "dev-master", - "symfony/debug": "3.1.*" + "symfony/debug": "3.1.*", + "facebook/webdriver": "^1.2", + "jakoch/phantomjs-installer": "^2.1", + "doctrine/doctrine-fixtures-bundle": "^2.3" }, "scripts": { "post-root-package-install": [ @@ -47,7 +50,8 @@ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget", + "PhantomInstaller\\Installer::installPhantomJS" ], "post-install-cmd": [ "@symfony-scripts", diff --git a/www/composer.lock b/www/composer.lock index a18b85a..e7db2c0 100644 --- a/www/composer.lock +++ b/www/composer.lock @@ -2651,6 +2651,122 @@ ], "time": "2014-10-05 19:11:51" }, + { + "name": "doctrine/data-fixtures", + "version": "v1.2.2", + "source": { + "type": "git", + "url": "https://github.com/doctrine/data-fixtures.git", + "reference": "17fa5bfe6ff52e35cb3d9ec37c934a2f4bd1fa2e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/17fa5bfe6ff52e35cb3d9ec37c934a2f4bd1fa2e", + "reference": "17fa5bfe6ff52e35cb3d9ec37c934a2f4bd1fa2e", + "shasum": "" + }, + "require": { + "doctrine/common": "~2.2", + "php": "^5.6 || ^7.0" + }, + "conflict": { + "doctrine/orm": "< 2.4" + }, + "require-dev": { + "doctrine/dbal": "^2.5.4", + "doctrine/orm": "^2.5.4", + "phpunit/phpunit": "^5.4.6" + }, + "suggest": { + "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\DataFixtures": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Data Fixtures for all Doctrine Object Managers", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database" + ], + "time": "2016-09-20 10:07:57" + }, + { + "name": "doctrine/doctrine-fixtures-bundle", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineFixturesBundle.git", + "reference": "0f1a2f91b349e10f5c343f75ab71d23aace5b029" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/0f1a2f91b349e10f5c343f75ab71d23aace5b029", + "reference": "0f1a2f91b349e10f5c343f75ab71d23aace5b029", + "shasum": "" + }, + "require": { + "doctrine/data-fixtures": "~1.0", + "doctrine/doctrine-bundle": "~1.0", + "php": ">=5.3.2", + "symfony/doctrine-bridge": "~2.3|~3.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Bundle\\FixturesBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony DoctrineFixturesBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "Fixture", + "persistence" + ], + "time": "2015-11-04 21:23:23" + }, { "name": "escapestudios/symfony2-coding-standard", "version": "2.9.1", @@ -2697,6 +2813,103 @@ ], "time": "2016-03-14 16:38:04" }, + { + "name": "facebook/webdriver", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/facebook/php-webdriver.git", + "reference": "af21de3ae5306a8ca0bcc02a19735dadc43e83f3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/af21de3ae5306a8ca0bcc02a19735dadc43e83f3", + "reference": "af21de3ae5306a8ca0bcc02a19735dadc43e83f3", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": "^5.5 || ~7.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^1.11", + "php-mock/php-mock-phpunit": "^1.1", + "phpunit/phpunit": "4.6.* || ~5.0", + "squizlabs/php_codesniffer": "^2.6" + }, + "suggest": { + "phpdocumentor/phpdocumentor": "2.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Facebook\\WebDriver\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "A PHP client for WebDriver", + "homepage": "https://github.com/facebook/php-webdriver", + "keywords": [ + "facebook", + "php", + "selenium", + "webdriver" + ], + "time": "2016-10-14 15:16:51" + }, + { + "name": "jakoch/phantomjs-installer", + "version": "2.1.1-p07", + "source": { + "type": "git", + "url": "https://github.com/jakoch/phantomjs-installer.git", + "reference": "4d0e994f110a79738b73083c2c3086d162547bd6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jakoch/phantomjs-installer/zipball/4d0e994f110a79738b73083c2c3086d162547bd6", + "reference": "4d0e994f110a79738b73083c2c3086d162547bd6", + "shasum": "" + }, + "require": { + "ext-bz2": "*", + "ext-openssl": "*", + "php": ">5.3" + }, + "require-dev": { + "composer/composer": "^1.2", + "phpunit/phpunit": "^4.8" + }, + "type": "custom-installer", + "autoload": { + "psr-4": { + "PhantomInstaller\\Test\\": "tests/" + }, + "psr-0": { + "PhantomInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jens-André Koch", + "email": "jakoch@web.de" + } + ], + "description": "A Composer package which installs the PhantomJS binary (Linux, Windows, Mac) into `/bin` of your project.", + "keywords": [ + "binaries", + "headless", + "phantomjs" + ], + "time": "2016-10-12 01:52:42" + }, { "name": "myclabs/deep-copy", "version": "1.6.0", @@ -3276,7 +3489,7 @@ }, { "name": "phpunit/phpunit-mock-objects", - "version": "3.4.3", + "version": "3.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", @@ -3380,7 +3593,7 @@ }, { "name": "sebastian/comparator", - "version": "1.2.4", + "version": "1.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", diff --git a/www/selenium/DembeloTest.php b/www/selenium/DembeloTest.php new file mode 100644 index 0000000..0bd1756 --- /dev/null +++ b/www/selenium/DembeloTest.php @@ -0,0 +1,84 @@ + 'phantomjs', + 'phantomjs.page.settings.userAgent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0' + ); + $this->webDriver = RemoteWebDriver::create('127.0.0.1:8910', $capabilities); + + $this->webDriver->manage()->window()->maximize(); + + $this->webDriver->manage()->deleteAllCookies(); + shell_exec('php bin/console doctrine:mongodb:fixtures:load -n -e selenium'); + } + + public function testDembeloHome() + { + $this->webDriver->get($this->url); + $this->assertEquals('was zu lesen', $this->webDriver->getTitle()); + } + + public function testDembeloLogin() + { + //$this->webDriver->manage()->window()->maximize(); + + $this->loginAsAdmin(); + + } + + protected function loginAsAdmin() + { + $this->webDriver->get($this->url); + + $menuSettings = $this->webDriver->findElement( + WebDriverBy::className('menu-icon') + ); + $menuSettings->click(); + + $menuLogin = $this->webDriver->findElement( + WebDriverBy::className('ion-person') + ); + $menuLogin->click(); + + $this->webDriver->wait(10)->until( + WebDriverExpectedCondition::presenceOfAllElementsLocatedBy( + WebDriverBy::id('form__username') + ) + ); + + $formEmail = $this->webDriver->findElement( + WebDriverBy::id('form__username') + ); + $formEmail->sendKeys('admin@dembelo.tld'); + + $formPassword = $this->webDriver->findElement( + WebDriverBy::id('form_password') + ); + $formPassword->sendKeys('dembelo')->submit(); + + $this->webDriver->wait(20)->until( + WebDriverExpectedCondition::presenceOfAllElementsLocatedBy( + WebDriverBy::className('ion-android-exit') + ) + ); + + } +} diff --git a/www/src/DembeloMain/DataFixtures/MongoDB/LoadSeleniumData.php b/www/src/DembeloMain/DataFixtures/MongoDB/LoadSeleniumData.php new file mode 100644 index 0000000..9a15a86 --- /dev/null +++ b/www/src/DembeloMain/DataFixtures/MongoDB/LoadSeleniumData.php @@ -0,0 +1,103 @@ +. + */ + +namespace DembeloMain\DataFixtures\MongoDB; + +use Doctrine\Common\DataFixtures\FixtureInterface; +use Doctrine\Common\Persistence\ObjectManager; +use DembeloMain\Document\User; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Class LoadSeleniumData + * loads all data used for selenium test suite + * + * @package DembeloMain\DataFixtures\MongoDB + */ +class LoadSeleniumData implements FixtureInterface, ContainerAwareInterface +{ + /** + * @var ContainerInterface + */ + private $container; + + /** + * sets the symfony container + * @param ContainerInterface|null $container + */ + public function setContainer(ContainerInterface $container = null) + { + $this->container = $container; + } + + /** + * loads all the data to the database + * + * @param ObjectManager $manager + */ + public function load(ObjectManager $manager) + { + $users = array( + array( + 'email' => 'admin@dembelo.tld', + 'password' => 'dembelo', + 'roles' => array('ROLE_ADMIN'), + 'gender' => 'm', + 'status' => 1, + 'source' => '', + 'reason' => '', + 'metadata' => array('created' => time(), 'updated' => time()), + ), + ); + + $this->installUsers($users, $manager); + } + + private function installUsers(array $users, ObjectManager $manager) + { + $repository = $manager->getRepository('DembeloMain:User'); + + $encoder = $this->container->get('security.password_encoder'); + + if (!isset($this->dummyData['users'])) { + $this->dummyData['users'] = array(); + } + + foreach ($users as $userData) { + $user = $repository->findOneByEmail($userData['email']); + + if (is_null($user)) { + $user = new User(); + $user->setEmail($userData['email']); + $password = $encoder->encodePassword($user, $userData['password']); + $user->setPassword($password); + $user->setRoles($userData['roles']); + $user->setGender($userData['gender']); + $user->setSource($userData['source']); + $user->setReason($userData['reason']); + $user->setStatus($userData['status']); + $user->setMetadata($userData['metadata']); + + $manager->persist($user); + $manager->flush(); + } + } + } +} diff --git a/www/src/DembeloMain/Tests/DataFixtures/MongoDB/LoadSeleniumDataTest.php b/www/src/DembeloMain/Tests/DataFixtures/MongoDB/LoadSeleniumDataTest.php new file mode 100644 index 0000000..681f96d --- /dev/null +++ b/www/src/DembeloMain/Tests/DataFixtures/MongoDB/LoadSeleniumDataTest.php @@ -0,0 +1,95 @@ +. + */ + +namespace DembeloMain\Tests\DataFixtures\MongoDB; + +use DembeloMain\Document\User; +use DembeloMain\Model\Repository\Doctrine\ODM\UserRepository; +use Doctrine\Common\Persistence\ObjectManager; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use DembeloMain\DataFixtures\MongoDB\LoadSeleniumData; +use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\Security\Core\Tests\Encoder\PasswordEncoder; + +/** + * Class DocumentTextnodeTest + */ +class LoadSeleniumDataTest extends WebTestCase +{ + /** + * simple tests for main functionality + */ + public function testLoad() + { + $phpunit = $this; + $userRepositoryMock = $this->getUserRepositoryMock(); + $managerMock = $this->getManagerMock(); + $managerMock->expects($this->once()) + ->method('getRepository') + ->with('DembeloMain:User') + ->willReturn($userRepositoryMock); + $managerMock->expects($this->once()) + ->method('persist') + ->willReturnCallback(function ($argument) use (&$phpunit) { + $phpunit->assertInstanceOf(User::class, $argument); + }); + $managerMock->expects($this->once()) + ->method('flush'); + + $encoderMock = $this->getEncoderMock(); + $containerMock = $this->getContainerMock(); + $containerMock->expects($this->once()) + ->method('get') + ->with('security.password_encoder') + ->willReturn($encoderMock); + + $fixture = new LoadSeleniumData(); + $fixture->setContainer($containerMock); + $fixture->load($managerMock); + } + + private function getEncoderMock() + { + return $this->getMockBuilder(PasswordEncoder::class) + ->setMethods(['encodePassword']) + ->getMock(); + } + + private function getUserRepositoryMock() + { + return $this->getMockBuilder(UserRepository::class) + ->disableOriginalConstructor() + ->setMethods(['findOneByEmail']) + ->getMock(); + } + + private function getManagerMock() + { + return $this->getMockBuilder(ObjectManager::class) + ->setMethods(['getRepository', 'persist', 'flush']) + ->getMockForAbstractClass(); + } + + private function getContainerMock() + { + return $this->getMockBuilder(Container::class) + ->setMethods(['get']) + ->getMock(); + } +} diff --git a/www/web/app.php b/www/web/app.php index 893f4a9..5e800f4 100644 --- a/www/web/app.php +++ b/www/web/app.php @@ -3,7 +3,7 @@ use Symfony\Component\HttpFoundation\Request; $loader = require __DIR__.'/../app/autoload.php'; -include_once __DIR__.'/../var/bootstrap.php.cache'; +include_once __DIR__.'/../app/bootstrap.php.cache'; $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); diff --git a/www/web/app_selenium.php b/www/web/app_selenium.php new file mode 100644 index 0000000..4f4ab60 --- /dev/null +++ b/www/web/app_selenium.php @@ -0,0 +1,29 @@ +. + */ + +use Symfony\Component\HttpFoundation\Request; + +$loader = require __DIR__.'/../app/autoload.php'; + +$kernel = new AppKernel('selenium', false); +$kernel->loadClassCache(); +$request = Request::createFromGlobals(); +$response = $kernel->handle($request); +$response->send(); +$kernel->terminate($request, $response);