Skip to content

Commit 27f6917

Browse files
authored
Merge pull request #3 from MuckRock/rtcamp
Applies changes from rtCamp
2 parents d4e5ae0 + 6657ac4 commit 27f6917

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+23357
-123
lines changed

.circleci/config.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
workflows:
2+
version: 2
3+
main:
4+
jobs:
5+
- php56-build
6+
- php70-build
7+
- php71-build
8+
- php72-build
9+
- php73-build
10+
- php74-build
11+
12+
version: 2
13+
14+
job-references:
15+
mysql_image: &mysql_image
16+
circleci/mysql:5.6
17+
18+
setup_environment: &setup_environment
19+
name: "Setup Environment Variables"
20+
command: |
21+
echo "export PATH=$HOME/.composer/vendor/bin:$PATH" >> $BASH_ENV
22+
source /home/circleci/.bashrc
23+
24+
install_dependencies: &install_dependencies
25+
name: "Install Dependencies"
26+
command: |
27+
sudo apt-get update && sudo apt-get install subversion
28+
sudo -E docker-php-ext-install mysqli
29+
sudo sh -c "printf '\ndeb http://ftp.us.debian.org/debian sid main\n' >> /etc/apt/sources.list"
30+
sudo apt-get update && sudo apt-get install mysql-client-5.7
31+
32+
php_job: &php_job
33+
environment:
34+
- WP_TESTS_DIR: "/tmp/wordpress-tests-lib"
35+
- WP_CORE_DIR: "/tmp/wordpress/"
36+
steps:
37+
- checkout
38+
- run: *setup_environment
39+
- run: *install_dependencies
40+
- run:
41+
name: "Run Tests"
42+
command: |
43+
composer global require "phpunit/phpunit=5.7.*"
44+
composer global require wp-coding-standards/wpcs
45+
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
46+
phpcs
47+
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
48+
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
49+
phpunit
50+
WP_MULTISITE=1 phpunit
51+
52+
jobs:
53+
php56-build:
54+
<<: *php_job
55+
docker:
56+
- image: circleci/php:5.6
57+
- image: *mysql_image
58+
steps:
59+
- checkout
60+
- run: *setup_environment
61+
- run: *install_dependencies
62+
- run:
63+
name: "Run Tests"
64+
command: |
65+
composer global require "phpunit/phpunit=5.7.*"
66+
composer global require wp-coding-standards/wpcs
67+
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
68+
phpcs
69+
SKIP_DB_CREATE=false
70+
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
71+
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 3.5 $SKIP_DB_CREATE
72+
phpunit
73+
WP_MULTISITE=1 phpunit
74+
SKIP_DB_CREATE=true
75+
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
76+
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest $SKIP_DB_CREATE
77+
phpunit
78+
WP_MULTISITE=1 phpunit
79+
SKIP_DB_CREATE=true
80+
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
81+
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 trunk $SKIP_DB_CREATE
82+
phpunit
83+
WP_MULTISITE=1 phpunit
84+
SKIP_DB_CREATE=true
85+
86+
php70-build:
87+
<<: *php_job
88+
docker:
89+
- image: circleci/php:7.0
90+
- image: *mysql_image
91+
92+
php71-build:
93+
<<: *php_job
94+
docker:
95+
- image: circleci/php:7.1
96+
- image: *mysql_image
97+
98+
php72-build:
99+
<<: *php_job
100+
docker:
101+
- image: circleci/php:7.2
102+
- image: *mysql_image
103+
104+
php73-build:
105+
<<: *php_job
106+
docker:
107+
- image: circleci/php:7.3
108+
- image: *mysql_image
109+
110+
php74-build:
111+
<<: *php_job
112+
docker:
113+
- image: circleci/php:7.4
114+
- image: *mysql_image

