Skip to content
This repository was archived by the owner on Jan 5, 2018. It is now read-only.

Commit 08d017b

Browse files
primsiprimsi
authored andcommitted
Issue #2690131 by Primsi: Add tests asserting the working of the element - add travis config
1 parent 36483f1 commit 08d017b

File tree

6 files changed

+256
-0
lines changed

6 files changed

+256
-0
lines changed

.travis.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# @file
2+
# .travis.yml - Drupal for Travis CI Integration
3+
#
4+
# Template provided by https://github.com/LionsAd/drupal_ti.
5+
#
6+
# Based for simpletest upon:
7+
# https://github.com/sonnym/travis-ci-drupal-module-example
8+
9+
language: php
10+
sudo: false
11+
12+
cache:
13+
directories:
14+
- $HOME/.composer/cache
15+
16+
php:
17+
- 5.5
18+
- 5.6
19+
- 7
20+
- hhvm
21+
22+
matrix:
23+
fast_finish: true
24+
25+
branches:
26+
only:
27+
- "8.x-1.x"
28+
29+
env:
30+
global:
31+
# add composer's global bin directory to the path
32+
# see: https://github.com/drush-ops/drush#install---composer
33+
- PATH="$PATH:$HOME/.composer/vendor/bin"
34+
35+
# Configuration variables.
36+
- DRUPAL_TI_MODULE_NAME="dropzonejs"
37+
- DRUPAL_TI_SIMPLETEST_GROUP="dropzonejs"
38+
39+
# Define runners and environment vars to include before and after the
40+
# main runners / environment vars.
41+
#- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before"
42+
#- DRUPAL_TI_SCRIPT_DIR_AFTER="./drupal_ti/after"
43+
44+
# The environment to use, supported are: drupal-7, drupal-8
45+
- DRUPAL_TI_ENVIRONMENT="drupal-8"
46+
47+
# Drupal specific variables.
48+
- DRUPAL_TI_DB="drupal_travis_db"
49+
- DRUPAL_TI_DB_URL="mysql://root:@127.0.0.1/drupal_travis_db"
50+
# Note: Do not add a trailing slash here.
51+
- DRUPAL_TI_WEBSERVER_URL="http://127.0.0.1"
52+
- DRUPAL_TI_WEBSERVER_PORT="8080"
53+
54+
# Simpletest specific commandline arguments, the DRUPAL_TI_SIMPLETEST_GROUP is appended at the end.
55+
- DRUPAL_TI_SIMPLETEST_ARGS="--verbose --color --concurrency 4 --url $DRUPAL_TI_WEBSERVER_URL:$DRUPAL_TI_WEBSERVER_PORT"
56+
57+
# === Behat specific variables.
58+
# This is relative to $TRAVIS_BUILD_DIR
59+
# - DRUPAL_TI_BEHAT_DIR="./tests/behat"
60+
# These arguments are passed to the bin/behat command.
61+
# - DRUPAL_TI_BEHAT_ARGS=""
62+
# Specify the filename of the behat.yml with the $DRUPAL_TI_DRUPAL_DIR variables.
63+
# - DRUPAL_TI_BEHAT_YML="behat.yml.dist"
64+
# This is used to setup Xvfb.
65+
# - DRUPAL_TI_BEHAT_SCREENSIZE_COLOR="1280x1024x16"
66+
# The version of seleniumthat should be used.
67+
# - DRUPAL_TI_BEHAT_SELENIUM_VERSION="2.44"
68+
69+
# PHPUnit specific commandline arguments.
70+
- DRUPAL_TI_PHPUNIT_ARGS=""
71+
72+
# Code coverage via coveralls.io
73+
- DRUPAL_TI_COVERAGE="satooshi/php-coveralls:0.6.*"
74+
# This needs to match your .coveralls.yml file.
75+
- DRUPAL_TI_COVERAGE_FILE="build/logs/clover.xml"
76+
77+
# Debug options
78+
#- DRUPAL_TI_DEBUG="-x -v"
79+
# Set to "all" to output all files, set to e.g. "xvfb selenium" or "selenium",
80+
# etc. to only output those channels.
81+
#- DRUPAL_TI_DEBUG_FILE_OUTPUT="selenium xvfb webserver"
82+
83+
matrix:
84+
# [[[ SELECT ANY OR MORE OPTIONS ]]]
85+
#- DRUPAL_TI_RUNNERS="phpunit"
86+
#- DRUPAL_TI_RUNNERS="simpletest"
87+
#- DRUPAL_TI_RUNNERS="behat"
88+
#- DRUPAL_TI_RUNNERS="phpunit simpletest behat"
89+
- DRUPAL_TI_RUNNERS="phpunit-core"
90+
91+
mysql:
92+
database: drupal_travis_db
93+
username: root
94+
encoding: utf8
95+
96+
before_install:
97+
- composer self-update
98+
- composer global require "lionsad/drupal_ti:1.*"
99+
- drupal-ti before_install
100+
# Codesniffer and Coder
101+
- composer global require "squizlabs/php_codesniffer:2.0.*@dev"
102+
- composer global require drupal/coder:8.2.0-beta1
103+
- ln -s ~/.composer/vendor/drupal/coder/coder_sniffer/Drupal ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/
104+
105+
install:
106+
- drupal-ti install
107+
108+
before_script:
109+
- drupal-ti --include drupal_ti/.travis-before_script.sh
110+
- drupal-ti before_script
111+
112+
script:
113+
- drupal-ti --include drupal_ti/.travis-phpcs.sh
114+
- export SIMPLETEST_DB=mysql://root:@127.0.0.1/drupal_travis_db; drupal-ti script
115+
116+
after_script:
117+
- drupal-ti after_script

