Commit 52c21df1 authored by Thomas Citharel's avatar Thomas Citharel 🌲

Try tests

parent c187909b
before_script:
# Install composer dependencies
- bash ci/docker_install.sh
# We test PHP7.0
test:7.0:
image: php:7.0
script:
- ant prepare-sqlite
- phpunit -v --colors
# We test PHP7.1
test:7.1:
image: php:7.1
script:
- ant prepare-sqlite
- phpunit -v --colors
cache:
paths:
- vendor/
\ No newline at end of file
......@@ -34,6 +34,7 @@ class AppKernel extends Kernel
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
}
return $bundles;
......
......@@ -4,7 +4,7 @@
<div class="container ombre">
<div class="col-md-6 col-md-offset-3">
<div class="header">
<h4 class="modal-title" id="templateModalTitle">{{ 'templates.title' | trans({ '%presentation%': presentation.title }) }}</h4>
<h4 class="modal-title">{{ 'templates.title' | trans({ '%presentation%': presentation.title }) }}</h4>
{% for flashMessage in app.session.flashbag.get('notice') %}
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
......
......@@ -4,7 +4,7 @@
<div class="container ombre">
<div class="col-md-6 col-md-offset-3">
<div class="header">
<h4 class="modal-title" id="templateModalTitle">{{ 'group.new.title' | trans }}</h4>
<h4 class="modal-title">{{ 'group.new.title' | trans }}</h4>
<div class="alert alert-warning alert-dismissible fade in hidden" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> <strong>{{ 'errors.default' | trans }}</strong> </div>
<div class="alert alert-info alert-dismissible fade in hidden" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> <strong>{{ 'info.default' | trans }}</strong> <span class="desc"></span></div>
</div>
......
......@@ -4,7 +4,7 @@
<div class="container ombre">
<div class="col-md-6 col-md-offset-3">
<div class="header">
<h4 class="modal-title" id="templateModalTitle">{{ 'templates.title' | trans({ '%presentation%': presentation.title }) }}</h4>
<h4 class="modal-title">{{ 'templates.title' | trans({ '%presentation%': presentation.title }) }}</h4>
{% for flashMessage in app.session.flashbag.get('notice') %}
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
......
......@@ -93,7 +93,7 @@ swiftmailer:
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
firewall_name: secured_area
user_class: Strut\UserBundle\Entity\User
registration:
confirmation:
......
imports:
- { resource: config_dev.yml }
- { resource: parameters_test.yml }
framework:
test: ~
......@@ -7,10 +8,32 @@ framework:
storage_id: session.storage.mock_file
profiler:
collect: false
translator:
enabled: false
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
# to be able to read emails sent
spool:
type: file
doctrine:
dbal:
driver: "%test_database_driver%"
host: "%test_database_host%"
port: "%test_database_port%"
dbname: "%test_database_name%"
user: "%test_database_user%"
password: "%test_database_password%"
charset: "%test_database_charset%"
path: "%test_database_path%"
orm:
metadata_cache_driver:
type: service
id: filesystem_cache
query_cache_driver:
type: service
id: filesystem_cache
parameters:
test_database_driver: pdo_sqlite
test_database_host: localhost
test_database_port:
test_database_name: ~
test_database_user: ~
test_database_password: ~
test_database_path: "%kernel.root_dir%/../data/db/framaslides_test.sqlite"
test_database_charset: utf8
......@@ -43,7 +43,7 @@ security:
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/users/, role: ROLE_ADMIN }
- { path: ^/users, role: ROLE_ADMIN }
- { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/picture/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_USER }
......@@ -91,4 +91,9 @@ services:
- "%pictures_directory%"
- "@logger"
tags:
- { name: doctrine.event_listener, event: postRemove }
\ No newline at end of file
- { name: doctrine.event_listener, event: postRemove }
filesystem_cache:
class: Doctrine\Common\Cache\FilesystemCache
arguments:
- "%kernel.cache_dir%/doctrine/metadata"
\ No newline at end of file
parameters:
test_database_driver: pdo_mysql
test_database_host: localhost
test_database_port: 3306
test_database_name: framaslides_test
test_database_user: root
test_database_password: ~
test_database_path: ~
test_database_charset: utf8mb4
parameters:
test_database_driver: pdo_pgsql
test_database_host: localhost
test_database_port:
test_database_name: framaslides_test
test_database_user: travis
test_database_password: ~
test_database_path: ~
test_database_charset: utf8
parameters:
test_database_driver: pdo_sqlite
test_database_host: localhost
test_database_port:
test_database_name: ~
test_database_user: ~
test_database_password: ~
test_database_path: "%kernel.root_dir%/../data/db/framaslides_test.sqlite"
test_database_charset: utf8
<?xml version="1.0" encoding="UTF-8"?>
<project name="framaslides" default="build">
<target name="build" depends="clean,prepare,phpunit"/>
<target name="prepare-mysql" depends="clean,prepare_mysql"/>
<target name="prepare-sqlite" depends="clean,prepare_sqlite"/>
<target name="prepare-pgsql" depends="clean,prepare_pgsql"/>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/var/cache"/>
</target>
<target name="prepare" description="Prepare for build">
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:drop"/>
<arg value="--force"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:create"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:schema:create"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:fixtures:load"/>
<arg value="--no-interaction"/>
<arg value="--env=test"/>
</exec>
</target>
<target name="prepare_mysql" description="Run test for MySQL">
<delete dir="${basedir}/app/config/parameters.yml"/>
<exec executable="cp">
<arg value="${basedir}/app/config/tests/parameters_test.mysql.yml"/>
<arg value="${basedir}/app/config/parameters_test.yml"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="cache:clear"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:drop"/>
<arg value="--force"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:create"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:import"/>
<arg value="data/sql/mysql_base.sql"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:migrations:migrate"/>
<arg value="--no-interaction"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:fixtures:load"/>
<arg value="--no-interaction"/>
<arg value="--env=test"/>
</exec>
</target>
<target name="prepare_sqlite" description="Run test for SQLite">
<delete dir="${basedir}/app/config/parameters.yml"/>
<exec executable="cp">
<arg value="${basedir}/app/config/tests/parameters_test.sqlite.yml"/>
<arg value="${basedir}/app/config/parameters_test.yml"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="cache:clear"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:drop"/>
<arg value="--force"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:create"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:schema:create"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:migrations:migrate"/>
<arg value="--no-interaction"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:fixtures:load"/>
<arg value="--no-interaction"/>
<arg value="--env=test"/>
</exec>
</target>
<target name="prepare_pgsql" description="Run test for PostgreSQL">
<delete dir="${basedir}/app/config/parameters.yml"/>
<exec executable="cp">
<arg value="${basedir}/app/config/tests/parameters_test.pgsql.yml"/>
<arg value="${basedir}/app/config/parameters_test.yml"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="cache:clear"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:drop"/>
<arg value="--force"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:database:create"/>
<arg value="--env=test"/>
</exec>
<exec executable="psql">
<arg value="-h"/>
<arg value="localhost"/>
<arg value="-d"/>
<arg value="framaslides_test"/>
<arg value="-U"/>
<arg value="travis"/>
<arg value="-f"/>
<arg value="data/sql/pgsql_base.sql"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:migrations:migrate"/>
<arg value="--no-interaction"/>
<arg value="--env=test"/>
</exec>
<exec executable="php">
<arg value="${basedir}/bin/console"/>
<arg value="doctrine:fixtures:load"/>
<arg value="--no-interaction"/>
<arg value="--env=test"/>
</exec>
</target>
<target name="phpunit" description="Run unit tests with PHPUnit + HTML Coverage">
<exec executable="phpunit" failonerror="true">
<arg value="--coverage-html"/>
<arg value="build/coverage"/>
</exec>
</target>
</project>
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0
set -xe
# Install nodejs
echo 'deb http://deb.nodesource.com/node_6.x jessie main' > /etc/apt/sources.list.d/nodesource.list
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
# Install other requirements
apt-get update -yqq
apt-get install git wget libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev nodejs build-essential bzip2 -yqq
npm i
grunt build
# Compile PHP, include these extensions.
docker-php-ext-install mbstring mcrypt pdo_sqlite curl json intl gd xml zip bz2 opcache
wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php'); unlink('installer.sig');"
php composer.phar install
# Install phpunit, the tool that we will use for testing
curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar
chmod +x /usr/local/bin/phpunit
\ No newline at end of file
......@@ -38,7 +38,8 @@
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
"symfony/phpunit-bridge": "^3.0",
"doctrine/doctrine-fixtures-bundle": "^2.3"
},
"scripts": {
"symfony-scripts": [
......
......@@ -10,6 +10,7 @@
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_DIR" value="app/" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>
<testsuites>
......@@ -22,6 +23,7 @@
<whitelist>
<directory>src</directory>
<exclude>
<directory>vendor</directory>
<directory>src/*Bundle/Resources</directory>
<directory>src/*/*Bundle/Resources</directory>
<directory>src/*/Bundle/*Bundle/Resources</directory>
......
......@@ -208,38 +208,6 @@ class PresentationController extends Controller
]);
}
/**
* @Route("/preview/{presentation}/", name="preview", requirements={"presentation": "\d+"})
* @param Presentation $presentation
* @param $type
* @return Response
*/
public function previewPresentationAction(Presentation $presentation, string $type = "impress"): Response
{
$this->get('strut.check_rights')->checkUserPresentationAction($this->getUser(), $presentation);
switch ($type) {
case 'impress':
return $this->render('@Strut/preview_export/impress.html', [
'presentation' => $presentation
]);
case 'bespoke':
return $this->render('@Strut/preview_export/bespoke.html', [
'presentation' => $presentation
]);
case 'handouts':
return $this->render('@Strut/preview_export/handouts.html', [
'presentation' => $presentation
]);
default:
return new JsonResponse(null, 406);
}
}
/**
* @Route("/versions/purge/{presentation}", name="purge-version")
* @param Presentation $presentation
......
<?php
namespace Strut\StrutBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Strut\StrutBundle\Entity\Config;
use Strut\UserBundle\Entity\User;
class LoadConfigData extends AbstractFixture implements OrderedFixtureInterface
{
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
/** @var User $admin */
$admin = $this->getReference('admin-user');
/** @var Config $adminConfig */
$adminConfig = new Config($admin);
$adminConfig->setLanguage('en');
$adminConfig->setListMode(0);
$manager->persist($adminConfig);
$admin->setConfig($adminConfig);
$manager->persist($admin);
$this->addReference('admin-config', $adminConfig);
/** @var User $bob */
$bob = $this->getReference('bob-user');
$bobConfig = new Config($bob);
$bobConfig->setLanguage('fr');
$bobConfig->setListMode(1);
$manager->persist($bobConfig);
$bob->setConfig($bobConfig);
$manager->persist($bob);
$this->addReference('bob-config', $bobConfig);
/** @var User $empty */
$empty = $this->getReference('empty-user');
$emptyConfig = new Config($empty);
$emptyConfig->setLanguage('en');
$emptyConfig->setListMode(0);
$manager->persist($emptyConfig);
$empty->setConfig($bobConfig);
$manager->persist($empty);
$this->addReference('empty-config', $emptyConfig);
$manager->flush();
}
/**
* {@inheritdoc}
*/
public function getOrder()
{
return 20;
}
}
<?php
namespace Wallabag\CoreBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Strut\StrutBundle\Entity\Presentation;
use Strut\StrutBundle\Entity\Version;
use Strut\UserBundle\Entity\User;
class LoadPresentationData extends AbstractFixture implements OrderedFixtureInterface
{
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
/** @var User $admin */
$admin = $this->getReference('admin-user');
$presentation = new Presentation($admin);
$presentation->setTitle('Test');
$manager->persist($presentation);
$version = new Version($presentation);
$framaslidesFile = file_get_contents(__DIR__ . '/../Content/TutoFramaslides.json');
$version->setContent($framaslidesFile);
$manager->persist($version);
$presentation->addVersion($version);
$manager->persist($presentation);
$manager->flush();
}
/**
* {@inheritdoc}
*/
public function getOrder()
{
return 30;
}
}
<?php
namespace Strut\UserBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Strut\UserBundle\Entity\User;
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
{
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$userAdmin = new User();
$userAdmin->setEmail('tcit@framasoft.org');
$userAdmin->setUsername('admin');
$userAdmin->setPlainPassword('mypassword');
$userAdmin->setEnabled(true);
$userAdmin->addRole('ROLE_SUPER_ADMIN');
$manager->persist($userAdmin);
$this->addReference('admin-user', $userAdmin);
$bobUser = new User();
$bobUser->setEmail('pyg@framasoft.org');
$bobUser->setUsername('bob');
$bobUser->setPlainPassword('mypassword');
$bobUser->setEnabled(true);
$manager->persist($bobUser);
$this->addReference('bob-user', $bobUser);
$emptyUser = new User();
$emptyUser->setEmail('empty@framasoft.org');
$emptyUser->setUsername('empty');
$emptyUser->setPlainPassword('mypassword');
$emptyUser->setEnabled(true);
$manager->persist($emptyUser);
$this->addReference('empty-user', $emptyUser);
$manager->flush();
}
/**
* {@inheritdoc}
*/
public function getOrder()
{
return 10;
}
}
<?php
namespace Tests\Strut\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text());
}
}
<?php
namespace Tests\Wallabag\CoreBundle\Command;
use Tests\Strut\StrutBundle\StrutTestCase;
class InstallCommandTest extends StrutTestCase
{
public function setUp()
{
parent::setUp();
if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) {
/*
* LOG: statement: CREATE DATABASE "wallabag"
* ERROR: source database "template1" is being accessed by other users
* DETAIL: There is 1 other session using the database.
* STATEMENT: CREATE DATABASE "wallabag"
* FATAL: database "wallabag" does not exist
*
* http://stackoverflow.com/a/14374832/569101
*/
$this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.');
}
}
}
<?php
namespace Tests\Wallabag\CoreBundle\Controller;
use Tests\Strut\StrutBundle\StrutTestCase;
class AdminControllerTest extends StrutTestCase
{
public function testSettingsWithAdmin()
{
$this->logInAs('admin');
$client = $this->getClient();
$crawler = $client->request('GET', '/users');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
public function testSettingsWithNormalUser()
{
$this->logInAs('bob');
$client = $this->getClient();
$crawler = $client->request('GET', '/users');
$this->assertEquals(403, $client->getResponse()->getStatusCode());
}
}
<?php
namespace Tests\Strut\StrutBundle\Controller;
use Tests\Strut\StrutBundle\StrutTestCase;
class DefaultControllerTest extends StrutTestCase