.github/workflows/unit_tests.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Unit Tests
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
test-wp:
7+
name: Test WordPress Plugin
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
13+
wp-version: ['6.6', '6.7', 'latest']
14+
include:
15+
- php-version: '7.4'
16+
php-image: php:7.4-cli
17+
- php-version: '8.0'
18+
php-image: php:8.0-cli
19+
- php-version: '8.1'
20+
php-image: php:8.1-cli
21+
- php-version: '8.2'
22+
php-image: php:8.2-cli
23+
- php-version: '8.3'
24+
php-image: php:8.3-cli
25+
26+
container:
27+
image: ${{ matrix.php-image }}
28+
options: --user root
29+
30+
services:
31+
mysql:
32+
image: mysql:5.7
33+
env:
34+
MYSQL_DATABASE: wordpress_test
35+
MYSQL_ROOT_PASSWORD: root
36+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Install tools and PHP extensions
42+
run: |
43+
apt-get update && apt-get install -y unzip git curl subversion default-mysql-client
44+
docker-php-ext-install mysqli
45+
if [ "${{ matrix.php-version }}" != "7.4" ]; then pecl install xdebug; fi
46+
if [ "${{ matrix.php-version }}" != "7.4" ]; then docker-php-ext-enable xdebug; fi
47+
48+
- name: Configure Xdebug for coverage
49+
if: ${{ matrix.php-version != '7.4' }}
50+
run: |
51+
echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
52+
echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
53+
echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
54+
55+
- name: Install Composer
56+
run: |
57+
curl -sS https://getcomposer.org/installer | php
58+
mv composer.phar /usr/local/bin/composer
59+
60+
- name: Install dependencies
61+
run: |
62+
if [ "${{ matrix.php-version }}" = "7.4" ]; then composer require phpunit/phpunit:^9 --no-update --no-interaction; fi
63+
if [ "${{ matrix.php-version }}" = "8.0" ] || [ "${{ matrix.php-version }}" = "8.1" ]; then composer require phpunit/phpunit:^9 --no-update --no-interaction; fi
64+
composer update --no-interaction
65+
66+
- name: Install WP test suite
67+
run: |
68+
mysql -u root -proot -h mysql -P 3306 -e "DROP DATABASE IF EXISTS wordpress_test;"
69+
bash ./bin/install-wp-tests.sh wordpress_test root 'root' mysql ${{ matrix.wp-version }}
70+
71+
- name: Run PHPUnit with coverage
72+
run: |
73+
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
74+
75+
- name: Cleanup
76+
if: ${{ always() }}
77+
uses: rtCamp/action-cleanup@master
78+
test-npm:
79+
name: Test Blocks
80+
runs-on: ubuntu-latest
81+
82+
container:
83+
image: node:20
84+
options: --user root
85+
86+
steps:
87+
- uses: actions/checkout@v4
88+
89+
- name: Install npm dependencies
90+
working-directory: ./src/documentcloud/blocks # Run npm commands from the blocks folder
91+
run: |
92+
npm install --force
93+
94+
- name: Run npm tests
95+
working-directory: ./src/documentcloud/blocks # Run npm tests from the blocks folder
96+
run: |
97+
npm run test
98+
99+
- name: Cleanup
100+
if: ${{ always() }}
101+
uses: rtCamp/action-cleanup@master

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
.DS_Store
33

44
# WordPress Dev Environment
5-
src/wordpress
5+
src/wordpress
6+
7+
# Composer
8+
**/vendor
9+
10+
# Testing
11+
.phpunit.cache

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM php:8.2-cli
2+
3+
# Install required tools and extensions
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
unzip \
7+
curl \
8+
subversion \
9+
default-mysql-client \
10+
&& docker-php-ext-install mysqli
11+
12+
# Install NPM and Node.js
13+
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - && \
14+
apt-get install -y nodejs
15+
RUN npm install -g npm@latest
16+
17+
# Install Xdebug for coverage
18+
RUN pecl install xdebug && docker-php-ext-enable xdebug
19+
20+
# Configure Xdebug
21+
RUN echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
22+
&& echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
23+
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
24+
25+
# Install Composer
26+
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
27+
28+
# Set working directory
29+
WORKDIR /var/www/html
30+
31+
# Install PHPUnit
32+
RUN composer require --dev phpunit/phpunit:^9 --no-interaction
33+
34+
# Add composer bin directory to PATH
35+
ENV PATH="/var/www/html/vendor/bin:${PATH}"
36+
37+
# Copy the local WordPress test suite installer script
38+
COPY ./bin/install-wp-tests.sh /usr/local/bin/install-wp-tests.sh
39+
RUN chmod +x /usr/local/bin/install-wp-tests.sh

