Compress JPEG & PNG images - Version 2.2.2

Version Description

  • Improved robustness in case an unexpected network error occurs.
  • Fixed false positive warning with Sucuri scanner.
  • Fixed compression issue for fopen users.
Download this release

Release Info

Developer TinyPNG
Plugin Icon 128x128 Compress JPEG & PNG images
Version 2.2.2
Comparing to
See all releases

Code changes from version 2.2.1 to 2.2.2

Files changed (81) hide show
  1. .gitignore +1 -0
  2. README.md +0 -64
  3. RELEASE +0 -18
  4. composer.lock +4 -4
  5. composer.phar +0 -0
  6. config/Dockerfile-mock-webservice +0 -5
  7. config/Dockerfile-phantomjs +0 -5
  8. config/Dockerfile-wordpress-30 +0 -17
  9. config/Dockerfile-wordpress-31 +0 -17
  10. config/Dockerfile-wordpress-32 +0 -17
  11. config/Dockerfile-wordpress-33 +0 -20
  12. config/Dockerfile-wordpress-34 +0 -17
  13. config/Dockerfile-wordpress-35 +0 -17
  14. config/Dockerfile-wordpress-36 +0 -17
  15. config/Dockerfile-wordpress-37 +0 -17
  16. config/Dockerfile-wordpress-38 +0 -17
  17. config/Dockerfile-wordpress-39 +0 -15
  18. config/Dockerfile-wordpress-40 +0 -15
  19. config/Dockerfile-wordpress-41 +0 -15
  20. config/Dockerfile-wordpress-42 +0 -15
  21. config/Dockerfile-wordpress-43 +0 -15
  22. config/Dockerfile-wordpress-44 +0 -15
  23. config/Dockerfile-wordpress-45 +0 -15
  24. config/Dockerfile-wordpress-46 +0 -15
  25. config/Dockerfile-wordpress-47 +0 -15
  26. config/mysql/additional.cnf +0 -3
  27. docker-compose.yml +0 -45
  28. readme.txt +6 -1
  29. src/class-tiny-plugin.php +1 -1
  30. src/class-tiny-settings.php +2 -2
  31. src/vendor/tinify/Tinify.php +1 -1
  32. src/vendor/tinify/Tinify/Client.php +65 -53
  33. test/fixtures/Client.php +0 -119
  34. test/fixtures/input-copyright.jpg +0 -0
  35. test/fixtures/input-example.gif +0 -0
  36. test/fixtures/input-example.jpg +0 -0
  37. test/fixtures/input-example.pdf +0 -0
  38. test/fixtures/input-example.png +0 -0
  39. test/fixtures/json/_wp_attachment_metadata.json +0 -33
  40. test/fixtures/json/_wp_attachment_metadata_duplicates.json +0 -51
  41. test/fixtures/json/image_database_metadata.json +0 -49
  42. test/fixtures/json/image_filesystem_data.json +0 -22
  43. test/fixtures/testca.key +0 -27
  44. test/fixtures/testca.pem +0 -23
  45. test/fixtures/tiny-config.php +0 -11
  46. test/helpers/mock-http-stream-wrapper.php +0 -98
  47. test/helpers/mock-tinify-client.php +0 -50
  48. test/helpers/setup.php +0 -214
  49. test/helpers/wordpress.php +0 -245
  50. test/integration/BulkOptimizationIntegrationTest.php +0 -84
  51. test/integration/CompressIntegrationTest.php +0 -358
  52. test/integration/DashboardWidgetIntegrationTest.php +0 -72
  53. test/integration/IntegrationTestCase.php +0 -170
  54. test/integration/PluginIntegrationTest.php +0 -41
  55. test/integration/SettingsIntegrationTest.php +0 -293
  56. test/mock-tinypng-webservice/.htaccess +0 -5
  57. test/mock-tinypng-webservice/common.php +0 -50
  58. test/mock-tinypng-webservice/keys.php +0 -14
  59. test/mock-tinypng-webservice/output-copyright.jpg +0 -0
  60. test/mock-tinypng-webservice/output-example.jpg +0 -0
  61. test/mock-tinypng-webservice/output-example.png +0 -0
  62. test/mock-tinypng-webservice/output-resized.jpg +0 -0
  63. test/mock-tinypng-webservice/output.php +0 -50
  64. test/mock-tinypng-webservice/reset.php +0 -4
  65. test/mock-tinypng-webservice/shrink.php +0 -133
  66. test/unit/TinyCompressClientTest.php +0 -48
  67. test/unit/TinyCompressFopenTest.php +0 -33
  68. test/unit/TinyCompressNoClientTest.php +0 -15
  69. test/unit/TinyCompressSharedTestCase.php +0 -304
  70. test/unit/TinyCompressTest.php +0 -20
  71. test/unit/TinyExceptionTest.php +0 -25
  72. test/unit/TinyImageDuplicateTest.php +0 -70
  73. test/unit/TinyImageEmptyTest.php +0 -26
  74. test/unit/TinyImageSizeTest.php +0 -158
  75. test/unit/TinyImageTest.php +0 -137
  76. test/unit/TinyPluginTest.php +0 -210
  77. test/unit/TinySettingsTest.php +0 -281
  78. test/unit/TinyTestCase.php +0 -93
  79. test/unit/TinyWpBaseTest.php +0 -23
  80. test/wp-includes/version.php +0 -7
  81. tiny-compress-images.php +1 -1
.gitignore CHANGED
@@ -2,6 +2,7 @@
2
  *.bak
3
  /vendor
4
  .DS_Store
 
5
  /tmp/*
6
  !/tmp/.gitkeep
7
  /src/languages/
2
  *.bak
3
  /vendor
4
  .DS_Store
5
+ composer.phar
6
  /tmp/*
7
  !/tmp/.gitkeep
8
  /src/languages/
README.md DELETED
@@ -1,64 +0,0 @@
1
- [<img src="https://travis-ci.org/tinify/wordpress-plugin.svg?branch=master" alt="Build Status">](https://travis-ci.org/tinify/wordpress-plugin)
2
-
3
- # Compress JPEG & PNG images for WordPress
4
-
5
- Make your website faster by optimizing your JPEG and PNG images.
6
-
7
- This plugin automatically optimizes your images by integrating with the
8
- popular image compression services TinyJPG and TinyPNG. You can download the
9
- plugin from https://wordpress.org/plugins/tiny-compress-images/.
10
-
11
- Learn more about TinyJPG and TinyPNG at https://tinypng.com/.
12
-
13
- ## Contact us
14
-
15
- Got questions or feedback? Let us know! Contact us at support@tinypng.com.
16
-
17
- ## Information for plugin contributors
18
-
19
- ### Prerequisites
20
- * A working Docker 1.12+ and Docker Compose installation (https://docs.docker.com/installation/).
21
- * Composer (https://getcomposer.org/download/).
22
- * PhantomJS 2.1 or greater (http://phantomjs.org).
23
- * MySQL client and admin tools.
24
-
25
- ### Running the plugin in WordPress
26
- 1. Run `bin/run-wordpress <version>`. E.g. `bin/run-wordpress 45`.
27
- 2. Connect to Wordpress on port `80<version>` (e.g. port `8045`).
28
-
29
- ### Running the unit tests
30
- 1. Run `bin/unit-tests <optional path to file>`.
31
-
32
- ### Running the integration tests
33
- 1. Install Docker 1.12 and docker-compose.
34
- 2. Run `bin/integration-tests <version>`. E.g. `bin/integration-tests 45`.
35
-
36
- ### Translating the plugin
37
- Language packs will be generated for the plugin once translations for a
38
- language are 100% filled in and approved.
39
-
40
- See https://translate.wordpress.org/projects/wp-plugins/tiny-compress-images.
41
-
42
- For development you may create .po and .mo files for a each language. The .mo
43
- files can be created with [gettext](https://www.gnu.org/software/gettext/).
44
- Install gettext and generate the .mo language file do the following:
45
-
46
- 1. Install gettext for example run `brew install gettext`.
47
- 2. Add a link msgfmt `ln -s /usr/local/Cellar/gettext/0.19.7/bin/msgfmt ~/.bin`.
48
- 3. Generate the .mo files `bin/format-language-files`.
49
-
50
- ## License
51
-
52
- Copyright (C) 2015-2017 Voormedia B.V.
53
-
54
- This program is free software; you can redistribute it and/or modify
55
- it under the terms of the GNU General Public License as published by
56
- the Free Software Foundation; either version 2 of the License, or
57
- (at your option) any later version.
58
-
59
- This program is distributed in the hope that it will be useful,
60
- but WITHOUT ANY WARRANTY; without even the implied warranty of
61
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62
- GNU General Public License for more details.
63
-
64
- [View the complete license](LICENSE).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RELEASE DELETED
@@ -1,18 +0,0 @@
1
- In order to release a new version of the plugin to wordpress.org, perform the following steps:
2
-
3
- 1. Update the version in tiny-compress-images.php and src/class-tiny-plugin.php
4
- 2. Change the 'Stable tag' in readme.txt to the new release number.
5
- 3. Add release notes to readme.txt.
6
- 4. If you've changed the plugin to work with newer version of WordPress add that to the readme.txt as well.
7
- 5. Commit and push to GitHub.
8
- 6. Create a new release in GitHub and pull it in.
9
- 7. Locally, checkout the new tag: `git checkout <tagged version>`.
10
- 8. If not already done so, checkout the plugin's Subversion repository: `svn co http://plugins.svn.wordpress.org/tiny-compress-images`.
11
- 9. Run `svn update` when the Subversion repository already existed.
12
- 10. Update svn:ignore property of trunk when .gitignore is updated: `svn propedit svn:ignore trunk`. Make sure src/vendor/* is NOT ignored in SVN.
13
- 11. Delete everything in trunk `rm -rf <path-to-local-svn-repo/trunk/*`.
14
- 12. Manually copy the Git release to the local Subversion repo: `git ls-files | xargs tar c | tar x -C <path-to-local-svn-repo>/trunk/`.
15
- 13. Add new files `svn st | awk '/^\?/ { print $2; }' | xargs svn add`.
16
- 14. Delete deleted files: `svn st | awk '/^!/ { print $2; }' | xargs svn rm`.
17
- 15. Commit the trunk to Subversion: `svn ci -m "<message>"`.
18
- 16. Tag the new release in Subversion and commit: `svn cp trunk tags/<version> && svn ci -m "<message>"`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
composer.lock CHANGED
@@ -1352,12 +1352,12 @@
1352
  "source": {
1353
  "type": "git",
1354
  "url": "https://github.com/tinify/tinify-php.git",
1355
- "reference": "fe7e745121eefe4d281e588cf6f2ed933d00dbac"
1356
  },
1357
  "dist": {
1358
  "type": "zip",
1359
- "url": "https://api.github.com/repos/tinify/tinify-php/zipball/fe7e745121eefe4d281e588cf6f2ed933d00dbac",
1360
- "reference": "fe7e745121eefe4d281e588cf6f2ed933d00dbac",
1361
  "shasum": ""
1362
  },
1363
  "require": {
@@ -1404,7 +1404,7 @@
1404
  "source": "https://github.com/tinify/tinify-php/tree/create-key",
1405
  "issues": "https://github.com/tinify/tinify-php/issues"
1406
  },
1407
- "time": "2017-01-19 10:34:17"
1408
  },
1409
  {
1410
  "name": "wp-coding-standards/wpcs",
1352
  "source": {
1353
  "type": "git",
1354
  "url": "https://github.com/tinify/tinify-php.git",
1355
+ "reference": "45e79fee561f6264dfa10f423a121a1a5293089a"
1356
  },
1357
  "dist": {
1358
  "type": "zip",
1359
+ "url": "https://api.github.com/repos/tinify/tinify-php/zipball/45e79fee561f6264dfa10f423a121a1a5293089a",
1360
+ "reference": "45e79fee561f6264dfa10f423a121a1a5293089a",
1361
  "shasum": ""
1362
  },
1363
  "require": {
1404
  "source": "https://github.com/tinify/tinify-php/tree/create-key",
1405
  "issues": "https://github.com/tinify/tinify-php/issues"
1406
  },
1407
+ "time": "2017-02-24 09:07:29"
1408
  },
1409
  {
1410
  "name": "wp-coding-standards/wpcs",
composer.phar DELETED
Binary file
config/Dockerfile-mock-webservice DELETED
@@ -1,5 +0,0 @@
1
- FROM php:5.6-apache
2
-
3
- EXPOSE 80 443
4
-
5
- RUN a2enmod rewrite
 
 
 
 
 
config/Dockerfile-phantomjs DELETED
@@ -1,5 +0,0 @@
1
- FROM wernight/phantomjs:2
2
-
3
- EXPOSE 8910
4
-
5
- CMD ["phantomjs", "--webdriver=8910"]
 
 
 
 
 
config/Dockerfile-wordpress-30 DELETED
@@ -1,17 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.0.6
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.0.6
7
- ENV WORDPRESS_SHA1 f75f2e74a80213608c798add216d137c7dfbd86a
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- ENTRYPOINT ["docker-entrypoint.sh"]
17
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-31 DELETED
@@ -1,17 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.1.4
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.1.4
7
- ENV WORDPRESS_SHA1 b93ff680a7035378abac1063abebf72a473e8a78
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- ENTRYPOINT ["docker-entrypoint.sh"]
17
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-32 DELETED
@@ -1,17 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.2.1
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.2.1
7
- ENV WORDPRESS_SHA1 674bcf0abe80770ac08dfb4c5f21df3303bf771a
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- ENTRYPOINT ["docker-entrypoint.sh"]
17
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-33 DELETED
@@ -1,20 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.3.3
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.3.3
7
- ENV WORDPRESS_SHA1 ea7c91903df3090d8e90ef4e26945def46437a37
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- # Fix empty dashboard bug (http://wordpress.stackexchange.com/questions/127427/how-to-fix-empty-dashboard-issue-in-wordpress).
17
- RUN sed -i '706s/self::$this/$this/' /usr/src/wordpress/wp-admin/includes/screen.php
18
-
19
- ENTRYPOINT ["docker-entrypoint.sh"]
20
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-34 DELETED
@@ -1,17 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.4.2
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.4.2
7
- ENV WORDPRESS_SHA1 11d130c06ba9c55e7aa80c04c249a4f1b19accd6
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- ENTRYPOINT ["docker-entrypoint.sh"]
17
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-35 DELETED
@@ -1,17 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.5.2
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.5.2
7
- ENV WORDPRESS_SHA1 f75e9aadb1c2f754e89aacdfb5ab72bbfb10678d
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- ENTRYPOINT ["docker-entrypoint.sh"]
17
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-36 DELETED
@@ -1,17 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.6.1
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.6.1
7
- ENV WORDPRESS_SHA1 a1ad687776a9348e85b9f9603b4d227e433ef697
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- ENTRYPOINT ["docker-entrypoint.sh"]
17
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-37 DELETED
@@ -1,17 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.7.13
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.7.13
7
- ENV WORDPRESS_SHA1 24759237f867b284f2bad1154eaff6362a81512f
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- ENTRYPOINT ["docker-entrypoint.sh"]
17
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-38 DELETED
@@ -1,17 +0,0 @@
1
- FROM wordpress:4
2
-
3
- RUN docker-php-ext-install mysql
4
-
5
- ENV WORDPRESS_VERSION 3.8.13
6
- ENV WORDPRESS_UPSTREAM_VERSION 3.8.13
7
- ENV WORDPRESS_SHA1 9fc98b9ee30f9437984e1bbef96d75d6c23e6950
8
-
9
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
10
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
11
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
12
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
13
- && rm wordpress.tar.gz \
14
- && chown -R www-data:www-data /usr/src/wordpress
15
-
16
- ENTRYPOINT ["docker-entrypoint.sh"]
17
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-39 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 3.9.11
4
- ENV WORDPRESS_UPSTREAM_VERSION 3.9.11
5
- ENV WORDPRESS_SHA1 8af7829f203cd410d9946f736324ca154b987389
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-40 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 4.0.10
4
- ENV WORDPRESS_UPSTREAM_VERSION 4.0.10
5
- ENV WORDPRESS_SHA1 a9e4d8cd92e211d55b40de3afd09efc5068ad483
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-41 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 4.1.10
4
- ENV WORDPRESS_UPSTREAM_VERSION 4.1.10
5
- ENV WORDPRESS_SHA1 dae2e813e0f824c12d3c79df8f5783bc7fa9e312
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-42 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 4.2.7
4
- ENV WORDPRESS_UPSTREAM_VERSION 4.2.7
5
- ENV WORDPRESS_SHA1 7e39a7cfc93ef54e02b91e4d9344040911f4128f
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-43 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 4.3.3
4
- ENV WORDPRESS_UPSTREAM_VERSION 4.3.3
5
- ENV WORDPRESS_SHA1 bf7a9281762e978712c6ab64ffdf64523abd6a33
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-44 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 4.4.2
4
- ENV WORDPRESS_UPSTREAM_VERSION 4.4.2
5
- ENV WORDPRESS_SHA1 7444099fec298b599eb026e83227462bcdf312a6
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-45 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 4.5.3
4
- ENV WORDPRESS_UPSTREAM_VERSION 4.5.3
5
- ENV WORDPRESS_SHA1 835b68748dae5a9d31c059313cd0150f03a49269
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-46 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 4.6
4
- ENV WORDPRESS_UPSTREAM_VERSION 4.6
5
- ENV WORDPRESS_SHA1 830962689f350e43cd1a069f3a4f68a44c0339c8
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/Dockerfile-wordpress-47 DELETED
@@ -1,15 +0,0 @@
1
- FROM wordpress:4
2
-
3
- ENV WORDPRESS_VERSION 4.7
4
- ENV WORDPRESS_UPSTREAM_VERSION 4.7
5
- ENV WORDPRESS_SHA1 1e14144c4db71421dc4ed22f94c3914dfc3b7020
6
-
7
- # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8
- RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
9
- && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
10
- && tar -xzf wordpress.tar.gz -C /usr/src/ \
11
- && rm wordpress.tar.gz \
12
- && chown -R www-data:www-data /usr/src/wordpress
13
-
14
- ENTRYPOINT ["docker-entrypoint.sh"]
15
- CMD ["apache2-foreground"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config/mysql/additional.cnf DELETED
@@ -1,3 +0,0 @@
1
- [mysqld]
2
- # Required for WordPress 3.8 and below.
3
- sql-mode="NO_ENGINE_SUBSTITUTION"
 
 
 
docker-compose.yml DELETED
@@ -1,45 +0,0 @@
1
- version: '2'
2
-
3
- services:
4
- wordpress:
5
- build:
6
- context: config
7
- dockerfile: Dockerfile-wordpress-${WORDPRESS_VERSION}
8
- ports:
9
- - 80${WORDPRESS_VERSION}:80
10
- volumes:
11
- - .:/var/www/html/wp-content/plugins/tiny-compress-images
12
- links:
13
- - mysql
14
- - phantomjs
15
- - webservice
16
- environment:
17
- WORDPRESS_DB_NAME: wordpress_${WORDPRESS_VERSION}
18
- WORDPRESS_DB_PASSWORD: root
19
-
20
- mysql:
21
- image: mysql
22
- ports:
23
- - 3306:3306
24
- volumes:
25
- - ./config/mysql:/etc/mysql/conf.d
26
- environment:
27
- MYSQL_ROOT_PASSWORD: root
28
-
29
- phantomjs:
30
- ports:
31
- - 8910:8910
32
- volumes:
33
- - ./test/fixtures:/test/fixtures
34
- build:
35
- context: config
36
- dockerfile: Dockerfile-phantomjs
37
-
38
- webservice:
39
- ports:
40
- - 80:80
41
- volumes:
42
- - ./test/mock-tinypng-webservice:/var/www/html
43
- build:
44
- context: config
45
- dockerfile: Dockerfile-mock-webservice
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://tinypng.com/
4
  Tags: optimize, compress, shrink, resize, faster, fit, scale, improve, images, tinypng, tinyjpg, jpeg, jpg, png, lossy, jpegmini, crunch, minify, smush, save, bandwidth, website, speed, performance, panda, wordpress app
5
  Requires at least: 3.0.6
6
  Tested up to: 4.7
7
- Stable tag: 2.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -110,6 +110,11 @@ A: Everything will keep on working, but newly uploaded images will not be optimi
110
  A: Yes! After installing the plugin, go to *Media > Bulk Optimization*, and click on the start button to optimize all unoptimized images in your media library.
111
 
112
  == Changelog ==
 
 
 
 
 
113
  = 2.2.1 =
114
  * Fixed an error that was introduced in v2.2.0 where all custom image sizes did not show up.
115
  * Added support for image sizes with unspecified height or width.
4
  Tags: optimize, compress, shrink, resize, faster, fit, scale, improve, images, tinypng, tinyjpg, jpeg, jpg, png, lossy, jpegmini, crunch, minify, smush, save, bandwidth, website, speed, performance, panda, wordpress app
5
  Requires at least: 3.0.6
6
  Tested up to: 4.7
7
+ Stable tag: 2.2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
110
  A: Yes! After installing the plugin, go to *Media > Bulk Optimization*, and click on the start button to optimize all unoptimized images in your media library.
111
 
112
  == Changelog ==
113
+ = 2.2.2 =
114
+ * Improved robustness in case an unexpected network error occurs.
115
+ * Fixed false positive warning with Sucuri scanner.
116
+ * Fixed compression issue for fopen users.
117
+
118
  = 2.2.1 =
119
  * Fixed an error that was introduced in v2.2.0 where all custom image sizes did not show up.
120
  * Added support for image sizes with unspecified height or width.
src/class-tiny-plugin.php CHANGED
@@ -18,7 +18,7 @@
18
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
  */