drupal_ti/.travis-before_script.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Add an optional statement to see that this is running in Travis CI.
4+
echo "running drupal_ti/before/before_script.sh"
5+
6+
set -e $DRUPAL_TI_DEBUG
7+
8+
# Ensure the right Drupal version is installed.
9+
# The first time this is run, it will install Drupal.
10+
# Note: This function is re-entrant.
11+
drupal_ti_ensure_drupal
12+
13+
# Change to the Drupal directory
14+
cd "$DRUPAL_TI_DRUPAL_DIR"
15+
16+
# Create the the module directory (only necessary for D7)
17+
# For D7, this is sites/default/modules
18+
# For D8, this is modules
19+
mkdir -p "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_LIBRARIES_PATH"
20+
cd "$DRUPAL_TI_DRUPAL_DIR"
21+
22+
# Manually clone the dependencies
23+
mkdir libraries
24+
cd libraries
25+
git clone --depth 1 https://github.com/enyo/dropzone.git

drupal_ti/.travis-phpcs.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e $DRUPAL_TI_DEBUG
4+
5+
# Ensure the right Drupal version is installed.
6+
# Note: This function is re-entrant.
7+
drupal_ti_ensure_drupal
8+
9+
phpcs --report=full --standard=Drupal "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH/$DRUPAL_TI_MODULE_NAME" || true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: 'DropzoneJs Test'
2+
type: module
3+
description: 'Support module for DropzoneJs tests.'
4+
package: Testing
5+
version: VERSION
6+
core: 8.x
7+
dependencies:
8+
- dropzonejs
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace Drupal\dropzonejs_test\Form;
3+
4+
use Drupal\Core\Form\FormBase;
5+
use Drupal\Core\Form\FormStateInterface;
6+
7+
class DropzoneJsTestForm extends FormBase {
8+
9+
/**
10+
* {@inheritdoc}
11+
*/
12+
public function getFormId() {
13+
return '_dropzonejs_test_form';
14+
}
15+
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function buildForm(array $form, FormStateInterface $form_state) {
20+
$form['dropzonejs'] = [
21+
'#title' => t('DropzoneJs element'),
22+
'#type' => 'dropzonejs',
23+
'#required' => TRUE,
24+
'#dropzone_description' => 'DropzoneJs description',
25+
'#max_filesize' => '1M',
26+
'#extensions' => 'jpg png',
27+
];
28+
29+
return $form;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function submitForm(array &$form, FormStateInterface $form_state) {
36+
}
37+
38+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Drupal\Tests\dropzonejs\Kernel;
4+
5+
use Drupal\KernelTests\KernelTestBase;
6+
use Drupal\user\Entity\Role;
7+
use Drupal\user\RoleInterface;
8+
9+
/**
10+
* Tests related to the dropzoneJs element.
11+
*
12+
* @group DropzoneJs
13+
*/
14+
class DropzoneJsElementTest extends KernelTestBase {
15+
16+
/**
17+
* Modules to enable.
18+
*
19+
* @var array
20+
*/
21+
public static $modules = ['system', 'file', 'user', 'dropzonejs', 'dropzonejs_test'];
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
protected function setUp() {
27+
parent::setUp();
28+
$this->installSchema('system', 'router');
29+
$this->installEntitySchema('user');
30+
31+
/** @var \Drupal\user\RoleInterface $role */
32+
$role = Role::create(['id' => RoleInterface::ANONYMOUS_ID]);
33+
$role->grantPermission('dropzone upload files');
34+
$role->save();
35+
}
36+
37+
/**
38+
* Tests that the dropzonejs element appears.
39+
*/
40+
public function testDropzoneJsElement() {
41+
$this->container->get('router.builder')->rebuild();
42+
$form = \Drupal::formBuilder()->getForm('\Drupal\dropzonejs_test\Form\DropzoneJsTestForm');
43+
$this->render($form);
44+
45+
$xpath_base = "/html/body/form/div[contains(@class, 'form-item-dropzonejs')]";
46+
// Label.
47+
$this->assertFalse($this->xpath("$xpath_base/label[text()='Not DropzoneJs element']"));
48+
$this->assertTrue($this->xpath("$xpath_base/label[text()='DropzoneJs element']"));
49+
// Element where dropzonejs is attached to.
50+
$this->assertTrue($this->xpath("$xpath_base/div[contains(@class, 'dropzone-enable')]"));
51+
// Uploaded files input.
52+
$this->assertTrue($this->xpath("$xpath_base/input[contains(@data-drupal-selector, 'edit-dropzonejs-uploaded-files')]"));
53+
// Upload files path.
54+
$this->assertTrue($this->xpath("$xpath_base/input[contains(@data-upload-path, '/dropzonejs/upload?token=')]"));
55+
// Js is attached.
56+
$this->assertTrue($this->xpath("/html/body/script[contains(@src, 'libraries/dropzone/dist/min/dropzone.min.js')]"));
57+
$this->assertTrue($this->xpath("/html/body/script[contains(@src, 'modules/dropzonejs/js/dropzone.integration.js')]"));
58+
}
59+
}

0 commit comments

Comments
 (0)