README.md

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The DocumentCloud WordPress plugin lets you embed [DocumentCloud](https://www.do
66

77
## Installation
88

9-
1. Upload the contents of the plugin to `wp-content/plugins/documentcloud`
9+
1. Upload the contents of the `src/documentcloud` plugin to `wp-content/plugins/documentcloud`
1010
2. Activate the plugin through the "Plugins" menu
1111
3. In your posts, embed documents, pages, or notes using the DocumentCloud button or the `[documentcloud]` shortcode
1212
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.)
@@ -69,6 +69,24 @@ Here's the full list of embed options you can pass via shortcode attributes; som
6969
- `zoom` (boolean): Hide or show zoom slider.
7070
- `format` (string): Indicate to the theme that this is a wide asset by setting this to `wide`. Defaults `normal`.
7171

72+
Or as a Gutenberg Block :
73+
74+
DocumentCloud
75+
Icon - ![DocumentCloud Block Icon](assets/DocumentCloud-Block-Icon.svg)
76+
77+
Here's the list of settings that can be used for the block:
78+
- `WIDTH` (number): Sets the width of the document (optional)
79+
- `HEIGHT` (number): Sets the height of the document (optional)
80+
- `STYLE` (string): Adds additional style to the embedded document (optional)
81+
82+
The following options can only be used for Documents:
83+
- `Show Title` (toggle): Determines whether to show the title of the embedded document
84+
- `Show FullScreen Button` (toggle): Determines whether to show a full screen icon on the document
85+
- `Only Show Organization` (toggle): Determines whether to only show the organization name that published the document.
86+
- `Show PDF Download Link` (toggle): Determines whether to show the download as pdf icon for documents.
87+
88+
**Note** - The default width and height from the Settings does not work for the Gutenberg Block.
89+
7290
You can read more about publishing and embedding DocumentCloud resources on https://www.documentcloud.org/help/publishing.
7391

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

89107
## Development
90108

109+
Plugin files are located in `src/documentcloud`
110+
91111
Docker is used to spin up a development and testing WordPress environment.
92112

113+
Unit tests are setup using PHPUnit and Jest, please refer to [Testing Setup ](./TESTING.md) for the setup steps
114+
93115
### Install
94116

95117
```sh
96118
# Start services
97119
docker compose up
120+
98121
# Fix permissions
99-
docker-compose exec wordpress chown -R www-data:www-data /var/www/html
122+
docker compose exec wordpress chown -R www-data:www-data /var/www/html
100123
```
101124

102-
1. Go to `localhost:8000`
125+
1. Go to [`localhost:8000`](http://localhost:8000)
103126
2. Create an account. Save the username and password, then log in.
104-
3. Go to the Plugins section, then activate the "Classic Editor" and "DocumentCloud" plugins.
127+
3. Go to the Plugins section, then activate the "DocumentCloud" plugin.
128+
129+
### Test
130+
131+
Tests can be run in a separate container called `testing`.
132+
133+
To test the PHP plugin, use `phpunit` command inside the testing container's `bash` shell after setting it up:
134+
135+
```sh
136+
# 1. Open a shell into the testing service
137+
docker compose exec -it testing bash
138+
139+
# 2. Install the WordPress Test Suite anytime you rebuild the container
140+
./bin/install-wp-tests.sh test root password db latest
141+
142+
# 3. Now the container is ready to run PHPUnit Tests
143+
phpunit
144+
```
145+
146+
To test the JS Gutenberg block, use `npm test` command inside the testing container's `bash` shell after setting it up:
147+
148+
```sh
149+
# 1. Open a shell into the testing service
150+
docker compose exec -it testing bash
151+
152+
# 2. Navigate to the blocks directory
153+
cd src/documentcloud/blocks
154+
155+
# 3. Install Node modules
156+
npm i
157+
158+
# 4. Now the container is ready to run Jest tests
159+
npm test
160+
```
161+
162+
Find more advanced instructions in `TESTING.md`
105163

106164
## Changelog
107165

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

110177
* Expand regex support to catch more DocumentCloud URLs

0 commit comments

Comments
 (0)