Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
workflows:
version: 2
main:
jobs:
- php56-build
- php70-build
- php71-build
- php72-build
- php73-build
- php74-build

version: 2

job-references:
mysql_image: &mysql_image
circleci/mysql:5.6

setup_environment: &setup_environment
name: "Setup Environment Variables"
command: |
echo "export PATH=$HOME/.composer/vendor/bin:$PATH" >> $BASH_ENV
source /home/circleci/.bashrc

install_dependencies: &install_dependencies
name: "Install Dependencies"
command: |
sudo apt-get update && sudo apt-get install subversion
sudo -E docker-php-ext-install mysqli
sudo sh -c "printf '\ndeb http://ftp.us.debian.org/debian sid main\n' >> /etc/apt/sources.list"
sudo apt-get update && sudo apt-get install mysql-client-5.7

php_job: &php_job
environment:
- WP_TESTS_DIR: "/tmp/wordpress-tests-lib"
- WP_CORE_DIR: "/tmp/wordpress/"
steps:
- checkout
- run: *setup_environment
- run: *install_dependencies
- run:
name: "Run Tests"
command: |
composer global require "phpunit/phpunit=5.7.*"
composer global require wp-coding-standards/wpcs
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
phpcs
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
phpunit
WP_MULTISITE=1 phpunit

jobs:
php56-build:
<<: *php_job
docker:
- image: circleci/php:5.6
- image: *mysql_image
steps:
- checkout
- run: *setup_environment
- run: *install_dependencies
- run:
name: "Run Tests"
command: |
composer global require "phpunit/phpunit=5.7.*"
composer global require wp-coding-standards/wpcs
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
phpcs
SKIP_DB_CREATE=false
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 3.5 $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 trunk $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true

php70-build:
<<: *php_job
docker:
- image: circleci/php:7.0
- image: *mysql_image

php71-build:
<<: *php_job
docker:
- image: circleci/php:7.1
- image: *mysql_image

php72-build:
<<: *php_job
docker:
- image: circleci/php:7.2
- image: *mysql_image

php73-build:
<<: *php_job
docker:
- image: circleci/php:7.3
- image: *mysql_image

php74-build:
<<: *php_job
docker:
- image: circleci/php:7.4
- image: *mysql_image
101 changes: 101 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Unit Tests

on: [pull_request]

jobs:
test-wp:
name: Test WordPress Plugin
runs-on: ubuntu-latest

strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
wp-version: ['6.6', '6.7', 'latest']
include:
- php-version: '7.4'
php-image: php:7.4-cli
- php-version: '8.0'
php-image: php:8.0-cli
- php-version: '8.1'
php-image: php:8.1-cli
- php-version: '8.2'
php-image: php:8.2-cli
- php-version: '8.3'
php-image: php:8.3-cli

container:
image: ${{ matrix.php-image }}
options: --user root

services:
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: wordpress_test
MYSQL_ROOT_PASSWORD: root
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v4

- name: Install tools and PHP extensions
run: |
apt-get update && apt-get install -y unzip git curl subversion default-mysql-client
docker-php-ext-install mysqli
if [ "${{ matrix.php-version }}" != "7.4" ]; then pecl install xdebug; fi
if [ "${{ matrix.php-version }}" != "7.4" ]; then docker-php-ext-enable xdebug; fi

- name: Configure Xdebug for coverage
if: ${{ matrix.php-version != '7.4' }}
run: |
echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

- name: Install Composer
run: |
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

- name: Install dependencies
run: |
if [ "${{ matrix.php-version }}" = "7.4" ]; then composer require phpunit/phpunit:^9 --no-update --no-interaction; fi
if [ "${{ matrix.php-version }}" = "8.0" ] || [ "${{ matrix.php-version }}" = "8.1" ]; then composer require phpunit/phpunit:^9 --no-update --no-interaction; fi
composer update --no-interaction

- name: Install WP test suite
run: |
mysql -u root -proot -h mysql -P 3306 -e "DROP DATABASE IF EXISTS wordpress_test;"
bash ./bin/install-wp-tests.sh wordpress_test root 'root' mysql ${{ matrix.wp-version }}

- name: Run PHPUnit with coverage
run: |
if [ "${{ matrix.php-version }}" = "7.4" ]; then vendor/bin/phpunit --configuration phpunit.xml.dist; else vendor/bin/phpunit --configuration phpunit.xml.dist --coverage-clover=coverage.xml; fi

- name: Cleanup
if: ${{ always() }}
uses: rtCamp/action-cleanup@master
test-npm:
name: Test Blocks
runs-on: ubuntu-latest

container:
image: node:20
options: --user root

steps:
- uses: actions/checkout@v4

- name: Install npm dependencies
working-directory: ./src/documentcloud/blocks # Run npm commands from the blocks folder
run: |
npm install --force

- name: Run npm tests
working-directory: ./src/documentcloud/blocks # Run npm tests from the blocks folder
run: |
npm run test

- name: Cleanup
if: ${{ always() }}
uses: rtCamp/action-cleanup@master
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
.DS_Store

# WordPress Dev Environment
src/wordpress
src/wordpress

# Composer
**/vendor