20
  class Tiny_Plugin extends Tiny_WP_Base {
21
- const VERSION = '2.2.1';
22
  const MEDIA_COLUMN = self::NAME;
23
  const DATETIME_FORMAT = 'Y-m-d G:i:s';
24
 
18
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
  */
20
  class Tiny_Plugin extends Tiny_WP_Base {
21
+ const VERSION = '2.2.2';
22
  const MEDIA_COLUMN = self::NAME;
23
  const DATETIME_FORMAT = 'Y-m-d G:i:s';
24
 
src/class-tiny-settings.php CHANGED
@@ -79,7 +79,7 @@ class Tiny_Settings extends Tiny_WP_Base {
79
  } else {
80
  $details .= ' without curl';
81
  }
82
- $message = printf(
83
  esc_html__(
84
  'You are using an outdated platform (%s) – some features are disabled',
85
  'tiny-compress-images'
@@ -221,7 +221,7 @@ class Tiny_Settings extends Tiny_WP_Base {
221
 
222
  /* Note: dimensions might be 0 to indicate no limit. */
223
  if ( $width || $height ) {
224
- return array( $width, $height );
225
  }
226
 
227
  if ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
79
  } else {
80
  $details .= ' without curl';
81
  }
82
+ $message = sprintf(
83
  esc_html__(
84
  'You are using an outdated platform (%s) – some features are disabled',
85
  'tiny-compress-images'
221
 
222
  /* Note: dimensions might be 0 to indicate no limit. */
223
  if ( $width || $height ) {
224
+ return array( $width, $height );
225
  }
226
 
227
  if ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
src/vendor/tinify/Tinify.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  namespace Tinify;
4
 
5
- const VERSION = "1.4.0";
6
 
7
  class Tinify {
8
  const AUTHENTICATED = true;
2
 
3
  namespace Tinify;
4
 
5
+ const VERSION = "1.5.0";
6
 
7
  class Tinify {
8
  const AUTHENTICATED = true;
src/vendor/tinify/Tinify/Client.php CHANGED
@@ -5,6 +5,9 @@ namespace Tinify;
5
  class Client {
6
  const API_ENDPOINT = "https://api.tinify.com";
7
 
 
 
 
8
  protected $options;
9
 
10
  public static function userAgent() {
@@ -64,73 +67,82 @@ class Client {
64
  }
65
  }
66
 
67
- $request = curl_init();
68
- if ($request === false || $request === null) {
69
- throw new ConnectionException(
70
- "Error while connecting: curl extension is not functional or disabled."
71
- );
72
- }
73
 
74
- curl_setopt_array($request, $this->options);
 
 
 
 
 
75
 
76
- $url = strtolower(substr($url, 0, 6)) == "https:" ? $url : self::API_ENDPOINT . $url;
77
- curl_setopt($request, CURLOPT_URL, $url);
78
- curl_setopt($request, CURLOPT_CUSTOMREQUEST, strtoupper($method));
79
 
80
- if (count($header) > 0) {
81
- curl_setopt($request, CURLOPT_HTTPHEADER, $header);
82
- }
83
 
84
- if ($body) {
85
- curl_setopt($request, CURLOPT_POSTFIELDS, $body);
86
- }
87
 
88
- $response = curl_exec($request);
 
 
89
 
90
- if (is_string($response)) {
91
- $status = curl_getinfo($request, CURLINFO_HTTP_CODE);
92
- $headerSize = curl_getinfo($request, CURLINFO_HEADER_SIZE);
93
- curl_close($request);
94
 
95
- $headers = self::parseHeaders(substr($response, 0, $headerSize));
96
- $body = substr($response, $headerSize);
 
 
97
 
98
- if (isset($headers["compression-count"])) {
99
- Tinify::setCompressionCount(intval($headers["compression-count"]));
100
- }
101
 
102
- $isJson = false;
103
- if (isset($headers["content-type"])) {
104
- /* Parse JSON response bodies. */
105
- list($contentType) = explode(";", $headers["content-type"], 2);
106
- if (strtolower(trim($contentType)) == "application/json") {
107
- $isJson = true;
108
  }
109
- }
110
 
111
- /* 1xx and 3xx are unexpected and will be treated as error. */
112
- $isError = $status <= 199 || $status >= 300;
113
-
114
- if ($isJson || $isError) {
115
- /* Parse JSON bodies, always interpret errors as JSON. */
116
- $body = json_decode($body);
117
- if (!$body) {
118
- $message = sprintf("Error while parsing response: %s (#%d)",
119
- PHP_VERSION_ID >= 50500 ? json_last_error_msg() : "Error",
120
- json_last_error());
121
- throw Exception::create($message, "ParseError", $status);
122
  }
123
- }
124
 
125
- if ($isError) {
126
- throw Exception::create($body->message, $body->error, $status);
127
- }
 
 
 
 
 
 
 
 
 
 
 
128
 
129
- return (object) array("body" => $body, "headers" => $headers);
130
- } else {
131
- $message = sprintf("%s (#%d)", curl_error($request), curl_errno($request));
132
- curl_close($request);
133
- throw new ConnectionException("Error while connecting: " . $message);
 
 
 
 
 
 
 
134
  }
135
  }
136
 
5
  class Client {
6
  const API_ENDPOINT = "https://api.tinify.com";
7
 
8
+ const RETRY_COUNT = 1;
9
+ const RETRY_DELAY = 500;
10
+
11
  protected $options;
12
 
13
  public static function userAgent() {
67
  }
68
  }
69
 
70
+ for ($retries = self::RETRY_COUNT; $retries >= 0; $retries--) {
71
+ if ($retries < self::RETRY_COUNT) {
72
+ usleep(self::RETRY_DELAY * 1000);
73
+ }
 
 
74
 
75
+ $request = curl_init();
76
+ if ($request === false || $request === null) {
77
+ throw new ConnectionException(
78
+ "Error while connecting: curl extension is not functional or disabled."
79
+ );
80
+ }
81
 
82
+ curl_setopt_array($request, $this->options);
 
 
83
 
84
+ $url = strtolower(substr($url, 0, 6)) == "https:" ? $url : self::API_ENDPOINT . $url;
85
+ curl_setopt($request, CURLOPT_URL, $url);
86
+ curl_setopt($request, CURLOPT_CUSTOMREQUEST, strtoupper($method));
87
 
88
+ if (count($header) > 0) {
89
+ curl_setopt($request, CURLOPT_HTTPHEADER, $header);
90
+ }
91
 
92
+ if ($body) {
93
+ curl_setopt($request, CURLOPT_POSTFIELDS, $body);
94
+ }
95
 
96
+ $response = curl_exec($request);
 
 
 
97
 
98
+ if (is_string($response)) {
99
+ $status = curl_getinfo($request, CURLINFO_HTTP_CODE);
100
+ $headerSize = curl_getinfo($request, CURLINFO_HEADER_SIZE);
101
+ curl_close($request);
102
 
103
+ $headers = self::parseHeaders(substr($response, 0, $headerSize));
104
+ $body = substr($response, $headerSize);
 
105
 
106
+ if (isset($headers["compression-count"])) {
107
+ Tinify::setCompressionCount(intval($headers["compression-count"]));
 
 
 
 
108
  }
 
109
 
110
+ $isJson = false;
111
+ if (isset($headers["content-type"])) {
112
+ /* Parse JSON response bodies. */
113
+ list($contentType) = explode(";", $headers["content-type"], 2);
114
+ if (strtolower(trim($contentType)) == "application/json") {
115
+ $isJson = true;
116
+ }
 
 
 
 
117
  }
 
118
 
119
+ /* 1xx and 3xx are unexpected and will be treated as error. */
120
+ $isError = $status <= 199 || $status >= 300;
121
+
122
+ if ($isJson || $isError) {
123
+ /* Parse JSON bodies, always interpret errors as JSON. */
124
+ $body = json_decode($body);
125
+ if (!$body) {
126
+ $message = sprintf("Error while parsing response: %s (#%d)",
127
+ PHP_VERSION_ID >= 50500 ? json_last_error_msg() : "Error",
128
+ json_last_error());
129
+ if ($retries > 0 && $status >= 500) continue;
130
+ throw Exception::create($message, "ParseError", $status);
131
+ }
132
+ }
133
 
134
+ if ($isError) {
135
+ if ($retries > 0 && $status >= 500) continue;
136
+ throw Exception::create($body->message, $body->error, $status);
137
+ }
138
+
139
+ return (object) array("body" => $body, "headers" => $headers);
140
+ } else {
141
+ $message = sprintf("%s (#%d)", curl_error($request), curl_errno($request));
142
+ curl_close($request);
143
+ if ($retries > 0) continue;
144
+ throw new ConnectionException("Error while connecting: " . $message);
145
+ }
146
  }
147
  }
148
 
test/fixtures/Client.php DELETED
@@ -1,119 +0,0 @@
1
- <?php
2
-
3
- namespace Tinify;
4
-
5
- class Client {
6
- const API_ENDPOINT = 'http://webservice';
7
-
8
- private $options;
9
-
10
- public static function userAgent() {
11
- $curl = curl_version();
12
- return 'Tinify/' . VERSION . ' PHP/' . PHP_VERSION . ' curl/' . $curl['version'];
13
- }
14
-
15
- private static function caBundle() {
16
- return __DIR__ . '/../data/cacert.pem';
17
- }
18
-
19
- function __construct( $key, $appIdentifier = null ) {
20
- $userAgent = join( ' ', array_filter( array( self::userAgent(), $appIdentifier ) ) );
21
- $this->options = array(
22
- CURLOPT_BINARYTRANSFER => true,
23
- CURLOPT_RETURNTRANSFER => true,
24
- CURLOPT_HEADER => true,
25
- CURLOPT_USERPWD => $key ? ('api:' . $key) : null,
26
- CURLOPT_USERAGENT => $userAgent,
27
- );
28
- }
29
-
30
- function request( $method, $url, $body = null, $header = array() ) {
31
- if ( is_array( $body ) ) {
32
- if ( ! empty( $body ) ) {
33
- $body = json_encode( $body );
34
- array_push( $header, 'Content-Type: application/json' );
35
- } else {
36
- $body = null;
37
- }
38
- }
39
-
40
- $request = curl_init();
41
- curl_setopt_array( $request, $this->options );
42
-
43
- $url = strtolower( substr( $url, 0, 5 ) ) == 'http:' ? $url : self::API_ENDPOINT . $url;
44
- curl_setopt( $request, CURLOPT_URL, $url );
45
- curl_setopt( $request, CURLOPT_HTTPHEADER, $header );
46
- curl_setopt( $request, CURLOPT_CUSTOMREQUEST, strtoupper( $method ) );
47
-
48
- if ( $body ) {
49
- curl_setopt( $request, CURLOPT_POSTFIELDS, $body );
50
- }
51
-
52
- $response = curl_exec( $request );
53
-
54
- if ( is_string( $response ) ) {
55
- $status = curl_getinfo( $request, CURLINFO_HTTP_CODE );
56
- $headerSize = curl_getinfo( $request, CURLINFO_HEADER_SIZE );
57
- curl_close( $request );
58
-
59
- $headers = self::parseHeaders( substr( $response, 0, $headerSize ) );
60
- $body = substr( $response, $headerSize );
61
-
62
- if ( isset( $headers['compression-count'] ) ) {
63
- Tinify::setCompressionCount( intval( $headers['compression-count'] ) );
64
- }
65
-
66
- $isJson = false;
67
- if ( isset( $headers['content-type'] ) ) {
68
- /* Parse JSON response bodies. */
69
- list($contentType) = explode( ';', $headers['content-type'], 2 );
70
- if ( strtolower( trim( $contentType ) ) == 'application/json' ) {
71
- $isJson = true;
72
- }
73
- }
74
-
75
- /* 1xx and 3xx are unexpected and will be treated as error. */
76
- $isError = $status <= 199 || $status >= 300;
77
-
78
- if ( $isJson || $isError ) {
79
- /* Parse JSON bodies, always interpret errors as JSON. */
80
- $body = json_decode( $body );
81
- if ( ! $body ) {
82
- $message = sprintf('Error while parsing response: %s (#%d)',
83
- PHP_VERSION_ID >= 50500 ? json_last_error_msg() : 'Error',
84
- json_last_error());
85
- throw Exception::create( $message, 'ParseError', $status );
86
- }
87
- }
88
-
89
- if ( $isError ) {
90
- throw Exception::create( $body->message, $body->error, $status );
91
- }
92
-
93
- return (object) array( 'body' => $body, 'headers' => $headers );
94
- } else {
95
- $message = sprintf( '%s (#%d)', curl_error( $request ), curl_errno( $request ) );
96
- curl_close( $request );
97
- throw new ConnectionException( 'Error while connecting: ' . $message );
98
- }
99
- }
100
-
101
- protected static function parseHeaders( $headers ) {
102
- if ( ! is_array( $headers ) ) {
103
- $headers = explode( "\r\n", $headers );
104
- }
105
-
106
- $result = array();
107
- foreach ( $headers as $header ) {
108
- if ( empty( $header ) ) {
109
- continue;
110
- }
111
-
112
- $split = explode( ':', $header, 2 );
113
- if ( count( $split ) === 2 ) {
114
- $result[ strtolower( $split[0] ) ] = trim( $split[1] );
115
- }
116
- }
117
- return $result;
118
- }
119
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/fixtures/input-copyright.jpg DELETED
Binary file
test/fixtures/input-example.gif DELETED
Binary file
test/fixtures/input-example.jpg DELETED
Binary file
test/fixtures/input-example.pdf DELETED
Binary file
test/fixtures/input-example.png DELETED
Binary file
test/fixtures/json/_wp_attachment_metadata.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "width": 1256,
3
- "height": 1256,
4
- "file": "2015/09/tinypng_gravatar.png",
5
- "sizes": {
6
- "small": {
7
- "file": "tinypng_gravatar-200x200.png",
8
- "width": 200,
9
- "height": 200,
10
- "mime-type": "image/png"
11
- },
12
- "medium": {
13
- "file": "tinypng_gravatar-300x300.png",
14
- "width": 300,
15
- "height": 300,
16
- "mime-type": "image/png"
17
- },
18
- "large": {
19
- "file": "tinypng_gravatar-600x600.png",
20
- "width": 600,
21
- "height": 600,
22
- "mime-type": "image/png"
23
- },
24
- "thumbnail": {
25
- "file": "tinypng_gravatar-150x150.png",
26
- "width": 150,
27
- "height": 150,
28
- "mime-type": "image/png"
29
- }
30
- },
31
- "image_meta": {
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/fixtures/json/_wp_attachment_metadata_duplicates.json DELETED
@@ -1,51 +0,0 @@
1
- {
2
- "width": 1256,
3
- "height": 1256,
4
- "file": "2015/09/tinypng_gravatar.png",
5
- "sizes": {
6
- "small": {
7
- "file": "tinypng_gravatar-200x200.png",
8
- "width": 200,
9
- "height": 200,
10
- "mime-type": "image/png"
11
- },
12
- "medium": {
13
- "file": "tinypng_gravatar-300x300.png",
14
- "width": 300,
15
- "height": 300,
16
- "mime-type": "image/png"
17
- },
18
- "medium-2": {
19
- "file": "tinypng_gravatar-300x300.png",
20
- "width": 300,
21
- "height": 300,
22
- "mime-type": "image/png"
23
- },
24
- "large": {
25
- "file": "tinypng_gravatar-600x600.png",
26
- "width": 600,
27
- "height": 600,
28
- "mime-type": "image/png"
29
- },
30
- "custom-thumbnail": {
31
- "file": "tinypng_gravatar-175x175.png",
32
- "width": 175,
33
- "height": 175,
34
- "mime-type": "image/png"
35
- },
36
- "custom-thumbnail-2": {
37
- "file": "tinypng_gravatar-175x175.png",
38
- "width": 175,
39
- "height": 175,
40
- "mime-type": "image/png"
41
- },
42
- "custom-thumbnail-3": {
43
- "file": "tinypng_gravatar-175x175.png",
44
- "width": 175,
45
- "height": 175,
46
- "mime-type": "image/png"
47
- }
48
- },
49
- "image_meta": {
50
- }
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/fixtures/json/image_database_metadata.json DELETED
@@ -1,49 +0,0 @@
1
- {
2
- "0": {
3
- "input": {
4
- "size": 146480
5
- },
6
- "output": {
7
- "size": 137856,
8
- "resized": true
9
- },
10
- "end": 1447925138,
11
- "start": 1447925134
12
- },
13
- "small": {
14
- "input": {
15
- "size": 66480
16
- },
17
- "start": 1447925134
18
- },
19
- "medium": {
20
- "input": {
21
- "size": 72480
22
- },
23
- "output": {
24
- "size": 57856
25
- }
26
- },
27
- "thumbnail": {
28
- "input": {
29
- "size": 46480
30
- },
31
- "output": {
32
- "size": 37856
33
- },
34
- "timestamp": 1437925244
35
- },
36
- "twentyfourteen-full-width": {
37
- "input": {
38
- "size": 139127
39
- },
40
- "output": {
41
- "size": 121873
42
- },
43
- "end": 1447925214
44
- },
45
- "failed": {
46
- "input": {
47
- }
48
- }
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/fixtures/json/image_filesystem_data.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "path": "2015/09",
3
- "images": [{
4
- "file": "tinypng_gravatar.png",
5
- "size": 137856
6
- }, {
7
- "file": "tinypng_gravatar-150x150.png",
8
- "size": 37856
9
- }, {
10
- "file": "tinypng_gravatar-200x200.png",
11
- "size": 66480
12
- }, {
13
- "file": "tinypng_gravatar-300x300.png",
14
- "size": 57856
15
- }, {
16
- "file": "tinypng_gravatar-600x600.png",
17
- "size": 95102
18
- }, {
19
- "file": "tinypng_gravatar-1038x576.png",
20
- "size": 121873
21
- }]
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/fixtures/testca.key DELETED
@@ -1,27 +0,0 @@
1
- -----BEGIN RSA PRIVATE KEY-----
2
- MIIEowIBAAKCAQEAv0RCmq3ohJg/4hQS7LexiDSIvRf5NgY/EhT7xCUPpxVGC63c
3
- abJ+5jP0GhicsoDqh0FzAwefZCQ55OU69OxLqaotqGb8cnsOAfFcXn4cx4L+AjEx
4
- bsfn+iVFALW5U9hVjq9BppIngfqEWV4Y11RWxJ3ZpGOIxvBUZNzNQwwFBbt0skTe
5
- Msgi/9+iBmyK7OX+wF9xP45wFQIc8fOMIyE88Aqn38S8OcIvVf9Qeil5LJ1N/EMk
6
- zmPptpybuQj+pJznE7LKI7fxv2qZ99NWVLETAQiQYDVAuV1fX6SGaN6gKEH0UDqL
7
- gg18T5MIjJXT5pk9jWwfgEIdZXufnY2Emo43PwIDAQABAoIBAAW/FkUxbmf1bw3q
8
- znrANhxCf802mC0wWNrBOKM2/dZmRDl7msCuNTPTYcUa8jJGv0UbCUqRAw/uKrMe
9
- 0/uh0dAiJccGeRUzb0NNrhnErjasT9dfBP4wEV8pmX4g95V2TXPA/jbz8y3riehp
10
- dFOb3BOCLpTKzMQ1WkPBgoU+KjR21QmuCrgUS/3vQGh96xRgrf9cEUDJ1d7GC3iG
11
- 5NtGs5VGl3wNhEdsN7apXK3lFlS+CJl4k+gs/UuEn4Luj/OVpSt1DI+X1vJ7j0Da
12
- 7eSNBIDpMTGZ61VFkXZbSWH+L+dFd64hqEZhz3ojRX45pN+tEkc+WVeB7YjkOvtv
13
- U/8wLqkCgYEA32yUbUxUeRd3uCudimgrgwg6jOuYa785NZXvwjUCJWB9z4H4y61V
14
- GYlt4Ik2c0Ld+EdgjAxec1Vzb26QKfG1PjZeMV5SsYyY76+kwLTnV+KhWkKHlfZH
15
- gfSRKriBKDhryxxZYS2C4qYc117F3NV9T0QDpM+DDS0P2XTZCxj3rpUCgYEA2ydi
16
- o9m1T+g+hiqYc4shaBT3b9pin8EO8z8anyIOFA2kaLrB4qUQfyCMUoY8tl2scCoB
17
- fb8sqnMdE+fpLd7FwfG24svYHS64/yDDfBQpzhw7gz3oT/yQokVnYcNnO64hcjF+
18
- 0iy+4norOKe/s0mK+EHJIm3A4MnO/fqjpYOlHYMCgYBz7W3ybFmkXzXiXNcomraB
19
- DcL7nb7/oT/4+uxls4WCiVeeVQ0X+b8fOfzGNcwH8FkmWzrQUBat91enKRIqgV0O
20
- g71KFmwH7jDopRVyXCtxoYkhQUYC3L/rwU+VgBicGvJreDE0SB4Spihu46D83dVg
21
- TKUrXfTc4FXJ+mQn6vORJQKBgDPs2QpJgxQzytyvKv/1byziCt6Nt+ByNcCcqwoZ
22
- X4yQzuuhlF7HDWmRpK3I8ImlGD5bNY89xK9+Jt2YjT85EVIqm1KRSdtgPqT0dlzn
23
- yh/zwIYQHQMWrI5GM4COc99IGtSbtZjG0VOH7sW1uU4ZlrvLmoR1zMV2C31R7YRB
24
- 9NVRAoGBAIWnhM1Fcy4kg5HCPtZrM1J8Ihr1FWPTWjbVir2l3SEIbfl4XNQ9wMXR
25
- zhlTV14dGBz11op/ZhWOPYYzxOa0OVEeQmLy7fusiel4poZE477ZAzHUa3AOQ9TZ
26
- QOjQn2NplAV4Tk/KnDZg8RvpI/wikEAbu7VZnAsBJXrxgEiDgQVs
27
- -----END RSA PRIVATE KEY-----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/fixtures/testca.pem DELETED
@@ -1,23 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIID0zCCArugAwIBAgIJAIbimBGoeNlXMA0GCSqGSIb3DQEBBQUAME8xCzAJBgNV
3
- BAYTAk5MMQswCQYDVQQIEwJOSDESMBAGA1UEBxMJQW1zdGVyZGFtMRAwDgYDVQQK
4
- EwdUaW55UE5HMQ0wCwYDVQQDEwRUZXN0MB4XDTE1MDIwNTExMTgyN1oXDTI1MDIw
5
- MjExMTgyN1owTzELMAkGA1UEBhMCTkwxCzAJBgNVBAgTAk5IMRIwEAYDVQQHEwlB
6
- bXN0ZXJkYW0xEDAOBgNVBAoTB1RpbnlQTkcxDTALBgNVBAMTBFRlc3QwggEiMA0G
7
- CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC/REKareiEmD/iFBLst7GINIi9F/k2
8
- Bj8SFPvEJQ+nFUYLrdxpsn7mM/QaGJyygOqHQXMDB59kJDnk5Tr07Eupqi2oZvxy
9
- ew4B8VxefhzHgv4CMTFux+f6JUUAtblT2FWOr0GmkieB+oRZXhjXVFbEndmkY4jG
10
- 8FRk3M1DDAUFu3SyRN4yyCL/36IGbIrs5f7AX3E/jnAVAhzx84wjITzwCqffxLw5
11
- wi9V/1B6KXksnU38QyTOY+m2nJu5CP6knOcTssojt/G/apn301ZUsRMBCJBgNUC5
12
- XV9fpIZo3qAoQfRQOouCDXxPkwiMldPmmT2NbB+AQh1le5+djYSajjc/AgMBAAGj
13
- gbEwga4wHQYDVR0OBBYEFBjOC3KAPtgyR1lDxZ9pDM1GxzFCMH8GA1UdIwR4MHaA
14
- FBjOC3KAPtgyR1lDxZ9pDM1GxzFCoVOkUTBPMQswCQYDVQQGEwJOTDELMAkGA1UE
15
- CBMCTkgxEjAQBgNVBAcTCUFtc3RlcmRhbTEQMA4GA1UEChMHVGlueVBORzENMAsG
16
- A1UEAxMEVGVzdIIJAIbimBGoeNlXMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEF
17
- BQADggEBAJziXd9yXydqMSrAxOnjiaMMY0Aqq6aOBmoLjOQp6tybOdBwYwTEm0Fo
18
- SJtEfe6AiFIoQiPbT2LuNU+zTsEdH6kqLRrJq6LSVb7OF3fmLYvSnlTtSE36Kj8p
19
- mAWjbzFYMVkKEtm1vkn/Vf8YuyaQ/f3YkU8Ztx6pk3vSpcd2SFXUXp0MYlI1cbzH
20
- Qer9E77Zr7X3M95faKgH0eXrW2WKw6nKjqjU27gew+F8RHzi2F63m8ctSOg2BmOR
21
- CoWYHzrHM8EupOAMiS1VHyDwCHHNL1cRFqnLt4Yu2hukSNDYNSU1wE5LLKGhIEwC
22
- zy6tfkn3hpBOfSpC4ITYMe90GqApkLs=
23
- -----END CERTIFICATE-----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/fixtures/tiny-config.php DELETED
@@ -1,11 +0,0 @@
1
- <?php
2
-
3
- if ( ! defined( 'TINY_DEBUG' ) ) {
4
- define( 'TINY_DEBUG', null );
5
- }
6
-
7
- class Tiny_Config {
8
- /* URL is only used by fopen driver. */
9
- const URL = 'http://webservice/shrink';
10
- const MONTHLY_FREE_COMPRESSIONS = 500;
11
- }
 
 
 
 
 
 
 
 
 
 
 
test/helpers/mock-http-stream-wrapper.php DELETED
@@ -1,98 +0,0 @@
1
- <?php
2
-
3
- class MockHttpStreamWrapper implements IteratorAggregate, ArrayAccess, Countable {
4
- public static $handlers = array();
5
-
6
- public $context;
7
- public $position = 0;
8
-
9
- protected $data = array();
10
-
11
- public static function clear() {
12
- self::$handlers = array();
13
- }
14
-
15
- public static function register( $method, $url, $handler ) {
16
- $key = self::get_key( $method, $url );
17
- self::$handlers[ $key ] = $handler;
18
- }
19
-
20
- private static function get_key( $method, $url ) {
21
- return strtoupper( $method ) . ' ' . $url;
22
- }
23
-
24
- /* IteratorAggregate */
25
-
26
- public function getIterator() {
27
- return new ArrayIterator( $this->data );
28
- }
29
-
30
- /* ArrayAccess */
31
-
32
- public function offsetExists( $offset ) {
33
- return array_key_exists( $offset, $this->data );
34
- }
35
-
36
- public function offsetGet( $offset ) {
37
- return $this->data[ $offset ];
38
- }
39
-
40
- public function offsetSet( $offset, $value ) {
41
- $this->data[ $offset ] = $value;
42
- }
43
-
44
- public function offsetUnset( $offset ) {
45
- unset( $this->data[ $offset ] );
46
- }
47
-
48
- /* Countable */
49
- public function count() {
50
- return count( $this->data );
51
- }
52
-
53
- /* StreamWrapper */
54
- public function stream_open( $path, $mode, $options, &$opened_path ) {
55
- $context = stream_context_get_options( $this->context );
56
- $path = str_replace( 'https://api.tinify.com', '', $path );
57
- $key = self::get_key( $context['http']['method'], $path );
58
- if ( isset( self::$handlers[ $key ] ) ) {
59
- $handler = self::$handlers[ $key ];
60
-
61
- $status = 'HTTP/1.1 ' . $handler['status'];
62
- $body = isset( $handler['body'] ) ? $handler['body'] : '';
63
- $headers = isset( $handler['headers'] ) ? $handler['headers'] : array();
64
-
65
- $this->mocked_body = $body;
66
- $this->mocked_status = $status;
67
-
68
- array_push( $this->data, $status );
69
- foreach ( $headers as $header => $value ) {
70
- array_push( $this->data, $header . ': ' . $value );
71
- }
72
- } else {
73
- throw new Exception( 'No handler for ' . $key );
74
- }
75
- return true;
76
- }
77
-
78
- public function stream_read( $count ) {
79
- if ( $this->position > strlen( $this->mocked_body ) ) {
80
- return false;
81
- }
82
- $result = substr( $this->mocked_body, $this->position, $count );
83
- $this->position += $count;
84
- return $result;
85
- }
86
-
87
- public function stream_eof() {
88
- return $this->position >= strlen( $this->mocked_body );
89
- }
90
-
91
- public function stream_stat() {
92
- return array( 'wrapper_data' => array( 'test' ) );
93
- }
94
-
95
- public function stream_tell() {
96
- return $this->position;
97
- }
98
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/helpers/mock-tinify-client.php DELETED
@@ -1,50 +0,0 @@
1
- <?php
2
-
3
- class MockTinifyClient extends Tinify\Client {
4
- function __construct( $key = null, $appIdentifier = null ) {
5
- parent::__construct( $key, $appIdentifier );
6
- $this->handlers = array();
7
- }
8
-
9
- public function request( $method, $url, $body = null, $header = array() ) {
10
- $url = str_replace( 'https://api.tinify.com', '', $url );
11
- $key = $this->get_key( $method, $url );
12
- if ( isset( $this->handlers[ $key ] ) ) {
13
- $handler = $this->handlers[ $key ];
14
-
15
- $status = $handler['status'];
16
- $body = isset( $handler['body'] ) ? $handler['body'] : '';
17
- $headers = isset( $handler['headers'] ) ? $handler['headers'] : array();
18
-
19
- if ( isset( $headers['compression-count'] ) ) {
20
- \Tinify\Tinify::setCompressionCount(
21
- intval( $headers['compression-count'] )
22
- );
23
- }
24
-
25
- $isError = $status <= 199 || $status >= 300;
26
- $isJson = true;
27
-
28
- if ( $isJson || $isError ) {
29
- $body = json_decode( $body );
30
- }
31
-
32
- if ( $isError ) {
33
- throw \Tinify\Exception::create( $body->message, $body->error, $status );
34
- }
35
-
36
- return (object) array( 'body' => $body, 'headers' => $headers );
37
- } else {
38
- throw new Exception( 'No handler for ' . $key );
39
- }
40
- }
41
-
42
- public function register( $method, $url, $handler ) {
43
- $key = $this->get_key( $method, $url );
44
- $this->handlers[ $key ] = $handler;
45
- }
46
-
47
- private function get_key( $method, $url ) {
48
- return strtoupper( $method ) . ' ' . $url;
49
- }
50
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/helpers/setup.php DELETED
@@ -1,214 +0,0 @@
1
- <?php
2
-
3
- require 'vendor/autoload.php';
4
-
5
- use Facebook\WebDriver;
6
- use Facebook\WebDriver\WebDriverBy;
7
- use Facebook\WebDriver\WebDriverDimension;
8
- use Facebook\WebDriver\WebDriverExpectedCondition;
9
- use Facebook\WebDriver\Remote;
10
- use Facebook\WebDriver\Remote\RemoteWebDriver;
11
- use Facebook\WebDriver\Remote\DesiredCapabilities;
12
-
13
- function wordpress( $url = null ) {
14
- return getenv( 'WORDPRESS_URL' ) . $url;
15
- }
16
-
17
- function wordpress_version() {
18
- return intval( getenv( 'WORDPRESS_VERSION' ) );
19
- }
20
-
21
- function configure_wordpress_for_testing( $driver ) {
22
- if ( is_wordpress_setup() ) {
23
- restore_wordpress_site();
24
- set_siteurl( wordpress() );
25
- login( $driver );
26
- clear_uploads( $driver );
27
- } else {
28
- setup_wordpress_language( $driver );
29
- setup_wordpress_site( $driver );
30
- set_siteurl( wordpress() );
31
- activate_plugin( $driver );
32
- backup_wordpress_site();
33
- }
34
- }
35
-
36
- function restore_wordpress() {
37
- if ( is_wordpress_setup() ) {
38
- set_siteurl( 'http://' . getenv( 'HOST' ) . ':' . getenv( 'WORDPRESS_PORT' ) );
39
- }
40
- }
41
-
42
- // Renamed this function to mysqldump_file without underscore
43
- // for compatibility with WP Engine PHP Compatibility Checker
44
- function mysqldump_file() {
45
- return dirname( __FILE__ ) . '/../../tmp/mysqldump_' . getenv( 'WORDPRESS_DATABASE' ) . '.sql.gz';
46
- }
47
-
48
- function restore_wordpress_site() {
49
- shell_exec( 'gunzip -c < ' . mysqldump_file() . ' | mysql -h ' . getenv( 'HOST' ) . ' -u root ' . getenv( 'WORDPRESS_DATABASE' ) );
50
- }
51
-
52
- function backup_wordpress_site() {
53
- shell_exec( 'mysqldump -h ' . getenv( 'HOST' ) . ' -u root ' . getenv( 'WORDPRESS_DATABASE' ) . ' | gzip -c > ' . mysqldump_file() );
54
- }
55
-
56
- function set_siteurl( $site_url ) {
57
- $db = new mysqli( getenv( 'HOST' ), 'root',
58
- getenv( 'MYSQL_PWD' ),
59
- getenv( 'WORDPRESS_DATABASE' )
60
- );
61
-
62
- $statement = $db->prepare( "UPDATE wp_options SET option_value = ? WHERE option_name = 'home' OR option_name = 'siteurl'" );
63
- $statement->bind_param( 's', $site_url );
64
- $statement->execute();
65
- }
66
-
67
- function clear_settings() {
68
- $db = new mysqli( getenv( 'HOST' ), 'root',
69
- getenv( 'MYSQL_PWD' ),
70
- getenv( 'WORDPRESS_DATABASE' )
71
- );
72
-
73
- $statement = $db->prepare( "DELETE FROM wp_options WHERE option_name LIKE 'tinypng_%'" );
74
- $statement->execute();
75
- $statement = $db->prepare( "DELETE FROM wp_usermeta WHERE meta_key LIKE 'tinypng_%'" );
76
- $statement->execute();
77
- }
78
-
79
- function clear_uploads() {
80
- $db = new mysqli( getenv( 'HOST' ), 'root',
81
- getenv( 'MYSQL_PWD' ),
82
- getenv( 'WORDPRESS_DATABASE' )
83
- );
84
-
85
- $statement = $db->prepare( "DELETE wp_postmeta FROM wp_postmeta JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id WHERE wp_posts.post_type = 'attachment'" );
86
- $statement->execute();
87
- $statement = $db->prepare( "DELETE FROM wp_posts WHERE wp_posts.post_type = 'attachment'" );
88
- $statement->execute();
89
-
90
- shell_exec( 'docker-compose exec wordpress rm -rf wp-content/uploads' );
91
- }
92
-
93
- function is_wordpress_setup() {
94
- $db = new mysqli( getenv( 'HOST' ), 'root',
95
- getenv( 'MYSQL_PWD' )
96
- );
97
-
98
- if ( $result = $db->query( "SELECT * FROM information_schema.tables WHERE table_schema = '" . getenv( 'WORDPRESS_DATABASE' ) . "'" ) ) {
99
- return $result->num_rows > 0;
100
- } else {
101
- return false;
102
- }
103
- }
104
-
105
- function setup_wordpress_language( $driver ) {
106
- $driver->get( wordpress( '/wp-admin/install.php' ) );
107
- $driver->findElement( WebDriverBy::tagName( 'form' ) )->submit();
108
- }
109
-
110
- function setup_wordpress_site( $driver ) {
111
- if ( $driver->getCurrentURL() != wordpress( '/wp-admin/install.php?step=1' ) ) {
112
- $driver->get( wordpress( '/wp-admin/install.php' ) );
113
- }
114
- $driver->findElement( WebDriverBy::name( 'weblog_title' ) )->sendKeys( 'Wordpress test' );
115
- $driver->findElement( WebDriverBy::name( 'user_name' ) )->clear()->sendKeys( 'admin' );
116
- if ( wordpress_version() > 42 ) {
117
- $driver->findElement( WebDriverBy::id( 'pass1-text' ) )->clear()->sendKeys( 'a' )->sendKeys( 'dmin' );
118
-
119
- /* Confirm use of weak password if necessary. */
120
- $confirm = $driver->findElement( WebDriverBy::name( 'pw_weak' ) );
121
- if ( $confirm && ! $confirm->isSelected() ) { $confirm->click(); }
122
- } else {
123
- $driver->findElement( WebDriverBy::name( 'admin_password' ) )->sendKeys( 'admin' );
124
- $driver->findElement( WebDriverBy::name( 'admin_password2' ) )->sendKeys( 'admin' );
125
- }
126
- $driver->findElement( WebDriverBy::name( 'admin_email' ) )->sendKeys( 'developers@voormedia.com' );
127
- $driver->findElement( WebDriverBy::tagName( 'form' ) )->submit();
128
-
129
- $h1s = $driver->findElements( WebDriverBy::tagName( 'h1' ) );
130
- $texts = array_map( function( $h1 ) {
131
- return $h1->getText();
132
- }, $h1s );
133
-
134
- if ( array_search( 'Dashboard', $texts ) !== false ) {
135
- print "Setting up WordPress is successful.\n";
136
- /* Already logged in. */
137
- } elseif ( array_search( 'Success', $texts ) !== false || array_search( 'Success!', $texts ) !== false ) {
138
- print "Setting up WordPress is successful.\n";
139
- login( $driver );
140
- } else {
141
- var_dump( $driver->getPageSource() );
142
- throw new UnexpectedValueException( 'Setting up WordPress failed.' );
143
- }
144
- }
145
-
146
- function login( $driver ) {
147
- print 'Logging in to WordPress... ';
148
-
149
- try {
150
- $driver->get( wordpress( '/wp-login.php' ) );
151
-
152
- usleep( 250000 );
153
-
154
- $driver->findElement( WebDriverBy::id( 'user_login' ) )->sendKeys( 'admin' );
155
- $driver->findElement( WebDriverBy::id( 'user_pass' ) )->sendKeys( 'admin' );
156
- $driver->findElement( WebDriverBy::id( 'loginform' ) )->submit();
157
-
158
- $driver
159
- ->wait( 2 )
160
- ->until(
161
- WebDriverExpectedCondition::presenceOfElementLocated(
162
- WebDriverBy::cssSelector( 'div.wrap h1, div.wrap h2' )
163
- )
164
- );
165
- } catch (Exception $e) {
166
- var_dump( $driver->getPageSource() );
167
- print( $e );
168
- throw new UnexpectedValueException( 'Login failed.' );
169
- }
170
- }
171
-
172
- function activate_plugin( $driver ) {
173
- $driver->get( wordpress( '/wp-admin/plugins.php' ) );
174
- $activate_links = $driver->findElements( WebDriverBy::xpath( '//a[starts-with(@href, "plugins.php?action=activate&plugin=tiny-compress-images")]' ) );
175
- $deactivate_links = $driver->findElements( WebDriverBy::xpath( '//a[starts-with(@href, "plugins.php?action=deactivate&plugin=tiny-compress-images")]' ) );
176
- if ( count( $activate_links ) > 0 ) {
177
- $activate_links[0]->click();
178
- } elseif ( count( $deactivate_links ) > 0 ) {
179
- print "Plugin already activated.\n";
180
- } else {
181
- var_dump( $driver->getPageSource() );
182
- throw new UnexpectedValueException( 'Activating plugin failed.' );
183
- }
184
- $driver->get( wordpress( '/wp-admin/upload.php?mode=list' ) );
185
- }
186
-
187
- function close_webdriver() {
188
- if ( isset( $GLOBALS['global_session_id'] ) && isset( $GLOBALS['global_webdriver_host'] ) ) {
189
- RemoteWebDriver::createBySessionId( $GLOBALS['global_session_id'], $GLOBALS['global_webdriver_host'] )->close();
190
- }
191
- }
192
-
193
- function reset_webservice() {
194
- $request = curl_init();
195
- curl_setopt_array($request, array(
196
- CURLOPT_URL => 'http://' . getenv( 'HOST' ) . ':8080/reset',
197
- ));
198
- $response = curl_exec( $request );
199
- curl_close( $request );
200
- }
201
-
202
- // $global_webdriver_host = 'http://127.0.0.1:4444/wd/hub';
203
- // $global_driver = RemoteWebDriver::create($global_webdriver_host, DesiredCapabilities::firefox());
204
- $global_webdriver_host = 'http://127.0.0.1:8910';
205
- $global_driver = RemoteWebDriver::create( $global_webdriver_host, DesiredCapabilities::phantomjs() );
206
- $global_session_id = $global_driver->getSessionID();
207
- $window = new WebDriverDimension( 1280, 1024 );
208
- $global_driver->manage()->window()->setSize( $window );
209
-
210
- register_shutdown_function( 'close_webdriver' );
211
- register_shutdown_function( 'restore_wordpress' );
212
-
213
- configure_wordpress_for_testing( $global_driver );
214
- print "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/helpers/wordpress.php DELETED
@@ -1,245 +0,0 @@
1
- <?php
2
-
3
- define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' );
4
- define( 'WPINC', 'wp-includes' );
5
-
6
- use org\bovigo\vfs\vfsStream;
7
- use org\bovigo\vfs\content\LargeFileContent;
8
-
9
- class WordPressOptions {
10
- private $values;
11
-
12
- public function __construct() {
13
- $this->values = array(
14
- 'thumbnail_size_w' => 150,
15
- 'thumbnail_size_h' => 150,
16
- 'medium_size_w' => 300,
17
- 'medium_size_h' => 300,
18
- 'medium_large_size_w' => 768,
19
- 'medium_large_size_h' => 0,
20
- 'large_size_w' => 1024,
21
- 'large_size_h' => 1024,
22
- );
23
- }
24
-
25
- public function set( $key, $value ) {
26
- if ( preg_match( '#^(.+)\[(.+)\]$#', $key, $match ) ) {
27
- if ( ! isset( $this->values[ $match[1] ] ) ) {
28
- $this->values[ $match[1] ] = array();
29
- }
30
- $this->values[ $match[1] ][ $match[2] ] = $value;
31
- } else {
32
- $this->values[ $key ] = $value;
33
- }
34
- }
35
-
36
- public function get( $key, $default = null ) {
37
- return isset( $this->values[ $key ] ) ? $this->values[ $key ] : $default;
38
- }
39
- }
40
-
41
- class WordPressStubs {
42
- const UPLOAD_DIR = 'wp-content/uploads';
43
-
44
- private $vfs;
45
- private $initFunctions;
46
- private $admin_initFunctions;
47
- private $options;
48
- private $metadata;
49
- private $calls;
50
- private $stubs;
51
-
52
- public function __construct( $vfs ) {
53
- $GLOBALS['wp'] = $this;
54
- $this->vfs = $vfs;
55
- $this->addMethod( 'add_action' );
56
- $this->addMethod( 'add_filter' );
57
- $this->addMethod( 'register_setting' );
58
- $this->addMethod( 'add_settings_section' );
59
- $this->addMethod( 'add_settings_field' );
60
- $this->addMethod( 'get_option' );
61
- $this->addMethod( 'get_site_option' );
62
- $this->addMethod( 'update_site_option' );
63
- $this->addMethod( 'get_post_meta' );
64
- $this->addMethod( 'update_post_meta' );
65
- $this->addMethod( 'get_intermediate_image_sizes' );
66
- $this->addMethod( 'add_image_size' );
67
- $this->addMethod( 'translate' );
68
- $this->addMethod( 'load_plugin_textdomain' );
69
- $this->addMethod( 'get_post_mime_type' );
70
- $this->addMethod( 'get_plugin_data' );
71
- $this->addMethod( 'wp_upload_dir' );
72
- $this->addMethod( 'plugin_basename' );
73
- $this->addMethod( 'is_multisite' );
74
- $this->addMethod( 'current_user_can' );
75
- $this->addMethod( 'wp_get_attachment_metadata' );
76
- $this->addMethod( 'is_admin' );
77
- $this->defaults();
78
- $this->create_filesystem();
79
- }
80
-
81
- public function create_filesystem() {
82
- vfsStream::newDirectory( self::UPLOAD_DIR )
83
- ->at( $this->vfs );
84
- }
85
-
86
- public function defaults() {
87
- $this->initFunctions = array();
88
- $this->admin_initFunctions = array();
89
- $this->options = new WordPressOptions();
90
- $this->metadata = array();
91
- $GLOBALS['_wp_additional_image_sizes'] = array();
92
- }
93
-
94
- public function call( $method, $args ) {
95
- $this->calls[ $method ][] = $args;
96
- if ( 'add_action' === $method ) {
97
- if ( 'init' === $args[0] ) {
98
- $this->initFunctions[] = $args[1];
99
- } elseif ( 'admin_init' === $args[0] ) {
100
- $this->admin_initFunctions[] = $args[1];
101
- }
102
- }
103
- if ( 'translate' === $method ) {
104
- return $args[0];
105
- } elseif ( 'get_option' === $method ) {
106
- return call_user_func_array( array( $this->options, 'get' ), $args );
107
- } elseif ( 'get_post_meta' === $method ) {
108
- return call_user_func_array( array( $this, 'getMetadata' ), $args );
109
- } elseif ( 'add_image_size' === $method ) {
110
- return call_user_func_array( array( $this, 'addImageSize' ), $args );
111
- } elseif ( 'update_post_meta' === $method ) {
112
- return call_user_func_array( array( $this, 'updateMetadata' ), $args );
113
- } elseif ( 'get_intermediate_image_sizes' === $method ) {
114
- return array_merge( array( 'thumbnail', 'medium', 'medium_large', 'large' ), array_keys( $GLOBALS['_wp_additional_image_sizes'] ) );
115
- } elseif ( 'get_plugin_data' === $method ) {
116
- return array( 'Version' => '1.7.2' );
117
- } elseif ( 'wp_upload_dir' === $method ) {
118
- return array( 'basedir' => $this->vfs->url() . '/' . self::UPLOAD_DIR, 'baseurl' => '/' . self::UPLOAD_DIR );
119
- } elseif ( 'is_admin' === $method ) {
120
- return true;
121
- } elseif ( $this->stubs[ $method ] ) {
122
- return call_user_func_array( $this->stubs[ $method ], $args );
123
- }
124
- }
125
-
126
- public function addMethod( $method ) {
127
- $this->calls[ $method ] = array();
128
- $this->stubs[ $method ] = array();
129
- if ( ! function_exists( $method ) ) {
130
- eval( "function $method() { return \$GLOBALS['wp']->call('$method', func_get_args()); }" );
131
- }
132
- }
133
-
134
- public function addOption( $key, $value ) {
135
- $this->options->set( $key, $value );
136
- }
137
-
138
- public function addImageSize( $size, $values ) {
139
- $GLOBALS['_wp_additional_image_sizes'][ $size ] = $values;
140
- }
141
-
142
- public function getMetadata( $id, $key, $single = false ) {
143
- $values = isset( $this->metadata[ $id ] ) ? $this->metadata[ $id ] : array();
144
- $value = isset( $values[ $key ] ) ? $values[ $key ] : '';
145
- return $single ? $value : array( $value );
146
- }
147
-
148
- public function updateMetadata( $id, $key, $values ) {
149
- $this->metadata[ $id ][ $key ] = $values;
150
- }
151
-
152
- public function setTinyMetadata( $id, $values ) {
153
- $this->metadata[ $id ] = array( Tiny_Image::META_KEY => $values );
154
- }
155
-
156
- public function getCalls( $method ) {
157
- return $this->calls[ $method ];
158
- }
159
-
160
- public function init() {
161
- foreach ( $this->initFunctions as $func ) {
162
- call_user_func( $func );
163
- }
164
- }
165
-
166
- public function admin_init() {
167
- foreach ( $this->admin_initFunctions as $func ) {
168
- call_user_func( $func );
169
- }
170
- }
171
-
172
- public function stub( $method, $func ) {
173
- $this->stubs[ $method ] = $func;
174
- }
175
-
176
- public function createImage( $file_size, $path, $name ) {
177
- if ( ! $this->vfs->hasChild( self::UPLOAD_DIR . "/$path" ) ) {
178
- vfsStream::newDirectory( self::UPLOAD_DIR . "/$path" )->at( $this->vfs );
179
- }
180
- $dir = $this->vfs->getChild( self::UPLOAD_DIR . "/$path" );
181
-
182
- vfsStream::newFile( $name )
183
- ->withContent( new LargeFileContent( $file_size ) )
184
- ->at( $dir );
185
- }
186
-
187
- public function createImages( $sizes = null, $original_size = 12345, $path = '14/01', $name = 'test' ) {
188
- vfsStream::newDirectory( self::UPLOAD_DIR . "/$path" )->at( $this->vfs );
189
- $dir = $this->vfs->getChild( self::UPLOAD_DIR . '/' . $path );
190
-
191
- vfsStream::newFile( "$name.png" )
192
- ->withContent( new LargeFileContent( $original_size ) )
193
- ->at( $dir );
194
-
195
- if ( is_null( $sizes ) ) {
196
- $sizes = array( 'thumbnail' => 100, 'medium' => 1000 , 'large' => 10000, 'post-thumbnail' => 1234 );
197
- }
198
-
199
- foreach ( $sizes as $key => $size ) {
200
- vfsStream::newFile( "$name-$key.png" )
201
- ->withContent( new LargeFileContent( $size ) )
202
- ->at( $dir );
203
- }
204
- }
205
-
206
- public function createImagesFromJSON( $virtual_images ) {
207
- foreach ( $virtual_images['images'] as $image ) {
208
- self::createImage( $image['size'], $virtual_images['path'], $image['file'] );
209
- }
210
- }
211
-
212
- public function getTestMetadata( $path = '14/01', $name = 'test' ) {
213
- $metadata = array(
214
- 'file' => "$path/$name.png",
215
- 'width' => 4000,
216
- 'height' => 3000,
217
- 'sizes' => array(),
218
- );
219
-
220
- $regex = '#^' . preg_quote( $name ) . '-([^.]+)[.](png|jpe?g)$#';
221
- $dir = $this->vfs->getChild( self::UPLOAD_DIR . "/$path" );
222
- foreach ( $dir->getChildren() as $child ) {
223
- $file = $child->getName();
224
- if ( preg_match( $regex, $file, $match ) ) {
225
- $metadata['sizes'][ $match[1] ] = array( 'file' => $file );
226
- }
227
- }
228
-
229
- return $metadata;
230
- }
231
- }
232
-
233
- class WP_HTTP_Proxy {
234
- public function is_enabled() {
235
- return false;
236
- }
237
- }
238
-
239
- function __( $text, $domain = 'default' ) {
240
- return translate( $text, $domain );
241
- }
242
-
243
- function esc_html__( $text, $domain = 'default' ) {
244
- return translate( $text, $domain );
245
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/integration/BulkOptimizationIntegrationTest.php DELETED
@@ -1,84 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/IntegrationTestCase.php';
4
-
5
- class BulkOptimizationIntegrationTest extends IntegrationTestCase {
6
- public function tear_down() {
7
- parent::tear_down();
8
- clear_settings();
9
- clear_uploads();
10
- }
11
-
12
- public function test_summary_should_display_correct_values_for_empty_library() {
13
- $this->enable_compression_sizes( array( '0', 'thumbnail', 'medium' ) );
14
-
15
- $this->visit( '/wp-admin/upload.php?page=tiny-bulk-optimization' );
16
-
17
- $this->assertEquals( '0', $this->find( '#uploaded-images' )->getText() );
18
- $this->assertEquals( '0', $this->find( '#optimizable-image-sizes' )->getText() );
19
- $this->assertEquals( '$ 0.00', $this->find( '#estimated-cost' )->getText() );
20
- $this->assertEquals( '0', $this->find( '#optimized-image-sizes' )->getText() );
21
-
22
- $this->assertEquals( '-', $this->find( '#unoptimized-library-size' )->getText() );
23
- $this->assertEquals( '-', $this->find( '#optimized-library-size' )->getText() );
24
- $this->assertEquals( '0%', $this->find( '#savings-percentage' )->getText() );
25
-
26
- $this->assertEquals( '0 / 0 (100%)', $this->find( '#compression-progress-bar' )->getText() );
27
- }
28
-
29
- public function test_summary_should_display_correct_values() {
30
- $this->set_api_key( 'JPG123' );
31
-
32
- $this->enable_compression_sizes( array() );
33
- $this->upload_media( 'test/fixtures/input-example.jpg' );
34
-
35
- $this->enable_compression_sizes( array( '0' ) );
36
- $this->upload_media( 'test/fixtures/input-example.jpg' );
37
-
38
- $this->enable_compression_sizes( array( '0', 'thumbnail', 'medium' ) );
39
- $this->upload_media( 'test/fixtures/input-example.jpg' );
40
-
41
- $this->visit( '/wp-admin/upload.php?page=tiny-bulk-optimization' );
42
-
43
- $this->assertEquals( '3', $this->find( '#uploaded-images' )->getText() );
44
- $this->assertEquals( '5', $this->find( '#optimizable-image-sizes' )->getText() );
45
- $this->assertEquals( '$ 0.00', $this->find( '#estimated-cost' )->getText() );
46
- $this->assertEquals( '4', $this->find( '#optimized-image-sizes' )->getText() );
47
-
48
- $this->assertRegExp( '/[23](\.\d+)? MB/', $this->find( '#unoptimized-library-size' )->getText() );
49
- $this->assertRegExp( '/[12](\.\d+)? MB/', $this->find( '#optimized-library-size' )->getText() );
50
- $this->assertRegExp( '/2\d(\.\d+)?%/', $this->find( '#savings-percentage' )->getText() );
51
-
52
- $this->assertEquals( '4 / 9 (44%)', $this->find( '#compression-progress-bar' )->getText() );
53
- }
54
-
55
- public function test_start_bulk_optimization_should_optimize_remaining_images() {
56
- $this->set_api_key( 'JPG123' );
57
-
58
- $this->enable_compression_sizes( array() );
59
- $this->upload_media( 'test/fixtures/input-example.jpg' );
60
-
61
- $this->enable_compression_sizes( array( '0' ) );
62
- $this->upload_media( 'test/fixtures/input-example.jpg' );
63
-
64
- $this->enable_compression_sizes( array( '0', 'thumbnail', 'medium' ) );
65
- $this->upload_media( 'test/fixtures/input-example.jpg' );
66
-
67
- $this->visit( '/wp-admin/upload.php?page=tiny-bulk-optimization' );
68
-
69
- $this->assertEquals( '5', $this->find( '#optimizable-image-sizes' )->getText() );
70
-
71
- $this->find_button( 'Start Bulk Optimization' )->click();
72
-
73
- $this->wait_for_text(
74
- '#optimizable-image-sizes',
75
- '0'
76
- );
77
-
78
- $this->assertEquals( '9 / 9 (100%)', $this->find( '#compression-progress-bar' )->getText() );
79
- }
80
-
81
- public function test_should_display_tooltips() {
82
- $this->assertGreaterThanOrEqual( '1', sizeof( $this->find_all( 'div.tip' ) ) );
83
- }
84
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/integration/CompressIntegrationTest.php DELETED
@@ -1,358 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/IntegrationTestCase.php';
4
-
5
- class CompressIntegrationTest extends IntegrationTestCase {
6
- public function tear_down() {
7
- parent::tear_down();
8
- clear_settings();
9
- clear_uploads();
10
- }
11
-
12
- public function test_upload_without_key_should_show_error() {
13
- $this->upload_media( 'test/fixtures/input-example.jpg' );
14
-
15
- $this->assertContains(
16
- 'Latest error: Register an account or provide an API key first',
17
- $this->find( 'td.tiny-compress-images' )->getText()
18
- );
19
- }
20
-
21
- public function test_upload_with_invalid_key_should_show_error() {
22
- $this->set_api_key( '1234' );
23
- $this->upload_media( 'test/fixtures/input-example.jpg' );
24
-
25
- $this->assertContains(
26
- 'Latest error: Credentials are invalid',
27
- $this->find( 'td.tiny-compress-images' )->getText()
28
- );
29
- }
30
-
31
- public function test_upload_with_limited_key_should_show_error() {
32
- $this->set_api_key( 'LIMIT123' );
33
- $this->upload_media( 'test/fixtures/input-example.jpg' );
34
-
35
- $this->assertContains(
36
- 'Latest error: Your monthly limit has been exceeded',
37
- $this->find( 'td.tiny-compress-images' )->getText()
38
- );
39
- }
40
-
41
- public function test_upload_with_valid_key_should_show_sizes_compressed() {
42
- $this->set_api_key( 'JPG123' );
43
- $this->upload_media( 'test/fixtures/input-example.jpg' );
44
-
45
- $this->assertContains(
46
- 'sizes compressed',
47
- $this->find( 'td.tiny-compress-images' )->getText()
48
- );
49
- }
50
-
51
- public function test_upload_with_gateway_timeout_should_show_error() {
52
- $this->set_api_key( 'GATEWAYTIMEOUT' );
53
- $this->enable_compression_sizes( array( 'medium' ) );
54
- $this->upload_media( 'test/fixtures/input-example.jpg' );
55
-
56
- $this->assertContains(
57
- 'Error while parsing response',
58
- $this->find( 'td.tiny-compress-images' )->getText()
59
- );
60
- }
61
-
62
- public function test_upload_with_incorrect_metadata_should_show_error() {
63
- $this->set_api_key( 'PNG123 INVALID' );
64
- $this->enable_compression_sizes( array( '0', 'medium' ) );
65
- $this->enable_preserve( array( 'copyright' ) );
66
- $this->upload_media( 'test/fixtures/input-example.jpg' );
67
-
68
- $this->assertContains(
69
- "Metadata key 'author' not supported",
70
- $this->find( 'td.tiny-compress-images' )->getText()
71
- );
72
- }
73
-
74
- public function test_upload_should_show_details_in_edit_screen() {
75
- if ( ! $this->has_postbox_container() ) { return; }
76
- $this->set_api_key( 'JPG123' );
77
- $this->enable_compression_sizes( array() );
78
- $this->upload_media( 'test/fixtures/input-example.jpg' );
79
- $this->enable_compression_sizes( array( 'medium', 'large' ) );
80
- $this->find_link( 'input-example' )->click();
81
-
82
- $this->assertContains(
83
- "JPEG and PNG optimization\n2 sizes to be compressed\nDetails\nCompress",
84
- $this->find( 'div.postbox-container div.tiny-compress-images' )->getText()
85
- );
86
- }
87
-
88
- public function test_upload_should_show_details_in_edit_screen_popup() {
89
- if ( ! $this->has_postbox_container() ) { return; }
90
- $this->set_api_key( 'PNG123' );
91
- $this->enable_compression_sizes( array( 'medium', 'large' ) );
92
- $this->upload_media( 'test/fixtures/input-example.png' );
93
-
94
- $this->find_link( 'input-example' )->click();
95
- $this->find( 'div.tiny-compress-images a.thickbox' )->click();
96
-
97
- $this->assertContains(
98
- 'Compression details for input-example.png',
99
- $this->find( 'div.tiny-compression-details' )->getText()
100
- );
101
- }
102
-
103
- public function test_upload_should_show_compression_details_in_edit_screen_popup() {
104
- if ( ! $this->has_postbox_container() ) { return; }
105
- $this->set_api_key( 'JPG123' );
106
- $this->enable_compression_sizes( array( 'medium', 'large' ) );
107
- $this->upload_media( 'test/fixtures/input-example.jpg' );
108
-
109
- $this->find_link( 'input-example' )->click();
110
- $this->find( 'div.tiny-compress-images a.thickbox' )->click();
111
-
112
- $rows = $this->find_all( 'div.tiny-compression-details tr' );
113
- $rows = array_map( function( $row ) {
114
- $cells = $this->find_all( 'td', $row );
115
- if ( count( $cells ) > 0 ) {
116
- return $cells[0]->getText();
117
- }
118
- }, $rows );
119
-
120
- $rows = array_filter( $rows, function( $row ) {
121
- return $row && in_array( $row, array(
122
- 'Original',
123
- 'Thumbnail',
124
- 'Medium',
125
- 'Large',
126
- ) );
127
- });
128
-
129
- $this->assertEquals(
130
- array(
131
- 'Original',
132
- 'Large',
133
- 'Medium',
134
- 'Thumbnail',
135
- ),
136
- array_values( $rows )
137
- );
138
- }
139
-
140
- public function test_compress_button_in_edit_screen_should_compress_images() {
141
- if ( ! $this->has_postbox_container() ) { return; }
142
- $this->upload_media( 'test/fixtures/input-example.jpg' );
143
-
144
- $this->set_api_key( 'JPG123' );
145
- $this->enable_compression_sizes( array( 'medium', 'large' ) );
146
-
147
- $this->find_link( 'input-example' )->click();
148
- $this->find( 'div.tiny-compress-images button.tiny-compress' )->click();
149
-
150
- $this->wait_for_text(
151
- 'div.tiny-compress-images',
152
- '2 sizes compressed'
153
- );
154
- }
155
-
156
- public function test_compress_button_should_compress_uncompressed_sizes() {
157
- $this->set_api_key( 'JPG123' );
158
-
159
- $this->enable_compression_sizes( array( 'medium' ) );
160
- $this->upload_media( 'test/fixtures/input-example.jpg' );
161
- $this->enable_compression_sizes( array( 'medium', 'thumbnail' ) );
162
-
163
- $this->visit( '/wp-admin/upload.php' );
164
- $this->assertContains(
165
- '1 size compressed',
166
- $this->find( 'td.tiny-compress-images' )->getText()
167
- );
168
-
169
- $this->assertContains(
170
- '1 size to be compressed',
171
- $this->find( 'td.tiny-compress-images' )->getText()
172
- );
173
-
174
- $this->find( 'td.tiny-compress-images button' )->click();
175
-
176
- $this->wait_for_text(
177
- 'td.tiny-compress-images',
178
- '2 sizes compressed'
179
- );
180
- }
181
-
182
- public function test_compress_button_should_show_error_for_incorrect_json() {
183
- $this->enable_compression_sizes( array() );
184
- $this->upload_media( 'test/fixtures/input-example.jpg' );
185
- $this->enable_compression_sizes( array( 'medium', 'large' ) );
186
-
187
- $this->set_api_key( 'JSON1234' );
188
- $this->visit( '/wp-admin/upload.php' );
189
-
190
- $this->find( 'td.tiny-compress-images button' )->click();
191
- $this->wait_for_text(
192
- 'td.tiny-compress-images',
193
- 'Error while parsing response'
194
- );
195
- }
196
-
197
- public function test_limit_reached_dismiss_button_should_remove_error() {
198
- $this->set_api_key( 'LIMIT123' );
199
- $this->upload_media( 'test/fixtures/input-example.jpg' );
200
-
201
- $this->find( '.tiny-notice button, .tiny-notice a.tiny-dismiss' )->click();
202
- $this->wait_for_text_disappearance( 'a.tiny-dismiss', 'Dismiss' );
203
-
204
- $this->visit( '/wp-admin/options-media.php' );
205
- $this->assertEquals( 0, count( $this->find_all( 'div.error p' ) ) );
206
- }
207
-
208
- public function test_resize_fit_should_display_resized_text_in_library() {
209
- $this->set_api_key( 'JPG123' );
210
- $this->enable_resize(array(
211
- 'method' => 'fit',
212
- 'width' => 300,
213
- 'height' => 200,
214
- ));
215
-
216
- $this->upload_media( 'test/fixtures/input-example.jpg' );
217
- $this->find( 'td.tiny-compress-images a.thickbox' )->click();
218
-
219
- $this->assertContains(
220
- 'resized to 300x200',
221
- $this->find( 'div.tiny-compression-details' )->getText()
222
- );
223
- }
224
-
225
- public function test_resize_fit_should_display_resized_text_in_edit_screen() {
226
- if ( ! $this->has_postbox_container() ) { return; }
227
- $this->set_api_key( 'JPG123' );
228
- $this->enable_resize(array(
229
- 'method' => 'fit',
230
- 'width' => 300,
231
- 'height' => 200,
232
- ));
233
-
234
- $this->upload_media( 'test/fixtures/input-example.jpg' );
235
- $this->find_link( 'input-example' )->click();
236
-
237
- $this->assertContains(
238
- 'Dimensions: 300 × 200',
239
- $this->find( $this->postbox_dimension_selector() )->getText()
240
- );
241
- }
242
-
243
- public function test_resize_scale_should_display_resized_text_in_library() {
244
- $this->set_api_key( 'JPG123' );
245
- $this->enable_resize(array(
246
- 'method' => 'scale',
247
- 'height' => 200,
248
- ));
249
-
250
- $this->upload_media( 'test/fixtures/input-example.jpg' );
251
- $this->find( 'td.tiny-compress-images a.thickbox' )->click();
252
-
253
- $this->assertContains(
254
- 'resized to 300x200',
255
- $this->find( 'div.tiny-compression-details' )->getText()
256
- );
257
- }
258
-
259
- public function test_resize_scale_should_display_resized_text_in_edit_screen() {
260
- if ( ! $this->has_postbox_container() ) { return; }
261
- $this->set_api_key( 'JPG123' );
262
- $this->enable_resize(array(
263
- 'method' => 'scale',
264
- 'height' => 200,
265
- ));
266
-
267
- $this->upload_media( 'test/fixtures/input-example.jpg' );
268
- $this->find_link( 'input-example' )->click();
269
-
270
- $this->assertContains(
271
- 'Dimensions: 300 × 200',
272
- $this->find( $this->postbox_dimension_selector() )->getText()
273
- );
274
- }
275
-
276
- public function test_superfluous_resize_should_not_display_resized_text_in_library() {
277
- $this->set_api_key( 'JPG123' );
278
- $this->enable_resize(array(
279
- 'method' => 'fit',
280
- 'width' => 15000,
281
- 'height' => 15000,
282
- ));
283
-
284
- $this->upload_media( 'test/fixtures/input-example.jpg' );
285
- $this->find( 'td.tiny-compress-images a.thickbox' )->click();
286
-
287
- $this->assertNotContains(
288
- 'resized',
289
- $this->find( 'div.tiny-compression-details' )->getText()
290
- );
291
- }
292
-
293
- public function test_superfluous_resize_should_display_original_dimensions_in_edit_screen() {
294
- if ( ! $this->has_postbox_container() ) { return; }
295
- $this->set_api_key( 'JPG123' );
296
- $this->enable_resize(array(
297
- 'method' => 'fit',
298
- 'width' => 15000,
299
- 'height' => 15000,
300
- ));
301
-
302
- $this->upload_media( 'test/fixtures/input-example.jpg' );
303
- $this->find_link( 'input-example' )->click();
304
-
305
- $this->assertContains(
306
- 'Dimensions: 1080 × 720',
307
- $this->find( $this->postbox_dimension_selector() )->getText()
308
- );
309
- }
310
-
311
- public function test_resize_disabled_should_not_display_resized_text_in_library() {
312
- $this->set_api_key( 'JPG123' );
313
- $this->disable_resize();
314
-
315
- $this->upload_media( 'test/fixtures/input-example.jpg' );
316
- $this->find( 'td.tiny-compress-images a.thickbox' )->click();
317
-
318
- $this->assertNotContains(
319
- 'resized',
320
- $this->find( 'div.tiny-compression-details' )->getText()
321
- );
322
- }
323
-
324
- public function test_resize_disabled_should_display_original_dimensions_in_edit_screen() {
325
- if ( ! $this->has_postbox_container() ) { return; }
326
- $this->set_api_key( 'JPG123' );
327
- $this->disable_resize();
328
-
329
- $this->upload_media( 'test/fixtures/input-example.jpg' );
330
- $this->find_link( 'input-example' )->click();
331
-
332
- $this->assertContains(
333
- 'Dimensions: 1080 × 720',
334
- $this->find( $this->postbox_dimension_selector() )->getText()
335
- );
336
- }
337
-
338
- public function test_preserve_copyright_should_not_display_modification_in_library() {
339
- $this->set_api_key( 'PRESERVEJPG123' );
340
- $this->enable_preserve( array( 'copyright' ) );
341
- $this->upload_media( 'test/fixtures/input-copyright.jpg' );
342
-
343
- $this->assertNotContains(
344
- 'files modified after compression',
345
- $this->find( 'div.tiny-compression-details' )->getText()
346
- );
347
- }
348
-
349
- public function test_unsupported_format_should_not_show_compress_info_in_library() {
350
- $this->upload_media( 'test/fixtures/input-example.gif' );
351
- $this->assertEquals( '', $this->find( 'td.column-tiny-compress-images' )->getText() );
352
- }
353
-
354
- public function test_non_image_file_should_not_show_compress_info_in_library() {
355
- $this->upload_media( 'test/fixtures/input-example.pdf' );
356
- $this->assertEquals( '', $this->find( 'td.column-tiny-compress-images' )->getText() );
357
- }
358
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/integration/DashboardWidgetIntegrationTest.php DELETED
@@ -1,72 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/IntegrationTestCase.php';
4
-
5
- class DashboardWidgetIntegrationTest extends IntegrationTestCase {
6
- public function set_up() {
7
- parent::set_up();
8
- $this->visit( '/wp-admin/index.php' );
9
- }
10
-
11
- public function tear_down() {
12
- parent::tear_down();
13
- clear_settings();
14
- clear_uploads();
15
- }
16
-
17
- public function test_should_show_widget_without_images() {
18
- $element = $this->find(
19
- '#no-images-uploaded p'
20
- );
21
-
22
- $this->assertEquals(
23
- 'You do not seem to have uploaded any JPEG or PNG images yet.',
24
- $element->getText()
25
- );
26
- }
27
-
28
-
29
- public function test_should_show_widget_without_optimized_images() {
30
- $this->upload_media( 'test/fixtures/input-example.jpg' );
31
- $this->visit( '/wp-admin/index.php' );
32
- $element = $this->find(
33
- '#widget-not-optimized p'
34
- );
35
-
36
- $this->assertEquals(
37
- 'Hi Admin, you haven’t compressed any images in your media library. If you like you can to optimize your whole library in one go with the bulk optimization page.',
38
- $element->getText()
39
- );
40
- }
41
-
42
- public function test_should_show_widget_with_some_images_optimized() {
43
- $this->upload_media( 'test/fixtures/input-example.jpg' );
44
- $this->set_api_key( 'JPG123' );
45
- $this->upload_media( 'test/fixtures/input-example.jpg' );
46
- $this->visit( '/wp-admin/index.php' );
47
-
48
- $element = $this->find(
49
- '#tinypng_dashboard_widget #widget-half-optimized p'
50
- );
51
-
52
- $this->assertContains(
53
- 'Admin, you are doing good. With your current settings you can still optimize',
54
- $element->getText()
55
- );
56
- }
57
-
58
- public function test_should_show_widget_with_all_images_optimized() {
59
- $this->set_api_key( 'JPG123' );
60
- $this->upload_media( 'test/fixtures/input-example.jpg' );
61
- $this->visit( '/wp-admin/index.php' );
62
-
63
- $element = $this->find(
64
- '#tinypng_dashboard_widget #widget-full-optimized p'
65
- );
66
-
67
- $this->assertEquals(
68
- 'Admin, this is great! Your entire library is optimized!',
69
- $element->getText()
70
- );
71
- }
72
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/integration/IntegrationTestCase.php DELETED
@@ -1,170 +0,0 @@
1
- <?php
2
-
3
- require dirname( __FILE__ ) . '/../unit/TinyTestCase.php';
4
- require dirname( __FILE__ ) . '/../helpers/setup.php';
5
-
6
- use Facebook\WebDriver\WebDriverBy;
7
- use Facebook\WebDriver\WebDriverExpectedCondition;
8
- use Facebook\WebDriver\Remote\RemoteWebDriver;
9
-
10
- abstract class IntegrationTestCase extends Tiny_TestCase {
11
- protected static $driver;
12
- protected static $db;
13
-
14
- public static function set_up_before_class() {
15
- self::$driver = RemoteWebDriver::createBySessionId(
16
- $GLOBALS['global_session_id'],
17
- $GLOBALS['global_webdriver_host']
18
- );
19
-
20
- self::$db = new mysqli( getenv( 'HOST' ), 'root',
21
- getenv( 'MYSQL_PWD' ),
22
- getenv( 'WORDPRESS_DATABASE' )
23
- );
24
- }
25
-
26
- protected function visit( $path ) {
27
- self::$driver->get( wordpress( $path ) );
28
- }
29
-
30
- protected function refresh() {
31
- self::$driver->navigate()->refresh();
32
- }
33
-
34
- protected function find( $selector, $base = null ) {
35
- if ( ! $base ) {
36
- $base = self::$driver;
37
- }
38
-
39
- return $base->findElement(
40
- WebDriverBy::cssSelector( $selector )
41
- );
42
- }
43
-
44
- protected function find_all( $selector, $base = null ) {
45
- if ( ! $base ) {
46
- $base = self::$driver;
47
- }
48
-
49
- return $base->findElements(
50
- WebDriverBy::cssSelector( $selector )
51
- );
52
- }
53
-
54
- protected function find_link( $text ) {
55
- return self::$driver->findElement(
56
- WebDriverBy::partialLinkText( $text )
57
- );
58
- }
59
-
60
- protected function find_button( $text ) {
61
- return self::$driver->findElement(
62
- WebDriverBy::cssSelector( "input[value='{$text}']" )
63
- );
64
- }
65
-
66
- protected function wait_for_text( $selector, $text ) {
67
- self::$driver->wait( 2 )->until(
68
- WebDriverExpectedCondition::textToBePresentInElement(
69
- WebDriverBy::cssSelector( $selector ), $text
70
- )
71
- );
72
- }
73
-
74
- protected function wait_for_text_disappearance( $selector, $text ) {
75
- self::$driver->wait( 2 )->until(
76
- WebDriverExpectedCondition::invisibilityOfElementWithText(
77
- WebDriverBy::cssSelector( $selector ), $text
78
- )
79
- );
80
- }
81
-
82
- protected function has_postbox_container() {
83
- return wordpress_version() >= 35;
84
- }
85
-
86
- protected function has_medium_large_size() {
87
- return wordpress_version() >= 44;
88
- }
89
-
90
- protected function postbox_dimension_selector() {
91
- $version = wordpress_version();
92
- if ( $version < 37 ) {
93
- return 'div.misc-pub-section:nth-child(5)';
94
- } elseif ( $version == 37 ) {
95
- return 'div.misc-pub-section:nth-child(6)';
96
- } else {
97
- return 'div.misc-pub-dimensions';
98
- }
99
- }
100
-
101
- protected function upload_media( $path ) {
102
- $this->visit( '/wp-admin/media-new.php?browser-uploader&flash=0' );
103
-
104
- $links = $this->find_all( 'p.upload-flash-bypass a' );
105
- if ( count( $links ) > 0 && $links[0]->isDisplayed() ) {
106
- $links[0]->click();
107
- }
108
-
109
- $this->find( 'input[name=async-upload]' )->sendKeys( $path );
110
- $this->find( 'input[type=submit]' )->click();
111
-
112
- $this->wait_for_text( 'div.wrap h1, div.wrap h2', 'Media Library' );
113
- }
114
-
115
- protected function set_api_key( $api_key, $wait = true ) {
116
- $this->set_option( 'tinypng_api_key', $api_key );
117
- }
118
-
119
- protected function enable_compression_sizes( $sizes ) {
120
- $value = array( '_tiny_dummy' => 'on' );
121
- foreach ( $sizes as $size ) {
122
- $value[ $size ] = 'on';
123
- }
124
- $this->set_option( 'tinypng_sizes', serialize( $value ) );
125
- }
126
-
127
- protected function enable_preserve( $keys ) {
128
- $value = array();
129
- foreach ( $keys as $key ) {
130
- $value[ $key ] = 'on';
131
- }
132
- $this->set_option( 'tinypng_preserve_data', serialize( $value ) );
133
- }
134
-
135
- protected function disable_preserve() {
136
- $this->unset_option( 'tinypng_preserve_data' );
137
- }
138
-
139
- protected function enable_resize( $options ) {
140
- $value = array( 'enabled' => 'on' );
141
- foreach ( $options as $option => $val ) {
142
- $value[ $option ] = $val;
143
- }
144
- $this->set_option( 'tinypng_resize_original', serialize( $value ) );
145
- }
146
-
147
- protected function disable_resize() {
148
- $this->unset_option( 'tinypng_resize_original' );
149
- }
150
-
151
- protected function set_option( $name, $value ) {
152
- $this->unset_option( $name );
153
-
154
- $query = self::$db->prepare(
155
- 'INSERT INTO wp_options (option_name, option_value) VALUES (?, ?)'
156
- );
157
-
158
- $query->bind_param( 'ss', $name, $value );
159
- $query->execute();
160
- }
161
-
162
- protected function unset_option( $name ) {
163
- $query = self::$db->prepare(
164
- 'DELETE FROM wp_options WHERE option_name = ?'
165
- );
166
-
167
- $query->bind_param( 's', $name );
168
- $query->execute();
169
- }
170
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/integration/PluginIntegrationTest.php DELETED
@@ -1,41 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/IntegrationTestCase.php';
4
-
5
- use Facebook\WebDriver\WebDriverBy;
6
-
7
- class PluginIntegrationTest extends IntegrationTestCase {
8
- public function set_up() {
9
- parent::set_up();
10
- $this->visit( '/wp-admin/plugins.php' );
11
- }
12
-
13
- public function tear_down() {
14
- parent::tear_down();
15
- clear_settings();
16
- }
17
-
18
- public function test_plugin_list_should_include_title() {
19
- $element = $this->find(
20
- 'tr[data-slug=tiny-compress-images] td.plugin-title strong, ' . /* WP4.5+ */
21
- 'tr#compress-jpeg-png-images td.plugin-title strong'
22
- );
23
-
24
- $this->assertEquals(
25
- 'Compress JPEG & PNG images',
26
- $element->getText()
27
- );
28
- }
29
-
30
- public function test_plugin_list_should_include_settings_link() {
31
- $element = $this->find(
32
- 'tr[data-slug=tiny-compress-images] span.settings a, ' . /* WP4.5+ */
33
- 'tr#compress-jpeg-png-images span.settings a'
34
- );
35
-
36
- $this->assertStringEndsWith(
37
- 'options-media.php#tiny-compress-images',
38
- $element->getAttribute( 'href' )
39
- );
40
- }
41
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/integration/SettingsIntegrationTest.php DELETED
@@ -1,293 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/IntegrationTestCase.php';
4
-
5
- class SettingsIntegrationTest extends IntegrationTestCase {
6
- public function set_up() {
7
- parent::set_up();
8
- $this->visit( '/wp-admin/options-media.php' );
9
- }
10
-
11
- public function tear_down() {
12
- parent::tear_down();
13
- clear_settings();
14
- clear_uploads();
15
- }
16
-
17
- protected function get_enabled_sizes() {
18
- return array_map( function( $checkbox ) {
19
- return $checkbox->getAttribute( 'name' );
20
- }, $this->find_all( 'input[type=checkbox][checked][name^=tinypng_sizes]' ) );
21
- }
22
-
23
- public function test_settings_should_contain_title() {
24
- $headings = array_map( function( $heading ) {
25
- return $heading->getText();
26
- }, $this->find_all( 'h2, h3' ) );
27
-
28
- $this->assertContains( 'JPEG and PNG optimization', $headings );
29
- }
30
-
31
- public function test_settings_should_show_notice_if_key_is_missing() {
32
- $this->assertStringEndsWith(
33
- 'options-media.php#tiny-compress-images',
34
- $this->find( '.error a' )->getAttribute( 'href' )
35
- );
36
- }
37
-
38
- public function test_settings_should_not_show_notice_if_key_is_set() {
39
- $this->set_api_key( 'PNG123' );
40
- $this->refresh();
41
-
42
- $this->assertEquals( 0, count( $this->find_all( '.error a' ) ) );
43
- }
44
-
45
- public function test_settings_should_store_valid_api_key() {
46
- $this->find( '#tinypng_api_key' )->sendKeys( 'PNG123' );
47
- $this->find( 'button[data-tiny-action=update-key]' )->click();
48
-
49
- $this->wait_for_text(
50
- 'div.tiny-account-status p.status',
51
- 'Your account is connected'
52
- );
53
-
54
- $this->refresh();
55
-
56
- $this->assertEquals(
57
- 'Your account is connected',
58
- $this->find( 'div.tiny-account-status p.status' )->getText()
59
- );
60
- }
61
-
62
- public function test_settings_should_not_store_invalid_api_key() {
63
- $this->find( '#tinypng_api_key' )->sendKeys( 'INVALID123' );
64
- $this->find( 'button[data-tiny-action=update-key]' )->click();
65
-
66
- $this->wait_for_text(
67
- 'div.tiny-account-status div.update p.message',
68
- 'The key that you have entered is not valid'
69
- );
70
-
71
- $this->refresh();
72
-
73
- $this->assertEquals(
74
- 'Register new account',
75
- $this->find( 'div.tiny-account-status h4' )->getText()
76
- );
77
- }
78
-
79
- public function test_settings_should_allow_changing_api_key() {
80
- $this->find( '#tinypng_api_key' )->sendKeys( 'PNG123' );
81
- $this->find( 'button[data-tiny-action=update-key]' )->click();
82
-
83
- $this->wait_for_text(
84
- 'div.tiny-account-status p.status',
85
- 'Your account is connected'
86
- );
87
-
88
- $this->find_link( 'Change API key' )->click();
89
-
90
- $this->find( '#tinypng_api_key' )->sendKeys( 'JPG123' );
91
- $this->find( 'button[data-tiny-action=update-key]' )->click();
92
-
93
- $this->wait_for_text(
94
- 'div.tiny-account-status p.status',
95
- 'Your account is connected'
96
- );
97
- }
98
-
99
- public function test_settings_should_pre_fill_registration_form() {
100
- $this->assertEquals(
101
- '',
102
- $this->find( '#tinypng_api_key_name' )->getAttribute( 'value' )
103
- );
104
-
105
- $this->assertEquals(
106
- 'developers@voormedia.com',
107
- $this->find( '#tinypng_api_key_email' )->getAttribute( 'value' )
108
- );
109
- }
110
-
111
- public function test_settings_should_not_send_registration_without_name() {
112
- $this->find( '#tinypng_api_key_name' )->clear();
113
- $this->find( '#tinypng_api_key_email' )->clear()->sendKeys( 'john@example.com' );
114
- $this->find( 'button[data-tiny-action=create-key]' )->click();
115
-
116
- $this->wait_for_text(
117
- 'div.tiny-account-status div.create p.message',
118
- 'Please enter your name'
119
- );
120
-
121
- $this->refresh();
122
-
123
- $this->assertEquals(
124
- 'Register new account',
125
- $this->find( 'div.tiny-account-status h4' )->getText()
126
- );
127
- }
128
-
129
- public function test_settings_should_not_send_registration_without_email() {
130
- $this->find( '#tinypng_api_key_name' )->clear()->sendKeys( 'John' );
131
- $this->find( '#tinypng_api_key_email' )->clear();
132
- $this->find( 'button[data-tiny-action=create-key]' )->click();
133
-
134
- $this->wait_for_text(
135
- 'div.tiny-account-status div.create p.message',
136
- 'Please enter your email address'
137
- );
138
-
139
- $this->refresh();
140
-
141
- $this->assertEquals(
142
- 'Register new account',
143
- $this->find( 'div.tiny-account-status h4' )->getText()
144
- );
145
- }
146
-
147
- public function test_settings_should_store_registration_key() {
148
- $this->find( '#tinypng_api_key_name' )->clear()->sendKeys( 'John' );
149
- $this->find( '#tinypng_api_key_email' )->clear()->sendKeys( 'john@example.com' );
150
- $this->find( 'button[data-tiny-action=create-key]' )->click();
151
-
152
- $this->wait_for_text(
153
- 'div.tiny-account-status p.status',
154
- 'An email has been sent with a link to activate your account'
155
- );
156
-
157
- $this->refresh();
158
-
159
- $this->assertEquals(
160
- 'An email has been sent with a link to activate your account',
161
- $this->find( 'div.tiny-account-status p.status' )->getText()
162
- );
163
- }
164
-
165
- public function test_settings_should_enable_all_sizes_by_default() {
166
- $enabled_sizes = $this->get_enabled_sizes();
167
-
168
- $this->assertContains( 'tinypng_sizes[0]', $enabled_sizes );
169
- $this->assertContains( 'tinypng_sizes[thumbnail]', $enabled_sizes );
170
- $this->assertContains( 'tinypng_sizes[medium]', $enabled_sizes );
171
- if ( $this->has_medium_large_size() ) {
172
- $this->assertContains( 'tinypng_sizes[medium_large]', $enabled_sizes );
173
- }
174
- $this->assertContains( 'tinypng_sizes[large]', $enabled_sizes );
175
- }
176
-
177
- public function test_settings_should_store_enabled_sizes() {
178
- $this->find( '#tinypng_sizes_medium' )->click();
179
- $this->find( '#tinypng_sizes_0' )->click();
180
- $this->find( 'form' )->submit();
181
-
182
- $enabled_sizes = $this->get_enabled_sizes();
183
-
184
- $this->assertNotContains( 'tinypng_sizes[0]', $enabled_sizes );
185
- $this->assertContains( 'tinypng_sizes[thumbnail]', $enabled_sizes );
186
- $this->assertNotContains( 'tinypng_sizes[medium]', $enabled_sizes );
187
- $this->assertContains( 'tinypng_sizes[large]', $enabled_sizes );
188
- }
189
-
190
- public function test_settings_should_store_all_disabled_sizes() {
191
- $checkboxes = $this->find_all(
192
- 'input[type=checkbox][checked][name^=tinypng_sizes]'
193
- );
194
-
195
- foreach ( $checkboxes as $checkbox ) {
196
- $checkbox->click();
197
- }
198
-
199
- $this->find( 'form' )->submit();
200
-
201
- $enabled_sizes = $this->get_enabled_sizes();
202
- $this->assertEquals( 0, count( $enabled_sizes ) );
203
- }
204
-
205
- public function test_settings_should_show_free_compressions() {
206
- $this->enable_compression_sizes(
207
- array( '0', 'thumbnail', 'medium', 'large' )
208
- );
209
-
210
- $this->refresh();
211
-
212
- $this->assertContains(
213
- 'With these settings you can compress at least 125 images for free each month.',
214
- $this->find( '#tiny-image-sizes-notice' )->getText()
215
- );
216
- }
217
-
218
- public function test_settings_should_update_free_compressions() {
219
- $this->enable_compression_sizes(
220
- array( '0', 'thumbnail', 'medium', 'large' )
221
- );
222
-
223
- $this->refresh();
224
- $this->find( '#tinypng_sizes_medium' )->click();
225
-
226
- $this->assertContains(
227
- 'With these settings you can compress at least 166 images for free each month.',
228
- $this->find( '#tiny-image-sizes-notice' )->getText()
229
- );
230
- }
231
-
232
- public function test_settings_should_show_no_compressions() {
233
- $checkboxes = $this->find_all(
234
- 'input[type=checkbox][checked][name^=tinypng_sizes]'
235
- );
236
-
237
- foreach ( $checkboxes as $checkbox ) {
238
- $checkbox->click();
239
- }
240
-
241
- $this->assertContains(
242
- 'With these settings no images will be compressed.',
243
- $this->find( '#tiny-image-sizes-notice' )->getText()
244
- );
245
- }
246
-
247
- public function test_settings_should_show_resizing_when_original_enabled() {
248
- $elements = $this->find_all( 'label[for=tinypng_resize_original_enabled]' );
249
- $this->assertEquals(
250
- 'Resize and compress the original image',
251
- $elements[0]->getText()
252
- );
253
-
254
- $elements = $this->find_all( 'p.tiny-resize-unavailable' );
255
- $this->assertEquals(
256
- '',
257
- $elements[0]->getText()
258
- );
259
- }
260
-
261
- public function test_settings_should_not_show_resizing_when_original_disabled() {
262
- $this->find( '#tinypng_sizes_0' )->click(); /* Enabled by default */
263
-
264
- $elements = $this->find_all( 'label[for=tinypng_resize_original_enabled]' );
265
- $this->assertEquals(
266
- '',
267
- $elements[0]->getText()
268
- );
269
-
270
- $elements = $this->find_all( 'p.tiny-resize-unavailable' );
271
- $this->assertEquals(
272
- 'Enable compression of the original image size for more options.',
273
- $elements[0]->getText()
274
- );
275
- }
276
-
277
- public function test_settings_should_store_resizing_settings() {
278
- $this->find( '#tinypng_resize_original_enabled' )->click();
279
- $this->find( '#tinypng_resize_original_width' )->clear()->sendKeys( '234' );
280
- $this->find( '#tinypng_resize_original_height' )->clear()->sendKeys( '345' );
281
- $this->find( 'form' )->submit();
282
-
283
- $this->assertEquals(
284
- '234',
285
- $this->find( '#tinypng_resize_original_width' )->getAttribute( 'value' )
286
- );
287
-
288
- $this->assertEquals(
289
- '345',
290
- $this->find( '#tinypng_resize_original_height' )->getAttribute( 'value' )
291
- );
292
- }
293
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/mock-tinypng-webservice/.htaccess DELETED
@@ -1,5 +0,0 @@
1
- RewriteEngine On
2
- RewriteRule ^keys$ keys.php [last]
3
- RewriteRule ^shrink$ shrink.php [last]
4
- RewriteRule ^output/.+$ output.php [last]
5
- RewriteRule ^reset$ reset.php [last]
 
 
 
 
 
test/mock-tinypng-webservice/common.php DELETED
@@ -1,50 +0,0 @@
1
- <?php
2
-
3
- define('SESSION_FILE', '/tmp/session.dat');
4
-
5
- if (file_exists(SESSION_FILE)) {
6
- $session = unserialize(file_get_contents(SESSION_FILE));
7
- } else {
8
- $session = array( 'Compression-Count' => 0 );
9
- }
10
-
11
- function save_session() {
12
- global $session;
13
- if ($session) {
14
- file_put_contents(SESSION_FILE, serialize($session));
15
- } elseif (file_exists(SESSION_FILE)) {
16
- unlink(SESSION_FILE);
17
- }
18
- }
19
- register_shutdown_function('save_session');
20
-
21
- function get_api_key() {
22
- $request_headers = apache_request_headers();
23
- if (!isset($request_headers['Authorization'])) {
24
- return null;
25
- }
26
- $basic_auth = base64_decode(str_replace('Basic ', '', $request_headers['Authorization']));
27
- return next(explode(':', $basic_auth));
28
- }
29
-
30
- function get_json_body() {
31
- return json_decode(file_get_contents("php://input"));
32
- }
33
-
34
- function mock_invalid_response() {
35
- global $session;
36
-
37
- header('HTTP/1.1 401 Unauthorized');
38
- header("Content-Type: application/json; charset=utf-8");
39
-
40
- $response = array(
41
- "error" => "Unauthorized",
42
- "message" => "Credentials are invalid "
43
- );
44
- return json_encode($response);
45
- }
46
-
47
- function mock_service_unavailable_response() {
48
- header('HTTP/1.1 503 Service unavailable');
49
- return 'HTTP Error 503. The service is unavailable';
50
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/mock-tinypng-webservice/keys.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- ob_start();
4
-
5
- header('HTTP/1.1 202 Pending');
6
- header("Content-Type: application/json; charset=utf-8");
7
-
8
- echo json_encode(
9
- array(
10
- 'key' => 'PENDING123',
11
- )
12
- );
13
-
14
- ob_end_flush();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/mock-tinypng-webservice/output-copyright.jpg DELETED
Binary file
test/mock-tinypng-webservice/output-example.jpg DELETED
Binary file
test/mock-tinypng-webservice/output-example.png DELETED
Binary file
test/mock-tinypng-webservice/output-resized.jpg DELETED
Binary file
test/mock-tinypng-webservice/output.php DELETED
@@ -1,50 +0,0 @@
1
- <?php
2
- ob_start();
3
-
4
- require_once 'common.php';
5
-
6
- if (preg_match('#output/.+[.](png|jpg)$#', $_SERVER['REQUEST_URI'], $match)) {
7
- $file = str_replace('/', '-', $match[0]);
8
- $ext = $match[1];
9
- $mime = $match[1] == 'jpg' ? 'image/jpeg' : "image/$ext";
10
- } else {
11
- $file = null;
12
- }
13
- $headers = [];
14
-
15
- $api_key = get_api_key();
16
- if (!is_null($api_key)) {
17
- $data = get_json_body();
18
- $resize = $data->resize;
19
- if ($resize->method) {
20
- $file = "output-resized.$ext";
21
- }
22
- }
23
-
24
- if (strpos($api_key, 'GATEWAYTIMEOUT') !== false) {
25
- echo mock_service_unavailable_response();
26
- } else if (strpos($api_key, 'INVALID') !== false) {
27
- header('HTTP/1.1 400 Bad Request');
28
- header("Content-Type: application/json; charset=utf-8");
29
-
30
- $response = array(
31
- "error" => "JSON validation error",
32
- "message" => "Metadata key 'author' not supported"
33
- );
34
- echo json_encode($response);
35
- } else if ($file && file_exists($file)) {
36
- list($width, $height) = getimagesize($file);
37
- header("Content-Type: $mime");
38
- header('Content-Disposition: attachment');
39
- header('Image-Width: ' . $width);
40
- header('Image-Height: ' . $height);
41
- header('Content-Length: ' . filesize($file));
42
- foreach ($headers as $name => $value) {
43
- header("$name: $value");
44
- }
45
- readfile($file);
46
- } else {
47
- header("HTTP/1.1 404 Not Found");
48
- }
49
-
50
- ob_end_flush();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/mock-tinypng-webservice/reset.php DELETED
@@ -1,4 +0,0 @@
1
- <?php
2
-
3
- require 'common.php';
4
- $session = null;
 
 
 
 
test/mock-tinypng-webservice/shrink.php DELETED
@@ -1,133 +0,0 @@
1
- <?php
2
- ob_start();
3
-
4
- require_once 'common.php';
5
-
6
- function mock_png_response() {
7
- global $session;
8
-
9
- $session['Compression-Count'] += 1;
10
- header('HTTP/1.1 201 Created');
11
- header("Location: http://webservice/output/example.png");
12
- header("Content-Type: application/json; charset=utf-8");
13
- header("Compression-Count: {$session['Compression-Count']}");
14
- header("Image-Width: 720");
15
- header("Image-Height: 1080");
16
-
17
- $response = array(
18
- "input" => array( "size" => 641206, "type" => "image/png" ),
19
- "output" => array( "size" => 151021, "type" => "image/png", "ratio" => 0.933 )
20
- );
21
- return json_encode($response);
22
- }
23
-
24
- function mock_jpg_response() {
25
- global $session;
26
-
27
- $session['Compression-Count'] += 1;
28
- header('HTTP/1.1 201 Created');
29
- header("Location: http://webservice/output/example.jpg");
30
- header("Content-Type: application/json; charset=utf-8");
31
- header("Compression-Count: {$session['Compression-Count']}");
32
- header("Image-Width: 200");
33
- header("Image-Height: 150");
34
-
35
- $response = array(
36
- "input" => array( "size" => 15391, "type" => "image/jpeg" ),
37
- "output" => array( "size" => 13910, "type" => "image/jpeg", "ratio" => 0.904 )
38
- );
39
- return json_encode($response);
40
- }
41
-
42
- function mock_preserve_jpg_copyright_response() {
43
- global $session;
44
-
45
- $session['Compression-Count'] += 1;
46
- header('HTTP/1.1 201 Created');
47
- header("Location: http://webservice/output/copyright.jpg");
48
- header("Content-Type: application/json; charset=utf-8");
49
- header("Compression-Count: {$session['Compression-Count']}");
50
- header("Image-Width: 330");
51
- header("Image-Height: 1080");
52
-
53
- $response = array(
54
- "input" => array( "size" => 110329, "type" => "image/jpeg" ),
55
- "output" => array( "size" => 97835, "type" => "image/jpeg", "ratio" => 0.8868 )
56
- );
57
- return json_encode($response);
58
- }
59
-
60
- function mock_empty_response() {
61
- global $session;
62
-
63
- header('HTTP/1.1 400 Bad Request');
64
- header("Content-Type: application/json; charset=utf-8");
65
- header("Compression-Count: {$session['Compression-Count']}");
66
-
67
- $response = array(
68
- "error" => "Input missing",
69
- "message" => "File is empty"
70
- );
71
- return json_encode($response);
72
- }
73
-
74
- function mock_limit_reached_response() {
75
- global $session;
76
-
77
- header('HTTP/1.1 429 Too Many Requests');
78
- header("Content-Type: application/json; charset=utf-8");
79
- header("Compression-Count: 500");
80
-
81
- $response = array(
82
- "error" => "Too many requests",
83
- "message" => "Your monthly limit has been exceeded"
84
- );
85
- return json_encode($response);
86
- }
87
-
88
- function mock_invalid_json_response() {
89
- global $session;
90
-
91
- $session['Compression-Count'] += 1;
92
- header('HTTP/1.1 201 Created');
93
- header("Location: http://webservice/output/example.png");
94
- header("Content-Type: application/json; charset=utf-8");
95
- header("Compression-Count: {$session['Compression-Count']}");
96
- return '{invalid: json}';
97
- }
98
-
99
-
100
- $api_key = get_api_key();
101
- if (substr($api_key, 0, 6) == 'PNG123') {
102
- if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
103
- echo mock_empty_response();
104
- } else {
105
- echo mock_png_response();
106
- }
107
- } else if ($api_key == 'JPG123') {
108
- if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
109
- echo mock_empty_response();
110
- } else {
111
- echo mock_jpg_response();
112
- }
113
- } else if ($api_key == 'PRESERVEJPG123') {
114
- if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
115
- echo mock_empty_response();
116
- } else {
117
- echo mock_preserve_jpg_copyright_response();
118
- }
119
- } else if ($api_key == 'JSON1234') {
120
- if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
121
- echo mock_empty_response();
122
- } else {
123
- echo mock_invalid_json_response();
124
- }
125
- } else if ($api_key == 'LIMIT123') {
126
- echo mock_limit_reached_response();
127
- } else if ($api_key == 'GATEWAYTIMEOUT') {
128
- echo mock_service_unavailable_response();
129
- } else {
130
- echo mock_invalid_response();
131
- }
132
-
133
- ob_end_flush();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyCompressClientTest.php DELETED
@@ -1,48 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyCompressSharedTestCase.php';
4
-
5
- class Tiny_Compress_Client_Test extends Tiny_Compress_Shared_TestCase {
6
- public static function set_up_before_class() {
7
- Tiny_PHP::$client_supported = true;
8
- }
9
-
10
- public function set_up() {
11
- parent::set_up();
12
- $this->client = new MockTinifyClient();
13
- Tinify\Tinify::setClient( $this->client );
14
- }
15
-
16
- protected function register( $method, $url, $details ) {
17
- $this->client->register( $method, $url, $details );
18
- }
19
-
20
- public function test_should_return_client_compressor() {
21
- $this->assertInstanceOf( 'Tiny_Compress_Client', $this->compressor );
22
- }
23
-
24
- public function test_can_create_key_should_return_true() {
25
- $this->assertSame( true, $this->compressor->can_create_key() );
26
- }
27
-
28
- public function test_create_key_should_set_api_key() {
29
- $this->register( 'POST', '/keys', array(
30
- 'status' => 202,
31
- 'headers' => array(
32
- 'content-type' => 'application/json',
33
- ),
34
- 'body' => json_encode(array(
35
- 'key' => 'newkey123',
36
- )),
37
- ));
38
-
39
- $this->compressor->create_key( 'john@example.com', array(
40
- 'name' => 'John Doe',
41
- ));
42
-
43
- $this->assertEquals(
44
- 'newkey123',
45
- $this->compressor->get_key()
46
- );
47
- }
48
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyCompressFopenTest.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyCompressSharedTestCase.php';
4
-
5
- class Tiny_Compress_Fopen_Test extends Tiny_Compress_Shared_TestCase {
6
- public static function set_up_before_class() {
7
- Tiny_PHP::$client_supported = false;
8
- }
9
-
10
- public function set_up() {
11
- stream_wrapper_unregister( 'https' );
12
- stream_wrapper_register( 'https', 'MockHttpStreamWrapper', STREAM_IS_URL );
13
- MockHttpStreamWrapper::clear();
14
- parent::set_up();
15
- }
16
-
17
- public function tear_down() {
18
- parent::tear_down();
19
- stream_wrapper_restore( 'http' );
20
- }
21
-
22
- protected function register( $method, $url, $details ) {
23
- MockHttpStreamWrapper::register( $method, $url, $details );
24
- }
25
-
26
- public function test_should_return_fopen_compressor_if_client_not_supported() {
27
- $this->assertInstanceOf( 'Tiny_Compress_Fopen', $this->compressor );
28
- }
29
-
30
- public function test_can_create_key_should_return_false() {
31
- $this->assertSame( false, $this->compressor->can_create_key() );
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyCompressNoClientTest.php DELETED
@@ -1,15 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Compress_No_Client_Test extends Tiny_TestCase {
6
- public static function set_up_before_class() {
7
- Tiny_PHP::$client_supported = false;
8
- Tiny_PHP::$fopen_available = false;
9
- }
10
-
11
- public function test_should_throw_error_when_curl_and_fopen_unavailable() {
12
- $this->setExpectedException( 'Tiny_Exception' );
13
- Tiny_Compress::create( 'api1234' );
14
- }
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyCompressSharedTestCase.php DELETED
@@ -1,304 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- abstract class Tiny_Compress_Shared_TestCase extends Tiny_TestCase {
6
- public function set_up() {
7
- parent::set_up();
8
- $this->after_compress_called = false;
9
- $after_compress_called = &$this->after_compress_called;
10
- $callback = function( $compressor ) use ( &$after_compress_called ) {
11
- $after_compress_called = true;
12
- };
13
- $this->compressor = Tiny_Compress::create( 'api1234', $callback );
14
- }
15
-
16
- protected abstract function register( $method, $url, $details );
17
-
18
- public function test_should_return_client_compressor() {
19
- $this->assertInstanceOf( 'Tiny_Compress', $this->compressor );
20
- }
21
-
22
- public function test_get_key_should_return_key() {
23
- $this->assertSame( 'api1234', $this->compressor->get_key() );
24
- }
25
-
26
- public function test_get_status_should_return_success_status() {
27
- $this->register( 'POST', '/shrink', array(
28
- 'status' => 400,
29
- 'headers' => array(
30
- 'content-type' => 'application/json',
31
- ),
32
- 'body' => json_encode(array(
33
- 'error' => 'Input missing',
34
- 'message' => 'No file provided',
35
- )),
36
- ));
37
-
38
- $this->assertEquals(
39
- (object) array(
40
- 'ok' => true,
41
- 'message' => null,
42
- ),
43
- $this->compressor->get_status()
44
- );
45
-
46
- $this->assertEquals(
47
- false,
48
- $this->compressor->limit_reached()
49
- );
50
-
51
- $this->assertEquals(
52
- true,
53
- $this->after_compress_called
54
- );
55
- }
56
-
57
- public function test_get_status_should_return_limit_reached_status() {
58
- $this->register( 'POST', '/shrink', array(
59
- 'status' => 429,
60
- 'headers' => array(
61
- 'content-type' => 'application/json',
62
- ),
63
- 'body' => json_encode(array(
64
- 'error' => 'Too many requests',
65
- 'message' => 'Your monthly limit has been exceeded',
66
- )),
67
- ));
68
-
69
- $this->assertEquals(
70
- (object) array(
71
- 'ok' => true,
72
- 'message' => null,
73
- ),
74
- $this->compressor->get_status()
75
- );
76
-
77
- $this->assertEquals(
78
- true,
79
- $this->compressor->limit_reached()
80
- );
81
-
82
- $this->assertEquals(
83
- true,
84
- $this->after_compress_called
85
- );
86
- }
87
-
88
- public function test_get_status_should_return_unauthorized_status() {
89
- $this->register( 'POST', '/shrink', array(
90
- 'status' => 401,
91
- 'headers' => array(
92
- 'content-type' => 'application/json',
93
- ),
94
- 'body' => json_encode(array(
95
- 'error' => 'Unauthorized',
96
- 'message' => 'Credentials are invalid',
97
- )),
98
- ));
99
-
100
- $this->assertEquals(
101
- (object) array(
102
- 'ok' => false,
103
- 'message' => 'The key that you have entered is not valid',
104
- ),
105
- $this->compressor->get_status()
106
- );
107
-
108
- $this->assertEquals(
109
- false,
110
- $this->compressor->limit_reached()
111
- );
112
-
113
- $this->assertEquals(
114
- true,
115
- $this->after_compress_called
116
- );
117
- }
118
-
119
- public function test_compress_file_should_save_compressed_file() {
120
- $this->register( 'POST', '/shrink', array(
121
- 'status' => 201,
122
- 'headers' => array(
123
- 'location' => 'https://api.tinify.com/output/compressed.png',
124
- 'content-type' => 'application/json',
125
- ),
126
- 'body' => '{}',
127
- ));
128
-
129
- $handler = array(
130
- 'status' => 200,
131
- 'headers' => array(
132
- 'content-type' => 'image/png',
133
- 'content-length' => 9,
134
- 'image-width' => 10,
135
- 'image-height' => 15,
136
- ),
137
- 'body' => 'optimized',
138
- );
139
-
140
- $this->register( 'GET', '/output/compressed.png', $handler );
141
- $this->register( 'POST', '/output/compressed.png', $handler );
142
-
143
- file_put_contents( $this->vfs->url() . '/image.png', 'unoptimized' );
144
-
145
- $this->assertEquals(
146
- array(
147
- 'input' => array(
148
- 'size' => 11,
149
- 'type' => 'image/png',
150
- ),
151
- 'output' => array(
152
- 'size' => 9,
153
- 'type' => 'image/png',
154
- 'width' => 10,
155
- 'height' => 15,
156
- 'ratio' => round( 9 / 11, 4 ),
157
- ),
158
- ),
159
- $this->compressor->compress_file( $this->vfs->url() . '/image.png' )
160
- );
161
-
162
- $this->assertEquals(
163
- false,
164
- $this->compressor->limit_reached()
165
- );
166
-
167
- $this->assertEquals(
168
- true,
169
- $this->after_compress_called
170
- );
171
- }
172
-
173
- public function test_compress_file_should_save_resized_file() {
174
- $this->register( 'POST', '/shrink', array(
175
- 'status' => 201,
176
- 'headers' => array(
177
- 'location' => 'https://api.tinify.com/output/compressed.png',
178
- 'content-type' => 'application/json',
179
- ),
180
- 'body' => '{}',
181
- ));
182
-
183
- $handler = array(
184
- 'status' => 200,
185
- 'headers' => array(
186
- 'content-type' => 'image/png',
187
- 'content-length' => 5,
188
- 'image-width' => 6,
189
- 'image-height' => 9,
190
- ),
191
- 'body' => 'small',
192
- );
193
-
194
- $this->register( 'GET', '/output/compressed.png', $handler );
195
- $this->register( 'POST', '/output/compressed.png', $handler );
196
-
197
- $img = file_get_contents( 'test/fixtures/input-example.jpg' );
198
- file_put_contents( $this->vfs->url() . '/image.png', $img );
199
-
200
- $resize = array(
201
- 'width' => 9,
202
- 'method' => 'fit',
203
- );
204
-
205
- $this->assertEquals(
206
- array(
207
- 'input' => array(
208
- 'size' => 641206,
209
- 'type' => 'image/png',
210
- ),
211
- 'output' => array(
212
- 'size' => 5,
213
- 'type' => 'image/png',
214
- 'width' => 6,
215
- 'height' => 9,
216
- 'ratio' => round( 5 / 641206, 4 ),
217
- 'resized' => true,
218
- ),
219
- ),
220
- $this->compressor->compress_file( $this->vfs->url() . '/image.png', $resize )
221
- );
222
-
223
- $this->assertEquals(
224
- false,
225
- $this->compressor->limit_reached()
226
- );
227
-
228
- $this->assertEquals(
229
- true,
230
- $this->after_compress_called
231
- );
232
- }
233
-
234
- public function test_compress_file_should_return_unauthorized_status() {
235
- $this->register( 'POST', '/shrink', array(
236
- 'status' => 401,
237
- 'headers' => array(
238
- 'content-type' => 'application/json',
239
- ),
240
- 'body' => json_encode(array(
241
- 'error' => 'Unauthorized',
242
- 'message' => 'Credentials are invalid',
243
- )),
244
- ));
245
-
246
- file_put_contents( $this->vfs->url() . '/image.png', 'unoptimized' );
247
-
248
- $exception = null;
249
- try {
250
- $this->compressor->compress_file( $this->vfs->url() . '/image.png' );
251
- } catch (Exception $err) {
252
- $exception = $err;
253
- }
254
-
255
- $this->assertEquals(
256
- false,
257
- $this->compressor->limit_reached()
258
- );
259
-
260
- $this->assertEquals(
261
- true,
262
- $this->after_compress_called
263
- );
264
-
265
- $this->setExpectedException( 'Tiny_Exception' );
266
- throw $exception;
267
- }
268
-
269
- public function test_get_compression_count_should_return_null_before_compresion() {
270
- $this->assertSame( null, $this->compressor->get_compression_count() );
271
- }
272
-
273
- public function test_get_compression_count_should_return_count() {
274
- $this->register( 'POST', '/shrink', array(
275
- 'status' => 201,
276
- 'headers' => array(
277
- 'location' => 'https://api.tinify.com/output/compressed.png',
278
- 'content-type' => 'application/json',
279
- 'compression-count' => 12,
280
- ),
281
- 'body' => '{}',
282
- ));
283
-
284
- $handler = array(
285
- 'status' => 200,
286
- 'headers' => array(
287
- 'content-type' => 'image/png',
288
- 'content-length' => 9,
289
- 'image-width' => 10,
290
- 'image-height' => 15,
291
- 'compression-count' => 12,
292
- ),
293
- 'body' => 'optimized',
294
- );
295
-
296
- $this->register( 'GET', '/output/compressed.png', $handler );
297
- $this->register( 'POST', '/output/compressed.png', $handler );
298
-
299
- file_put_contents( $this->vfs->url() . '/image.png', 'unoptimized' );
300
- $this->compressor->compress_file( $this->vfs->url() . '/image.png' );
301
-
302
- $this->assertSame( 12, $this->compressor->get_compression_count() );
303
- }
304
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyCompressTest.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Compress_Common extends Tiny_TestCase {
6
- public function test_estimate_cost_free() {
7
- $this->assertEquals( 150 * 0,
8
- Tiny_Compress::estimate_cost( 150, 0 ) );
9
- }
10
-
11
- public function test_estimate_cost_normal_and_free() {
12
- $this->assertEquals( 350 * 0 + 2650 * 0.009,
13
- Tiny_Compress::estimate_cost( 3000, 150 ) );
14
- }
15
-
16
- public function test_estimate_cost_cheap_and_normal_and_free() {
17
- $this->assertEquals( 500 * 0 + 9500 * 0.009 + 40000 * 0.002,
18
- Tiny_Compress::estimate_cost( 50000, 0 ) );
19
- }
20
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyExceptionTest.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Exception_Test extends Tiny_TestCase {
6
- public function test_constructor_creates_exception_with_message() {
7
- $err = new Tiny_Exception( 'Message' );
8
- $this->assertInstanceOf( 'Tiny_Exception', $err );
9
- }
10
-
11
- public function test_constructor_creates_exception_with_message_and_error() {
12
- $err = new Tiny_Exception( 'Message', 'ErrorType' );
13
- $this->assertInstanceOf( 'Tiny_Exception', $err );
14
- }
15
-
16
- public function test_constructor_throws_if_message_is_not_a_string() {
17
- $this->setExpectedException( 'InvalidArgumentException' );
18
- new Tiny_Exception( 404, 'ErrorType' );
19
- }
20
-
21
- public function test_constructor_throws_if_error_is_not_a_string() {
22
- $this->setExpectedException( 'InvalidArgumentException' );
23
- new Tiny_Exception( 'Message', new Exception( 'err' ) );
24
- }
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyImageDuplicateTest.php DELETED
@@ -1,70 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Image_Duplicate_Test extends Tiny_TestCase {
6
- public function set_up() {
7
- parent::set_up();
8
-
9
- $this->wp->addImageSize( 'medium-2', array( 'width' => 300, 'height' => 300 ) );
10
- $this->wp->addImageSize( 'custom-thumbnail', array( 'width' => 175, 'height' => 175 ) );
11
- $this->wp->addImageSize( 'custom-thumbnail-2', array( 'width' => 175, 'height' => 175 ) );
12
-
13
- $this->wp->addOption( 'tinypng_sizes[medium-2]', 'on' );
14
- $this->wp->addOption( 'tinypng_sizes[custom-thumbnail]', 'off' );
15
- $this->wp->addOption( 'tinypng_sizes[custom-thumbnail-2]', 'on' );
16
- $this->wp->addOption( 'tinypng_sizes[custom-thumbnail-3]', 'on' );
17
-
18
- $this->wp->createImagesFromJSON( $this->json( 'image_filesystem_data' ) );
19
- $this->wp->setTinyMetadata( 1, $this->json( 'image_database_metadata' ) );
20
- $this->subject = new Tiny_Image( new Tiny_Settings(), 1, $this->json( '_wp_attachment_metadata_duplicates' ) );
21
- }
22
-
23
- public function test_get_images_should_return_all_images() {
24
- $this->assertEquals( array(
25
- Tiny_Image::ORIGINAL,
26
- 'medium',
27
- 'thumbnail',
28
- 'twentyfourteen-full-width',
29
- 'custom-thumbnail',
30
- 'custom-thumbnail-2',
31
- 'custom-thumbnail-3',
32
- 'failed',
33
- 'large',
34
- 'medium-2',
35
- 'small',
36
- ), array_keys( $this->subject->get_image_sizes() ) );
37
- }
38
-
39
- public function test_filter_images_should_filter_correctly() {
40
- $this->assertEquals( array(
41
- Tiny_Image::ORIGINAL,
42
- 'medium',
43
- ), array_keys( $this->subject->filter_image_sizes( 'compressed' ) ) );
44
- }
45
-
46
- public function test_filter_images_should_filter_duplicates_correctly() {
47
- $this->assertEquals( array(
48
- 'medium-2',
49
- 'custom-thumbnail',
50
- 'custom-thumbnail-3',
51
- ), array_keys( $this->subject->filter_image_sizes( 'is_duplicate' ) ) );
52
- }
53
-
54
- public function test_duplicate_images_should_be_linked_to_primary_size() {
55
- $this->assertEquals(
56
- 'medium',
57
- $this->subject->get_image_size( 'medium-2' )->duplicate_of_size()
58
- );
59
-
60
- $this->assertEquals(
61
- 'custom-thumbnail-2',
62
- $this->subject->get_image_size( 'custom-thumbnail' )->duplicate_of_size()
63
- );
64
-
65
- $this->assertEquals(
66
- 'custom-thumbnail-2',
67
- $this->subject->get_image_size( 'custom-thumbnail-3' )->duplicate_of_size()
68
- );
69
- }
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyImageEmptyTest.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Image_Empty_Test extends Tiny_TestCase {
6
- public function set_up() {
7
- parent::set_up();
8
-
9
- $this->wp->createImagesFromJSON( $this->json( 'image_filesystem_data' ) );
10
- $this->wp->setTinyMetadata( 1, '' );
11
- $this->subject = new Tiny_Image( new Tiny_Settings(), 1, $this->json( '_wp_attachment_metadata' ) );
12
- }
13
-
14
- public function test_get_savings() {
15
- $this->assertEquals( 0, $this->subject->get_savings( $this->subject->get_statistics() ) );
16
- }
17
-
18
- public function test_get_statistics() {
19
- $this->assertEquals( array(
20
- 'initial_total_size' => 328670,
21
- 'optimized_total_size' => 328670,
22
- 'image_sizes_optimized' => 0,
23
- 'available_unoptimized_sizes' => 4,
24
- ), $this->subject->get_statistics() );
25
- }
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyImageSizeTest.php DELETED
@@ -1,158 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Image_Size_Test extends Tiny_TestCase {
6
- public function set_up() {
7
- parent::set_up();
8
-
9
- $this->wp->createImagesFromJSON( $this->json( 'image_filesystem_data' ) );
10
- $this->wp->setTinyMetadata( 1, $this->json( 'image_database_metadata' ) );
11
- $tiny_image = new Tiny_Image( new Tiny_Settings(), 1, $this->json( '_wp_attachment_metadata' ) );
12
-
13
- $this->original = $tiny_image->get_image_size();
14
- $this->thumbnail = $tiny_image->get_image_size( 'thumbnail' );
15
- $this->small = $tiny_image->get_image_size( 'small' );
16
- $this->medium = $tiny_image->get_image_size( 'medium' );
17
- $this->large = $tiny_image->get_image_size( 'large' );
18
- }
19
-
20
- public function test_end_time_should_return_end_from_meta() {
21
- $this->assertEquals( 1447925138, $this->original->end_time() );
22
- }
23
-
24
- public function test_end_time_should_return_end_from_timestamp_if_end_is_unavailable() {
25
- $this->assertEquals( 1437925244, $this->thumbnail->end_time() );
26
- }
27
-
28
- public function test_end_time_should_return_null_if_unavailable() {
29
- $this->assertEquals( null, $this->medium->end_time() );
30
- }
31
-
32
- public function test_add_tiny_meta_start_should_add_start_time() {
33
- $this->large->add_tiny_meta_start();
34
- $this->assertEqualWithinDelta( time(), $this->large->meta['start'], 2 );
35
- }
36
-
37
- public function test_add_tiny_meta_start_should_unset_previous_response() {
38
- $this->medium->add_tiny_meta_start();
39
- $this->assertEqualWithinDelta( time(), $this->medium->meta['start'], 2 );
40
- }
41
-
42
- public function test_add_tiny_meta_should_add_end_time() {
43
- $this->large->add_tiny_meta_start();
44
- $this->large->add_tiny_meta( array( 'input' => array( 'size' => 1024 ), 'output' => array( 'size' => 1024 ) ) );
45
- $this->assertEqualWithinDelta( time(), $this->large->meta['end'], 2 );
46
- }
47
-
48
- public function test_add_response_should_response() {
49
- $this->large->add_tiny_meta_start();
50
- $this->large->add_tiny_meta( array( 'input' => array( 'size' => 1024 ), 'output' => array( 'size' => 1024 ) ) );
51
- $actual = $this->large->meta;
52
- unset( $actual['end'] );
53
- $this->assertEquals( array( 'input' => array( 'size' => 1024 ), 'output' => array( 'size' => 1024 ) ), $actual );
54
- }
55
-
56
- public function test_add_response_should_not_add_if_no_request_was_made() {
57
- $this->large->add_tiny_meta( array( 'input' => array( 'size' => 1024 ), 'output' => array( 'size' => 1024 ) ) );
58
- $this->assertEquals( array(), $this->large->meta );
59
- }
60
-
61
- public function test_add_exception_should_add_message_and_error() {
62
- $this->large->add_tiny_meta_start();
63
- $this->large->add_tiny_meta_error( new Tiny_Exception( 'Image could not be found', 'Not found' ) );
64
- unset( $this->large->meta['timestamp'] );
65
- $this->assertEquals( array( 'error' => 'Not found', 'message' => 'Image could not be found' ), $this->large->meta );
66
- }
67
-
68
- public function test_add_exception_should_add_timestamp() {
69
- $this->large->add_tiny_meta_start();
70
- $this->large->add_tiny_meta_error( new Tiny_Exception( 'Image could not be found', 'Not found' ) );
71
- $this->assertEqualWithinDelta( time(), $this->large->meta['timestamp'], 2 );
72
- }
73
-
74
- public function test_add_exception_should_not_add_if_no_request_was_made() {
75
- $this->large->add_tiny_meta_error( new Tiny_Exception( 'Image could not be found', 'Not found' ) );
76
- unset( $this->large->meta['timestamp'] );
77
- $this->assertEquals( array(), $this->large->meta );
78
- }
79
-
80
- public function test_image_has_been_compressed_if_meta_has_output() {
81
- $this->assertTrue( $this->original->has_been_compressed() );
82
- }
83
-
84
- public function test_image_has_not_been_compressed_if_meta_does_not_have_output() {
85
- $this->assertFalse( $this->large->has_been_compressed() );
86
- }
87
-
88
- public function test_image_size_filename() {
89
- $image_size = new Tiny_Image_Size( 'random_file_name.jpg' );
90
- $this->assertEquals( 'random_file_name.jpg', $image_size->filename );
91
- }
92
-
93
- public function test_image_does_not_still_exist_if_file_does_not_exist() {
94
- $image = new Tiny_Image_Size( 'file_that_does_not_exist.jpg' );
95
- $this->assertFalse( $image->still_exists() );
96
- }
97
-
98
- public function test_image_still_exists_if_file_exists() {
99
- $this->assertTrue( $this->original->still_exists() );
100
- }
101
-
102
- public function test_image_compressed_should_return_true_if_file_exists_and_size_is_same() {
103
- $this->assertTrue( $this->original->compressed() );
104
- }
105
-
106
- public function test_image_compressed_should_return_false_if_size_is_inequal_to_meta() {
107
- $this->wp->createImage( 37857, '2015/09', 'tinypng_gravatar-150x150.png' );
108
- $this->assertFalse( $this->thumbnail->compressed() );
109
- }
110
-
111
- public function test_image_modified_should_return_true_if_size_is_inequal_to_meta() {
112
- $this->wp->createImage( 37857, '2015/09', 'tinypng_gravatar-150x150.png' );
113
- $this->assertTrue( $this->thumbnail->modified() );
114
- }
115
-
116
- public function test_image_modified_should_return_false_if_compressed_correctly() {
117
- $this->assertFalse( $this->original->modified() );
118
- }
119
-
120
- public function test_uncompressed_should_return_true_if_image_exist_and_is_uncompressed() {
121
- $this->wp->createImage( 37857, '2015/09', 'tinypng_gravatar-150x150.png' );
122
- $this->assertTrue( $this->thumbnail->uncompressed() );
123
- }
124
-
125
- public function test_uncompressed_should_return_false_if_image_exist_and_is_compressed() {
126
- $this->assertFalse( $this->original->uncompressed() );
127
- }
128
-
129
- public function test_in_progress_should_return_false_if_meta_start_is_long_ago() {
130
- $image_size = new Tiny_Image_Size( 'test.jpg' );
131
- $one_hour_ago = date( 'U' ) - (60 * 60);
132
- $image_size->meta['start'] = $one_hour_ago;
133
- $this->assertFalse( $image_size->in_progress() );
134
- }
135
-
136
- public function test_in_progress_should_return_truef_meta_start_is_recent() {
137
- $image_size = new Tiny_Image_Size( 'test.jpg' );
138
- $two_minutes_ago = date( 'U' ) - (60 * 2);
139
- $image_size->meta['start'] = $two_minutes_ago;
140
- $this->assertTrue( $image_size->in_progress() );
141
- }
142
-
143
- public function test_in_progress_should_return_false_if_meta_contains_start_and_output() {
144
- $this->assertFalse( $this->original->in_progress() );
145
- }
146
-
147
- public function test_in_progress_should_return_false_if_meta_contains_timestamp_and_output() {
148
- $this->assertFalse( $this->thumbnail->in_progress() );
149
- }
150
-
151
- public function test_resized_should_return_true_if_meta_have_output_and_resized() {
152
- $this->assertTrue( $this->original->resized() );
153
- }
154
-
155
- public function test_resized_should_return_false_if_meta_have_output_and_not_resized() {
156
- $this->assertFalse( $this->thumbnail->resized() );
157
- }
158
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyImageTest.php DELETED
@@ -1,137 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Image_Test extends Tiny_TestCase {
6
- public function set_up() {
7
- parent::set_up();
8
-
9
- $this->wp->createImagesFromJSON( $this->json( 'image_filesystem_data' ) );
10
- $this->wp->setTinyMetadata( 1, $this->json( 'image_database_metadata' ) );
11
- $this->subject = new Tiny_Image( new Tiny_Settings(), 1, $this->json( '_wp_attachment_metadata' ) );
12
- }
13
-
14
- public function test_tiny_post_meta_key_may_never_change() {
15
- $this->assertEquals( '61b16225f107e6f0a836bf19d47aa0fd912f8925', sha1( Tiny_Image::META_KEY ) );
16
- }
17
-
18
- public function test_update_wp_metadata_should_not_update_with_no_resized_original() {
19
- $tiny_image = new Tiny_Image( new Tiny_Settings(), 150, $this->json( '_wp_attachment_metadata' ) );
20
- $tiny_image_metadata = $tiny_image->get_wp_metadata();
21
- $this->assertEquals( 1256, $tiny_image_metadata['width'] );
22
- $this->assertEquals( 1256, $tiny_image_metadata['height'] );
23
- }
24
-
25
- public function test_update_wp_metadata_should_update_with_resized_original() {
26
- $tiny_image = new Tiny_Image( new Tiny_Settings(), 150, $this->json( '_wp_attachment_metadata' ) );
27
- $response = array( 'output' => array( 'width' => 200, 'height' => 100 ) );
28
- $tiny_image->get_image_size()->add_tiny_meta_start();
29
- $tiny_image->get_image_size()->add_tiny_meta( $response );
30
- $tiny_image->add_wp_metadata( Tiny_Image::ORIGINAL, $tiny_image->get_image_size() );
31
- $tiny_image_metadata = $tiny_image->get_wp_metadata();
32
- $this->assertEquals( 200, $tiny_image_metadata['width'] );
33
- $this->assertEquals( 100, $tiny_image_metadata['height'] );
34
- }
35
-
36
- public function test_get_images_should_return_all_images() {
37
- $this->assertEquals( array(
38
- Tiny_Image::ORIGINAL,
39
- 'medium',
40
- 'thumbnail',
41
- 'twentyfourteen-full-width',
42
- 'failed',
43
- 'large',
44
- 'small',
45
- ), array_keys( $this->subject->get_image_sizes() ) );
46
- }
47
-
48
- public function test_filter_images_should_filter_correctly() {
49
- $this->assertEquals( array(
50
- Tiny_Image::ORIGINAL,
51
- 'medium',
52
- 'thumbnail',
53
- ), array_keys( $this->subject->filter_image_sizes( 'compressed' ) ) );
54
- }
55
-
56
- public function test_filter_images_should_filter_correctly_when_sizes_are_given() {
57
- $this->assertEquals( array(
58
- Tiny_Image::ORIGINAL
59
- ), array_keys( $this->subject->filter_image_sizes( 'compressed', array( Tiny_Image::ORIGINAL, 'invalid' ) ) )
60
- );
61
- }
62
-
63
- public function test_get_count_should_add_count_correctly() {
64
- $this->assertEquals(array(
65
- 'compressed' => 3,
66
- 'resized' => 1,
67
- ), $this->subject->get_count( array( 'compressed', 'resized' ) )
68
- );
69
- }
70
-
71
- public function test_get_count_should_add_count_correctly_when_sizes_are_given() {
72
- $this->assertEquals(array(
73
- 'compressed' => 1,
74
- 'resized' => 1,
75
- ), $this->subject->get_count( array( 'compressed', 'resized' ), array( Tiny_Image::ORIGINAL, 'invalid' ) )
76
- );
77
- }
78
-
79
- public function test_get_latest_error_should_return_message() {
80
- $this->subject->get_image_size()->add_tiny_meta_start( 'large' );
81
- $this->subject->get_image_size()->add_tiny_meta_error( new Tiny_Exception( 'Could not download output', 'OutputError' ), 'large' );
82
- $this->assertEquals( 'Could not download output', $this->subject->get_latest_error() );
83
- }
84
-
85
- public function test_get_statistics() {
86
- $this->assertEquals( array(
87
- 'initial_total_size' => 360542,
88
- 'optimized_total_size' => 328670,
89
- 'image_sizes_optimized' => 3,
90
- 'available_unoptimized_sizes' => 1,
91
- ), $this->subject->get_statistics() );
92
- }
93
-
94
- public function test_get_image_sizes_available_for_compression_when_file_modified() {
95
- $this->wp->createImage( 37857, '2015/09', 'tinypng_gravatar-150x150.png' );
96
- $statistics = $this->subject->get_statistics();
97
- $this->assertEquals( 2, $statistics['available_unoptimized_sizes'] );
98
- }
99
-
100
- public function test_get_savings() {
101
- $this->assertEquals( 8.8, $this->subject->get_savings( $this->subject->get_statistics() ) );
102
- }
103
-
104
- public function test_get_optimization_statistics() {
105
- $wpdb_wp_metadata = serialize( $this->json( '_wp_attachment_metadata' ) );
106
- $wpdb_tiny_metadata = serialize( $this->json( 'image_database_metadata' ) );
107
- $wpdb_results = array(
108
- array( 'ID' => 1, 'post_title' => 'I am the one and only', 'meta_value' => $wpdb_wp_metadata, 'tiny_meta_value' => $wpdb_wp_metadata ),
109
- array( 'ID' => 3628, 'post_title' => 'Ferrari.jpeg', 'meta_value' => '', 'tiny_meta_value' => '' ),
110
- array( 'ID' => 4350, 'post_title' => 'IMG 3092', 'meta_value' => '', 'tiny_meta_value' => '' ),
111
- );
112
- $this->assertEquals(
113
- array(
114
- 'uploaded-images' => 3,
115
- 'optimized-image-sizes' => 0,
116
- 'available-unoptimised-sizes' => 4,
117
- 'optimized-library-size' => 328670,
118
- 'unoptimized-library-size' => 328670,
119
- 'available-for-optimization' => array( array( 'ID' => 1, 'post_title' => 'I am the one and only' ) ),
120
- 'display-percentage' => 0.0
121
- ),
122
- Tiny_Image::get_optimization_statistics( new Tiny_Settings(), $wpdb_results )
123
- );
124
- }
125
-
126
- public function test_is_retina_for_retina_size() {
127
- $this->assertEquals( true, Tiny_Image::is_retina( 'small_wr2x' ) );
128
- }
129
-
130
- public function test_is_retina_for_non_retina_size() {
131
- $this->assertEquals( false, Tiny_Image::is_retina( 'small' ) );
132
- }
133
-
134
- public function test_is_retina_for_non_retina_size_with_short_name() {
135
- $this->assertEquals( false, Tiny_Image::is_retina( 'file' ) );
136
- }
137
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyPluginTest.php DELETED
@@ -1,210 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- use org\bovigo\vfs\vfsStream;
6
- use org\bovigo\vfs\content\LargeFileContent;
7
-
8
- class Tiny_Plugin_Test extends Tiny_TestCase {
9
- public function set_up() {
10
- parent::set_up();
11
- $this->subject = new Tiny_Plugin();
12
- $this->subject->init();
13
- $this->compressor = $this->getMockBuilder( 'TestCompressor' )
14
- ->setMethods( array( 'compress_file' ) )
15
- ->getMock();
16
- $this->subject->set_compressor( $this->compressor );
17
-
18
- $this->wp->addOption( 'tinypng_api_key', 'test123' );
19
- $this->wp->addOption( 'tinypng_sizes[0]', 'on' );
20
- $this->wp->addOption( 'tinypng_sizes[large]', 'on' );
21
- $this->wp->addOption( 'tinypng_sizes[post-thumbnail]', 'on' );
22
-
23
- $this->wp->addImageSize( 'post-thumbnail', array( 'width' => 825, 'height' => 510 ) );
24
- $this->wp->createImages();
25
- }
26
-
27
- public function success_compress( $file ) {
28
- if ( preg_match( '#[^-]+-([^.]+)[.](png|jpe?g)$#', basename( $file ), $match ) ) {
29
- $key = $match[1];
30
- } else {
31
- $key = null;
32
- }
33
-
34
- $input = filesize( $file );
35
- switch ( $key ) {
36
- case 'thumbnail':
37
- $output = 81;
38
- $width = '150';
39
- $height = '150';
40
- break;
41
- case 'medium':
42
- $output = 768;
43
- $width = '300';
44
- $height = '300';
45
- break;
46
- case 'large':
47
- $output = 6789;
48
- $width = '1024';
49
- $height = '1024';
50
- break;
51
- case 'post-thumbnail':
52
- $output = 1000;
53
- $width = '800';
54
- $height = '500';
55
- break;
56
- default:
57
- $output = 10000;
58
- $width = '4000';
59
- $height = '3000';
60
- }
61
- $this->vfs->getChild( vfsStream::path( $file ) )->truncate( $output );
62
- return array( 'input' => array( 'size' => $input ), 'output' => array( 'size' => $output, 'width' => $width, 'height' => $height ) );
63
- }
64
-
65
- public function test_init_should_add_filters() {
66
- $this->assertEquals(array(
67
- array( 'jpeg_quality', array( 'Tiny_Plugin', 'jpeg_quality' ) ),
68
- array( 'wp_editor_set_quality', array( 'Tiny_Plugin', 'jpeg_quality' ) ),
69
- array( 'wp_generate_attachment_metadata', array( $this->subject, 'compress_on_upload' ), 10, 2 ),
70
- ), $this->wp->getCalls( 'add_filter' ));
71
- }
72
-
73
- public function test_compress_should_respect_settings() {
74
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "image/png";' ) );
75
- $this->compressor->expects( $this->exactly( 3 ) )->method( 'compress_file' )->withConsecutive(
76
- array( $this->equalTo( 'vfs://root/wp-content/uploads/14/01/test.png' ) ),
77
- array( $this->equalTo( 'vfs://root/wp-content/uploads/14/01/test-large.png' ) ),
78
- array( $this->equalTo( 'vfs://root/wp-content/uploads/14/01/test-post-thumbnail.png' ) )
79
- )->will( $this->returnCallback( array( $this, 'success_compress' ) ) );
80
- $this->subject->compress_on_upload( $this->wp->getTestMetadata(), 1 );
81
- }
82
-
83
- public function test_compress_should_not_compress_twice() {
84
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "image/png";' ) );
85
-
86
- $testmeta = $this->wp->getTestMetadata();
87
- $tiny_image = new Tiny_Image( new Tiny_Settings(), 1, $testmeta );
88
- $tiny_image->get_image_size()->add_tiny_meta_start();
89
- $tiny_image->get_image_size()->add_tiny_meta( self::success_compress( 'vfs://root/wp-content/uploads/14/01/test.png' ) );
90
- $tiny_image->get_image_size( 'large' )->add_tiny_meta_start();
91
- $tiny_image->get_image_size( 'large' )->add_tiny_meta( self::success_compress( 'vfs://root/wp-content/uploads/14/01/test-large.png' ) );
92
- $tiny_image->update_tiny_post_meta();
93
-
94
- $this->compressor->expects( $this->once() )->method( 'compress_file' )->withConsecutive(
95
- array( $this->equalTo( 'vfs://root/wp-content/uploads/14/01/test-post-thumbnail.png' ) )
96
- )->will( $this->returnCallback( array( $this, 'success_compress' ) ) );
97
- $this->subject->compress_on_upload( $testmeta, 1 );
98
- }
99
-
100
- public function test_compress_when_file_changed() {
101
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "image/png";' ) );
102
-
103
- $testmeta = $this->wp->getTestMetadata();
104
- $tiny_image = new Tiny_Image( new Tiny_Settings(), 1, $testmeta );
105
- $tiny_image->get_image_size()->add_tiny_meta_start();
106
- $tiny_image->get_image_size()->add_tiny_meta( self::success_compress( 'vfs://root/wp-content/uploads/14/01/test.png' ) );
107
- $tiny_image->get_image_size( 'large' )->add_tiny_meta_start();
108
- $tiny_image->get_image_size( 'large' )->add_tiny_meta( self::success_compress( 'vfs://root/wp-content/uploads/14/01/test-large.png' ) );
109
- $tiny_image->get_image_size( 'post-thumbnail' )->add_tiny_meta_start();
110
- $tiny_image->get_image_size( 'post-thumbnail' )->add_tiny_meta( self::success_compress( 'vfs://root/wp-content/uploads/14/01/test-post-thumbnail.png' ) );
111
- $tiny_image->update_tiny_post_meta();
112
-
113
- $this->vfs->getChild( 'wp-content/uploads/14/01/test-large.png' )->truncate( 100000 );
114
-
115
- $this->compressor->expects( $this->once() )->method( 'compress_file' )->withConsecutive(
116
- array( $this->equalTo( 'vfs://root/wp-content/uploads/14/01/test-large.png' ) )
117
- )->will( $this->returnCallback( array( $this, 'success_compress' ) ) );
118
- $this->subject->compress_on_upload( $testmeta, 1 );
119
- }
120
-
121
- public function test_compress_should_update_metadata() {
122
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "image/png";' ) );
123
- $this->compressor->expects( $this->exactly( 3 ) )->method( 'compress_file' )->will(
124
- $this->returnCallback( array( $this, 'success_compress' ) )
125
- );
126
-
127
- $this->subject->compress_on_upload( $this->wp->getTestMetadata(), 1 );
128
-
129
- $tiny_metadata = $this->wp->getMetadata( 1, Tiny_Image::META_KEY, true );
130
- foreach ( $tiny_metadata as $key => $values ) {
131
- if ( ! empty( $values ) ) {
132
- $this->assertBetween( -1, + 1, $values['end'] - time() );
133
- unset( $tiny_metadata[ $key ]['end'] );
134
- unset( $tiny_metadata[ $key ]['start'] );
135
- }
136
- }
137
- $this->assertEquals(array(
138
- 0 => array( 'input' => array( 'size' => 12345 ), 'output' => array( 'size' => 10000, 'width' => 4000, 'height' => 3000 ) ),
139
- 'thumbnail' => array(),
140
- 'medium' => array(),
141
- 'large' => array( 'input' => array( 'size' => 10000 ), 'output' => array( 'size' => 6789, 'width' => 1024, 'height' => 1024 ) ),
142
- 'post-thumbnail' => array( 'input' => array( 'size' => 1234 ), 'output' => array( 'size' => 1000, 'width' => 800, 'height' => 500 ) ),
143
- ), $tiny_metadata);
144
- }
145
-
146
- public function test_should_handle_compress_exceptions() {
147
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "image/jpeg";' ) );
148
-
149
- $this->compressor->expects( $this->exactly( 3 ) )->method( 'compress_file' )->will(
150
- $this->throwException( new Tiny_Exception( 'Does not appear to be a PNG or JPEG file', 'BadSignature' ) )
151
- );
152
-
153
- $this->subject->compress_on_upload( $this->wp->getTestMetadata(), 1 );
154
-
155
- $tiny_metadata = $this->wp->getMetadata( 1, Tiny_Image::META_KEY, true );
156
- foreach ( $tiny_metadata as $key => $values ) {
157
- if ( ! empty( $values ) ) {
158
- $this->assertEquals( time(), $values['timestamp'], 2 );
159
- unset( $tiny_metadata[ $key ]['timestamp'] );
160
- }
161
- }
162
- $this->assertEquals(array(
163
- 0 => array( 'error' => 'BadSignature', 'message' => 'Does not appear to be a PNG or JPEG file' ),
164
- 'thumbnail' => array(),
165
- 'medium' => array(),
166
- 'large' => array( 'error' => 'BadSignature', 'message' => 'Does not appear to be a PNG or JPEG file' ),
167
- 'post-thumbnail' => array( 'error' => 'BadSignature', 'message' => 'Does not appear to be a PNG or JPEG file' ),
168
- ), $tiny_metadata);
169
- }
170
-
171
- public function test_should_return_if_no_compressor() {
172
- $this->subject->set_compressor( null );
173
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "image/png";' ) );
174
- $this->compressor->expects( $this->never() )->method( 'compress_file' );
175
-
176
- $this->subject->compress_on_upload( $this->wp->getTestMetadata(), 1 );
177
- }
178
-
179
- public function test_should_return_if_no_image() {
180
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "video/webm";' ) );
181
- $this->compressor->expects( $this->never() )->method( 'compress_file' );
182
-
183
- $this->subject->compress_on_upload( $this->wp->getTestMetadata(), 1 );
184
- }
185
-
186
- public function test_wrong_metadata_should_not_show_warnings() {
187
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "image/png";' ) );
188
- $this->compressor->expects( $this->exactly( 1 ) )->method( 'compress_file' )->will(
189
- $this->returnCallback( array( $this, 'success_compress' ) )
190
- );
191
-
192
- $testmeta = $this->wp->getTestMetadata();
193
- $testmeta['sizes'] = 0;
194
-
195
- $this->subject->compress_on_upload( $testmeta, 1 );
196
- }
197
-
198
- public function test_wrong_metadata_should_save_tiny_metadata() {
199
- $this->wp->stub( 'get_post_mime_type', create_function( '$i', 'return "image/png";' ) );
200
- $this->compressor->expects( $this->exactly( 1 ) )->method( 'compress_file' )->will(
201
- $this->returnCallback( array( $this, 'success_compress' ) )
202
- );
203
-
204
- $testmeta = $this->wp->getTestMetadata();
205
- $testmeta['sizes'] = 0;
206
-
207
- $this->subject->compress_on_upload( $testmeta, 1 );
208
- $this->assertEquals( 2, count( $this->wp->getCalls( 'update_post_meta' ) ) );
209
- }
210
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinySettingsTest.php DELETED
@@ -1,281 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Settings_Test extends Tiny_TestCase {
6
- public function set_up() {
7
- parent::set_up();
8
- $this->subject = new Tiny_Settings();
9
- $this->subject->admin_init();
10
- }
11
-
12
- public function test_admin_init_should_register_keys() {
13
- $this->assertEquals(array(
14
- array( 'media', 'tinypng_api_key' ),
15
- array( 'media', 'tinypng_api_key_pending' ),
16
- array( 'media', 'tinypng_sizes' ),
17
- array( 'media', 'tinypng_resize_original' ),
18
- array( 'media', 'tinypng_preserve_data' ),
19
- ), $this->wp->getCalls( 'register_setting' ));
20
- }
21
-
22
- public function test_admin_init_should_add_settings_section() {
23
- $this->assertEquals( array(
24
- array(
25
- 'tinypng_settings',
26
- 'JPEG and PNG optimization',
27
- array( $this->subject, 'render_section' ),
28
- 'media',
29
- ),
30
- array(
31
- 'section_end',
32
- '',
33
- array( $this->subject, 'render_section_end' ),
34
- 'media',
35
- ),
36
- ), $this->wp->getCalls( 'add_settings_section' ) );
37
- }
38
-
39
- public function test_admin_init_should_add_settings_field() {
40
- $this->assertEquals( array(
41
- array(
42
- 'tinypng_api_key',
43
- 'TinyPNG account',
44
- array( $this->subject, 'render_pending_status' ),
45
- 'media',
46
- 'tinypng_settings',
47
- ),
48
- array(
49
- 'tinypng_sizes',
50
- 'File compression',
51
- array( $this->subject, 'render_sizes' ),
52
- 'media',
53
- 'tinypng_settings',
54
- ),
55
- array(
56
- 'tinypng_resize_original',
57
- 'Original image',
58
- array( $this->subject, 'render_resize' ),
59
- 'media',
60
- 'tinypng_settings',
61
- ),
62
- ), $this->wp->getCalls( 'add_settings_field' ) );
63
- }
64
-
65
- public function test_should_retrieve_sizes_with_settings() {
66
- $this->wp->addOption( 'tinypng_sizes[0]', 'on' );
67
- $this->wp->addOption( 'tinypng_sizes[medium]', 'on' );
68
- $this->wp->addOption( 'tinypng_sizes[post-thumbnail]', 'on' );
69
- $this->wp->addImageSize( 'post-thumbnail', array( 'width' => 825, 'height' => 510 ) );
70
-
71
- $this->subject->get_sizes();
72
- $this->assertEquals(array(
73
- 0 => array( 'width' => null, 'height' => null, 'tinify' => true ),
74
- 'thumbnail' => array( 'width' => 150, 'height' => 150, 'tinify' => false ),
75
- 'medium' => array( 'width' => 300, 'height' => 300, 'tinify' => true ),
76
- 'medium_large' => array( 'width' => 768, 'height' => 0, 'tinify' => false ),
77
- 'large' => array( 'width' => 1024, 'height' => 1024, 'tinify' => false ),
78
- 'post-thumbnail' => array( 'width' => 825, 'height' => 510, 'tinify' => true ),
79
- ), $this->subject->get_sizes());
80
- }
81
-
82
- public function test_should_not_retrieve_sizes_with_zero_width_and_height_values() {
83
- $this->wp->addOption( 'tinypng_sizes[0]', 'on' );
84
- $this->wp->addOption( 'tinypng_sizes[medium]', 'on' );
85
- $this->wp->addOption( 'tinypng_sizes[post-thumbnail]', 'on' );
86
- $this->wp->addOption( 'tinypng_sizes[zero-width]', 'off' );
87
- $this->wp->addOption( 'tinypng_sizes[zero-height]', 'off' );
88
- $this->wp->addOption( 'tinypng_sizes[zero-width-height]', 'off' );
89
-
90
- $this->wp->addImageSize( 'zero-width', array( 'width' => 0, 'height' => 510 ) );
91
- $this->wp->addImageSize( 'zero-height', array( 'width' => 825, 'height' => 0 ) );
92
- $this->wp->addImageSize( 'zero-width-height', array( 'width' => 0, 'height' => 0 ) );
93
-
94
- $this->subject->get_sizes();
95
- $this->assertEquals(array(
96
- 0 => array( 'width' => null, 'height' => null, 'tinify' => true ),
97
- 'thumbnail' => array( 'width' => 150, 'height' => 150, 'tinify' => false ),
98
- 'medium' => array( 'width' => 300, 'height' => 300, 'tinify' => true ),
99
- 'medium_large' => array( 'width' => 768, 'height' => 0, 'tinify' => false ),
100
- 'large' => array( 'width' => 1024, 'height' => 1024, 'tinify' => false ),
101
- 'zero-width' => array( 'width' => 0, 'height' => 510, 'tinify' => false ),
102
- 'zero-height' => array( 'width' => 825, 'height' => 0, 'tinify' => false )
103
- ), $this->subject->get_sizes());
104
- }
105
-
106
- public function test_should_skip_dummy_size() {
107
- $this->wp->addOption( 'tinypng_sizes[tiny_dummy]', 'on' );
108
-
109
- $this->subject->get_sizes();
110
- $this->assertEquals(array(
111
- 0 => array( 'width' => null, 'height' => null, 'tinify' => false ),
112
- 'thumbnail' => array( 'width' => 150, 'height' => 150, 'tinify' => false ),
113
- 'medium' => array( 'width' => 300, 'height' => 300, 'tinify' => false ),
114
- 'medium_large' => array( 'width' => 768, 'height' => 0, 'tinify' => false ),
115
- 'large' => array( 'width' => 1024, 'height' => 1024, 'tinify' => false ),
116
- ), $this->subject->get_sizes());
117
- }
118
-
119
- public function test_should_set_all_sizes_on_without_configuration() {
120
- $this->subject->get_sizes();
121
- $this->assertEquals(array(
122
- 0 => array( 'width' => null, 'height' => null, 'tinify' => true ),
123
- 'thumbnail' => array( 'width' => 150, 'height' => 150, 'tinify' => true ),
124
- 'medium' => array( 'width' => 300, 'height' => 300, 'tinify' => true ),
125
- 'medium_large' => array( 'width' => 768, 'height' => 0, 'tinify' => true ),
126
- 'large' => array( 'width' => 1024, 'height' => 1024, 'tinify' => true ),
127
- ), $this->subject->get_sizes());
128
- }
129
-
130
- public function test_should_show_additional_size() {
131
- $this->wp->addImageSize( 'additional_size_1', array( 'width' => 666, 'height' => 333 ) );
132
- $this->subject->get_sizes();
133
- $sizes = $this->subject->get_sizes();
134
- $this->assertEquals(
135
- array( 'width' => 666, 'height' => 333, 'tinify' => true ),
136
- $sizes['additional_size_1']
137
- );
138
- }
139
-
140
- public function test_should_show_additional_size_without_height() {
141
- $this->wp->addImageSize( 'additional_size_no_height', array( 'width' => 777 ) );
142
- $this->subject->get_sizes();
143
- $sizes = $this->subject->get_sizes();
144
- $this->assertEquals(
145
- array( 'width' => 777, 'height' => 0, 'tinify' => true ),
146
- $sizes['additional_size_no_height']
147
- );
148
- }
149
-
150
- public function test_should_show_additional_size_without_width() {
151
- $this->wp->addImageSize( 'additional_size_no_width', array( 'height' => 888 ) );
152
- $this->subject->get_sizes();
153
- $sizes = $this->subject->get_sizes();
154
- $this->assertEquals(
155
- array( 'width' => 0, 'height' => 888, 'tinify' => true ),
156
- $sizes['additional_size_no_width']
157
- );
158
- }
159
-
160
- public function test_get_resize_enabled_should_return_true_if_enabled() {
161
- $this->wp->addOption( 'tinypng_resize_original', array( 'enabled' => 'on' ) );
162
- $this->assertEquals( true, $this->subject->get_resize_enabled() );
163
- }
164
-
165
- public function test_get_resize_enabled_should_return_false_without_configuration() {
166
- $this->wp->addOption( 'tinypng_resize_original', array() );
167
- $this->assertEquals( false, $this->subject->get_resize_enabled() );
168
- }
169
-
170
- public function test_get_resize_enabled_should_return_false_if_original_is_not_compressed() {
171
- $this->wp->addOption( 'tinypng_sizes[0]', 'off' );
172
- $this->wp->addOption( 'tinypng_resize_original', array( 'enabled' => 'on' ) );
173
- $this->assertEquals( false, $this->subject->get_resize_enabled() );
174
- }
175
-
176
- public function test_should_return_resize_options_with_width_and_height() {
177
- $this->wp->addOption(
178
- 'tinypng_resize_original',
179
- array( 'enabled' => 'on', 'width' => '800', 'height' => '600' )
180
- );
181
-
182
- $this->assertEquals(
183
- array( 'method' => 'fit', 'width' => 800, 'height' => 600 ),
184
- $this->subject->get_resize_options( Tiny_Image::ORIGINAL )
185
- );
186
- }
187
-
188
- public function test_should_return_resize_options_without_width() {
189
- $this->wp->addOption(
190
- 'tinypng_resize_original',
191
- array( 'enabled' => 'on', 'width' => '', 'height' => '600' )
192
- );
193
-
194
- $this->assertEquals(
195
- array( 'method' => 'scale', 'height' => 600 ),
196
- $this->subject->get_resize_options( Tiny_Image::ORIGINAL )
197
- );
198
- }
199
-
200
- public function test_should_return_resize_options_without_height() {
201
- $this->wp->addOption(
202
- 'tinypng_resize_original',
203
- array( 'enabled' => 'on', 'width' => '800', 'height' => '' )
204
- );
205
-
206
- $this->assertEquals(
207
- array( 'method' => 'scale', 'width' => 800 ),
208
- $this->subject->get_resize_options( Tiny_Image::ORIGINAL )
209
- );
210
- }
211
-
212
- public function test_should_return_resize_options_with_invaled_width() {
213
- $this->wp->addOption(
214
- 'tinypng_resize_original',
215
- array( 'enabled' => 'on', 'width' => '-1', 'height' => '600' )
216
- );
217
-
218
- $this->assertEquals(
219
- array( 'method' => 'scale', 'height' => 600 ),
220
- $this->subject->get_resize_options( Tiny_Image::ORIGINAL )
221
- );
222
- }
223
-
224
- public function test_should_return_resize_options_with_invaled_height() {
225
- $this->wp->addOption(
226
- 'tinypng_resize_original',
227
- array( 'enabled' => 'on', 'width' => '800', 'height' => '-1' )
228
- );
229
-
230
- $this->assertEquals(
231
- array( 'method' => 'scale', 'width' => 800 ),
232
- $this->subject->get_resize_options( Tiny_Image::ORIGINAL )
233
- );
234
- }
235
-
236
- public function test_should_not_return_resize_options_without_with_and_height() {
237
- $this->wp->addOption(
238
- 'tinypng_resize_original',
239
- array( 'enabled' => 'on', 'width' => '', 'height' => '' )
240
- );
241
-
242
- $this->assertEquals( false, $this->subject->get_resize_options( Tiny_Image::ORIGINAL ) );
243
- }
244
-
245
- public function test_should_not_return_resize_options_when_not_enabled() {
246
- $this->wp->addOption(
247
- 'tinypng_resize_original',
248
- array( 'width' => '800', 'height' => '600' )
249
- );
250
-
251
- $this->assertEquals( false, $this->subject->get_resize_options( Tiny_Image::ORIGINAL ) );
252
- }
253
-
254
- public function test_should_return_include_metadata_enabled() {
255
- $this->wp->addOption( 'tinypng_preserve_data', array( 'copyright' => 'on' ) );
256
- $this->assertEquals( true, $this->subject->get_preserve_enabled( 'copyright' ) );
257
- }
258
-
259
- public function test_should_return_include_metadata_not_enabled_without_configuration() {
260
- $this->wp->addOption( 'tinypng_include_metadata', array() );
261
- $this->assertEquals( false, $this->subject->get_preserve_enabled( 'copyright' ) );
262
- }
263
-
264
- public function test_should_return_preserve_options_when_enabled() {
265
- $this->wp->addOption( 'tinypng_preserve_data', array( 'copyright' => 'on' ) );
266
-
267
- $this->assertEquals(
268
- array( '0' => 'copyright' ),
269
- $this->subject->get_preserve_options( Tiny_Image::ORIGINAL )
270
- );
271
- }
272
-
273
- public function test_should_not_return_preserve_options_when_disabled() {
274
- $this->wp->addOption( 'tinypng_include_metadata', array() );
275
-
276
- $this->assertEquals(
277
- array(),
278
- $this->subject->get_preserve_options( Tiny_Image::ORIGINAL )
279
- );
280
- }
281
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyTestCase.php DELETED
@@ -1,93 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/../helpers/mock-http-stream-wrapper.php';
4
- require_once dirname( __FILE__ ) . '/../helpers/mock-tinify-client.php';
5
- require_once dirname( __FILE__ ) . '/../helpers/wordpress.php';
6
- require_once dirname( __FILE__ ) . '/../../src/config/tiny-config.php';
7
- require_once 'vendor/autoload.php';
8
-
9
- use org\bovigo\vfs\vfsStream;
10
-
11
- function plugin_autoloader( $class ) {
12
- $file = dirname( __FILE__ ) . '/../../src/class-' .
13
- str_replace( '_', '-', strtolower( $class ) ) . '.php';
14
-
15
- if ( file_exists( $file ) ) {
16
- include $file;
17
- } else {
18
- spl_autoload( $class );
19
- }
20
- }
21
-
22
- spl_autoload_register( 'plugin_autoloader' );
23
-
24
- class Tiny_PHP {
25
- public static $fopen_available = true;
26
- public static $client_supported = true;
27
-
28
- public static function fopen_available() {
29
- return self::$fopen_available;
30
- }
31
-
32
- public static function client_supported() {
33
- return self::$client_supported;
34
- }
35
- }
36
-
37
- abstract class Tiny_TestCase extends PHPUnit_Framework_TestCase {
38
- protected $wp;
39
- protected $vfs;
40
-
41
- // @codingStandardsIgnoreStart
42
- public static function setUpBeforeClass() {
43
- static::set_up_before_class();
44
- }
45
-
46
- public static function tearDownAfterClass() {
47
- static::tear_down_after_class();
48
- }
49
-
50
- protected function setUp() {
51
- $this->set_up();
52
- }
53
-
54
- protected function tearDown() {
55
- $this->tear_down();
56
- }
57
-
58
- protected function assertBetween($lower_bound, $upper_bound, $actual, $message = '') {
59
- $this->assertGreaterThanOrEqual( $lower_bound, $actual, $message );
60
- $this->assertLessThanOrEqual( $upper_bound, $actual, $message );
61
- }
62
-
63
- protected function assertEqualWithinDelta($expected, $actual, $delta, $message = '') {
64
- $this->assertGreaterThanOrEqual( $expected - $delta, $actual, $message );
65
- $this->assertLessThanOrEqual( $expected + $delta, $actual, $message );
66
- }
67
- // @codingStandardsIgnoreEnd
68
-
69
- protected function json( $file_name ) {
70
- return json_decode(
71
- file_get_contents(
72
- dirname( __FILE__ ) . '/../fixtures/json/' . $file_name . '.json'
73
- ),
74
- true
75
- );
76
- }
77
-
78
- public static function set_up_before_class() {
79
- }
80
-
81
- public static function tear_down_after_class() {
82
- Tiny_PHP::$client_supported = true;
83
- Tiny_PHP::$fopen_available = true;
84
- }
85
-
86
- protected function set_up() {
87
- $this->vfs = vfsStream::setup();
88
- $this->wp = new WordPressStubs( $this->vfs );
89
- }
90
-
91
- protected function tear_down() {
92
- }
93
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/unit/TinyWpBaseTest.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
- require_once dirname( __FILE__ ) . '/TinyTestCase.php';
4
-
5
- class Tiny_Test_Base extends Tiny_WP_Base {
6
- }
7
-
8
- class Tiny_WP_Base_Test extends Tiny_TestCase {
9
- public function set_up() {
10
- parent::set_up();
11
- $this->subject = new Tiny_Test_Base();
12
- }
13
-
14
- public function test_should_add_init_hooks() {
15
- $this->assertEquals(array(
16
- array( 'init', array( $this->subject, 'init' ) ),
17
- array( 'admin_init', array( $this->subject, 'admin_init' ) ),
18
- array( 'admin_menu', array( $this->subject, 'admin_menu' ) ),
19
- ),
20
- $this->wp->getCalls( 'add_action' )
21
- );
22
- }
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/wp-includes/version.php DELETED
@@ -1,7 +0,0 @@
1
- <?php
2
-
3
- $wp_version = '4.6-alpha-37595';
4
- $wp_db_version = 36686;
5
- $tinymce_version = '4310-20160418';
6
- $required_php_version = '5.2.4';
7
- $required_mysql_version = '5.0';
 
 
 
 
 
 
 
tiny-compress-images.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Compress JPEG & PNG images
4
  * Description: Speed up your website. Optimize your JPEG and PNG images automatically with TinyPNG.
5
- * Version: 2.2.1
6
  * Author: TinyPNG
7
  * Author URI: https://tinypng.com
8
  * Text Domain: tiny-compress-images
2
  /**
3
  * Plugin Name: Compress JPEG & PNG images
4
  * Description: Speed up your website. Optimize your JPEG and PNG images automatically with TinyPNG.
5
+ * Version: 2.2.2
6
  * Author: TinyPNG
7
  * Author URI: https://tinypng.com
8
  * Text Domain: tiny-compress-images