# Testing
.phpunit.cache
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM php:8.2-cli

# Install required tools and extensions
RUN apt-get update && apt-get install -y \
git \
unzip \
curl \
subversion \
default-mysql-client \
&& docker-php-ext-install mysqli

# Install NPM and Node.js
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs
RUN npm install -g npm@latest

# Install Xdebug for coverage
RUN pecl install xdebug && docker-php-ext-enable xdebug

# Configure Xdebug
RUN echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer

# Set working directory
WORKDIR /var/www/html

# Install PHPUnit
RUN composer require --dev phpunit/phpunit:^9 --no-interaction

# Add composer bin directory to PATH
ENV PATH="/var/www/html/vendor/bin:${PATH}"

# Copy the local WordPress test suite installer script
COPY ./bin/install-wp-tests.sh /usr/local/bin/install-wp-tests.sh
RUN chmod +x /usr/local/bin/install-wp-tests.sh
75 changes: 71 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The DocumentCloud WordPress plugin lets you embed [DocumentCloud](https://www.do

## Installation

1. Upload the contents of the plugin to `wp-content/plugins/documentcloud`
1. Upload the contents of the `src/documentcloud` plugin to `wp-content/plugins/documentcloud`
2. Activate the plugin through the "Plugins" menu
3. In your posts, embed documents, pages, or notes using the DocumentCloud button or the `[documentcloud]` shortcode
4. Optional: Set a default width/height for all DocumentCloud embeds (which can be overridden on a per-embed basis with the `height/width` attributes) at Settings > DocumentCloud. (This default width will only be used if you set `responsive="false"` on an embed.)
Expand Down Expand Up @@ -69,6 +69,24 @@ Here's the full list of embed options you can pass via shortcode attributes; som
- `zoom` (boolean): Hide or show zoom slider.
- `format` (string): Indicate to the theme that this is a wide asset by setting this to `wide`. Defaults `normal`.

Or as a Gutenberg Block :

DocumentCloud
Icon - ![DocumentCloud Block Icon](assets/DocumentCloud-Block-Icon.svg)

Here's the list of settings that can be used for the block:
- `WIDTH` (number): Sets the width of the document (optional)
- `HEIGHT` (number): Sets the height of the document (optional)
- `STYLE` (string): Adds additional style to the embedded document (optional)

The following options can only be used for Documents:
- `Show Title` (toggle): Determines whether to show the title of the embedded document
- `Show FullScreen Button` (toggle): Determines whether to show a full screen icon on the document
- `Only Show Organization` (toggle): Determines whether to only show the organization name that published the document.
- `Show PDF Download Link` (toggle): Determines whether to show the download as pdf icon for documents.

**Note** - The default width and height from the Settings does not work for the Gutenberg Block.

You can read more about publishing and embedding DocumentCloud resources on https://www.documentcloud.org/help/publishing.

## How the oEmbed endpoint is discovered
Expand All @@ -88,23 +106,72 @@ If you find yourself absolutely needing to expire the cache, though, you have tw

## Development

Plugin files are located in `src/documentcloud`

Docker is used to spin up a development and testing WordPress environment.

Unit tests are setup using PHPUnit and Jest, please refer to [Testing Setup ](./TESTING.md) for the setup steps

### Install

```sh
# Start services
docker compose up

# Fix permissions
docker-compose exec wordpress chown -R www-data:www-data /var/www/html
docker compose exec wordpress chown -R www-data:www-data /var/www/html
```

1. Go to `localhost:8000`
1. Go to [`localhost:8000`](http://localhost:8000)
2. Create an account. Save the username and password, then log in.
3. Go to the Plugins section, then activate the "Classic Editor" and "DocumentCloud" plugins.
3. Go to the Plugins section, then activate the "DocumentCloud" plugin.

### Test

Tests can be run in a separate container called `testing`.

To test the PHP plugin, use `phpunit` command inside the testing container's `bash` shell after setting it up:

```sh
# 1. Open a shell into the testing service
docker compose exec -it testing bash

# 2. Install the WordPress Test Suite anytime you rebuild the container
./bin/install-wp-tests.sh test root password db latest

# 3. Now the container is ready to run PHPUnit Tests
phpunit
```

To test the JS Gutenberg block, use `npm test` command inside the testing container's `bash` shell after setting it up:

```sh
# 1. Open a shell into the testing service
docker compose exec -it testing bash

# 2. Navigate to the blocks directory
cd src/documentcloud/blocks

# 3. Install Node modules
npm i

# 4. Now the container is ready to run Jest tests
npm test
```

Find more advanced instructions in `TESTING.md`

## Changelog

### 0.6.0
* Add Gutenberg block for embedding DocumentCloud documents resonating a functionality similar to the shortcode.
* Update the shortcode to support the following attributes
* `onlyshoworg` - When set to 1 it only displays the organization name
* `pdf` - When set to 1 it shows a pdf download icon
* `showfullscreen` - When set to 1 it displays a full screen icon.
* `title` - When set to 1 it displays the title of the document.
* Allow setting the query parameter attributes when directly embedding the url in Embed block.

### 0.5.1

* Expand regex support to catch more DocumentCloud URLs
Expand Down
Loading