Fix max preview, some resizing and caching issues and force preview providers to resize their previews properly
* introduces a method in OC_Image which doesn't stretch images when trying to make them fit in a box * adds the method to all key providers so that they can do their job, as expected by the Preview class * improves the caching mechanism of Preview in order to reduce I/O and to avoid filling the available disk space * fixes some long standing issues * **contains mostly tests**remotes/origin/poc-doctrine-migrations
parent
16708ae187
commit
71d65cb713
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 169 KiB |
@ -0,0 +1,175 @@ |
||||
%!PS-Adobe-3.0 EPSF-3.0 |
||||
%%Creator: cairo 1.14.1 (http://cairographics.org) |
||||
%%CreationDate: Fri May 15 16:27:38 2015 |
||||
%%Pages: 1 |
||||
%%DocumentData: Clean7Bit |
||||
%%LanguageLevel: 2 |
||||
%%BoundingBox: 0 -1 2400 1706 |
||||
%%EndComments |
||||
%%BeginProlog |
||||
save |
||||
50 dict begin |
||||
/q { gsave } bind def |
||||
/Q { grestore } bind def |
||||
/cm { 6 array astore concat } bind def |
||||
/w { setlinewidth } bind def |
||||
/J { setlinecap } bind def |
||||
/j { setlinejoin } bind def |
||||
/M { setmiterlimit } bind def |
||||
/d { setdash } bind def |
||||
/m { moveto } bind def |
||||
/l { lineto } bind def |
||||
/c { curveto } bind def |
||||
/h { closepath } bind def |
||||
/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto |
||||
0 exch rlineto 0 rlineto closepath } bind def |
||||
/S { stroke } bind def |
||||
/f { fill } bind def |
||||
/f* { eofill } bind def |
||||
/n { newpath } bind def |
||||
/W { clip } bind def |
||||
/W* { eoclip } bind def |
||||
/BT { } bind def |
||||
/ET { } bind def |
||||
/pdfmark where { pop globaldict /?pdfmark /exec load put } |
||||
{ globaldict begin /?pdfmark /pop load def /pdfmark |
||||
/cleartomark load def end } ifelse |
||||
/BDC { mark 3 1 roll /BDC pdfmark } bind def |
||||
/EMC { mark /EMC pdfmark } bind def |
||||
/cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def |
||||
/Tj { show currentpoint cairo_store_point } bind def |
||||
/TJ { |
||||
{ |
||||
dup |
||||
type /stringtype eq |
||||
{ show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse |
||||
} forall |
||||
currentpoint cairo_store_point |
||||
} bind def |
||||
/cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore |
||||
cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def |
||||
/Tf { pop /cairo_font exch def /cairo_font_matrix where |
||||
{ pop cairo_selectfont } if } bind def |
||||
/Td { matrix translate cairo_font_matrix matrix concatmatrix dup |
||||
/cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point |
||||
/cairo_font where { pop cairo_selectfont } if } bind def |
||||
/Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def |
||||
cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def |
||||
/g { setgray } bind def |
||||
/rg { setrgbcolor } bind def |
||||
/d1 { setcachedevice } bind def |
||||
%%EndProlog |
||||
%%BeginSetup |
||||
%%EndSetup |
||||
%%Page: 1 1 |
||||
%%BeginPageSetup |
||||
%%PageBoundingBox: 0 -1 2400 1706 |
||||
%%EndPageSetup |
||||
q 0 -1 2400 1707 rectclip q |
||||
0.113725 0.176471 0.266667 rg |
||||
0 1705.263 2400 -1705.262 re f |
||||
1 g |
||||
1348.539 1275.525 m 1269.973 1275.525 1206.5 1212.052 1206.5 1133.486 c |
||||
1206.5 1101.099 1217.285 1071.294 1235.465 1047.427 c 1274.906 1093.076 |
||||
1333.117 1122.064 1398.113 1122.064 c 1429.914 1122.064 1460.066 1114.986 |
||||
1487.238 1102.572 c 1489.438 1112.517 1490.578 1122.865 1490.578 1133.486 |
||||
c 1490.578 1212.052 1427.105 1275.525 1348.539 1275.525 c h |
||||
1163.055 1209.794 m 1122.137 1209.794 1089.246 1176.626 1089.246 1135.712 |
||||
c 1089.246 1122.466 1092.664 1109.951 1098.719 1099.228 c 1123.406 1113.158 |
||||
1151.949 1121.232 1182.27 1121.232 c 1185.195 1121.232 1188.016 1121.111 |
||||
1190.902 1120.951 c 1190.578 1125.099 1190.348 1129.255 1190.348 1133.486 |
||||
c 1190.348 1156.275 1195.297 1177.955 1203.992 1197.541 c 1192.285 1205.396 |
||||
1178.254 1209.794 1163.055 1209.794 c h |
||||
1513.418 1158.83 m 1510.395 1158.83 1507.48 1158.458 1504.504 1158.271 |
||||
c 1505.793 1150.154 1506.734 1141.958 1506.734 1133.486 c 1506.734 1120.294 |
||||
1505.055 1107.568 1501.996 1095.33 c 1537.844 1075.494 1567.609 1045.81 |
||||
1587.223 1009.826 c 1607.563 1020.416 1630.258 1027.15 1654.344 1028.767 |
||||
c 1648.137 1101.56 1587.828 1158.83 1513.418 1158.83 c h |
||||
1398.113 1105.912 m 1288.176 1105.912 1199.258 1017.001 1199.258 907.056 |
||||
c 1199.258 797.123 1288.172 708.201 1398.113 708.201 c 1508.055 708.201 |
||||
1596.969 797.126 1596.969 907.056 c 1596.969 1017.001 1508.051 1105.912 |
||||
1398.113 1105.912 c h |
||||
1182.27 1105.076 m 1096.98 1105.076 1027.977 1036.072 1027.977 950.783 |
||||
c 1027.977 900.576 1051.898 856.126 1088.969 827.962 c 1104.598 858.103 |
||||
1135.988 878.65 1172.242 878.65 c 1176.625 878.65 1180.832 878.119 1185.055 |
||||
877.537 c 1183.73 887.181 1183.105 897.048 1183.105 907.056 c 1183.105 |
||||
954.908 1198.68 999.154 1225.16 1034.892 c 1209.309 1054.728 1197.965 1078.556 |
||||
1193.133 1104.521 c 1189.547 1104.767 1185.918 1105.076 1182.27 1105.076 |
||||
c h |
||||
1665.762 1013.169 m 1639.863 1013.169 1615.602 1006.556 1594.184 995.345 |
||||
c 1606.348 968.404 1613.121 938.513 1613.121 907.056 c 1613.121 848.158 |
||||
1589.441 794.677 1551.016 755.826 c 1579.246 724.486 1620.203 704.861 1665.762 |
||||
704.861 c 1751.051 704.861 1820.055 773.865 1820.055 859.154 c 1820.055 |
||||
944.443 1751.051 1013.169 1665.762 1013.169 c h |
||||
1012.938 992.837 m 934.367 992.837 870.617 929.646 870.617 851.076 c 870.617 |
||||
772.509 934.367 708.759 1012.938 708.759 c 1042.84 708.759 1070.543 718.076 |
||||
1093.426 733.826 c 1083.969 748.517 1078.387 766.083 1078.387 784.791 c |
||||
1078.387 794.501 1079.82 803.83 1082.563 812.642 c 1039.723 843.603 1011.824 |
||||
893.986 1011.824 950.783 c 1011.824 965.212 1013.723 979.169 1017.113 992.56 |
||||
c 1015.707 992.599 1014.355 992.837 1012.938 992.837 c h |
||||
1848.184 870.849 m 1843.992 870.849 1839.938 870.373 1835.93 869.736 c |
||||
1836.152 866.193 1836.207 862.751 1836.207 859.154 c 1836.207 813.853 1818.332 |
||||
772.736 1789.418 742.181 c 1803.645 725.638 1824.539 715.166 1848.184 715.166 |
||||
c 1891.254 715.166 1926.168 749.798 1926.168 792.869 c 1926.168 835.939 |
||||
1891.254 870.849 1848.184 870.849 c h |
||||
1172.242 862.498 m 1129.176 862.498 1094.539 827.861 1094.539 784.791 c |
||||
1094.539 741.724 1129.176 706.81 1172.242 706.81 c 1205.258 706.81 1233.277 |
||||
727.408 1244.656 756.384 c 1216.891 784.662 1196.938 820.74 1188.117 860.826 |
||||
c 1182.961 861.892 1177.723 862.498 1172.242 862.498 c h |
||||
2026.43 797.044 m 2026.43 643.029 l 1944.828 643.029 l 1891.484 643.029 |
||||
1848.184 599.455 1848.184 546.111 c 1848.184 492.775 1891.484 449.466 1944.828 |
||||
449.466 c 1976.578 449.466 l 1992.227 449.466 2007.852 457.068 2020.305 |
||||
468.685 c 2032.754 480.302 2042.254 496.392 2042.582 514.361 c 2043.145 |
||||
545.197 2042.582 634.955 2042.582 634.955 c 2042.582 797.044 l h |
||||
1280.305 727.419 m 1280.305 514.361 l 1280.305 478.552 1309.668 449.466 |
||||
1345.477 449.466 c 1345.477 465.623 l 1318.383 465.623 1296.457 487.263 |
||||
1296.457 514.361 c 1296.457 717.392 l 1290.836 720.416 1285.617 723.923 |
||||
1280.305 727.419 c h |
||||
1118.77 707.646 m 1090.16 680.345 1072.258 641.908 1072.258 599.306 c 1072.258 |
||||
516.642 1139.438 449.466 1222.098 449.466 c 1222.098 465.623 l 1148.152 |
||||
465.623 1088.414 525.357 1088.414 599.306 c 1088.414 639.076 1105.773 674.822 |
||||
1133.254 699.291 c 1128.117 701.654 1123.359 704.427 1118.77 707.646 c |
||||
h |
||||
928.547 643.587 m 875.203 643.587 831.906 600.291 831.906 546.947 c 831.906 |
||||
457.544 l 848.059 457.544 l 848.059 546.947 l 848.059 591.572 883.922 627.712 |
||||
928.547 627.712 c 973.184 627.712 1009.316 591.572 1009.316 546.947 c 1009.316 |
||||
457.544 l 1025.469 457.544 l 1025.469 546.947 l 1025.469 600.291 981.898 |
||||
643.587 928.547 643.587 c h |
||||
1470.805 643.029 m 1417.457 643.029 1374.164 599.455 1374.164 546.111 c |
||||
1374.164 492.763 1417.457 449.189 1470.805 449.189 c 1524.152 449.189 1567.727 |
||||
492.763 1567.727 546.111 c 1567.727 599.455 1524.152 643.029 1470.805 643.029 |
||||
c h |
||||
392.418 642.751 m 339.078 642.751 295.496 599.451 295.496 546.111 c 295.496 |
||||
492.767 339.078 449.466 392.418 449.466 c 445.762 449.466 489.063 492.767 |
||||
489.063 546.111 c 489.063 599.451 445.762 642.751 392.418 642.751 c h |
||||
537.523 635.513 m 537.523 514.361 l 537.523 478.552 566.613 449.466 602.414 |
||||
449.466 c 626.816 449.466 648.344 462.958 659.508 482.888 c 670.59 462.958 |
||||
691.93 449.466 716.324 449.466 c 752.133 449.466 781.496 478.552 781.496 |
||||
514.361 c 781.496 635.513 l 765.344 635.513 l 765.344 514.361 l 765.344 |
||||
487.267 743.418 465.623 716.324 465.623 c 689.23 465.623 667.586 487.267 |
||||
667.586 514.361 c 667.586 635.513 l 651.434 635.513 l 651.434 514.361 l |
||||
651.434 487.267 629.52 465.623 602.414 465.623 c 575.328 465.623 553.676 |
||||
487.267 553.676 514.361 c 553.676 635.513 l h |
||||
1610.059 635.513 m 1610.059 546.111 l 1610.059 492.775 1653.359 449.466 |
||||
1706.703 449.466 c 1760.047 449.466 1803.621 492.775 1803.621 546.111 c |
||||
1803.621 635.513 l 1787.469 635.513 l 1787.469 546.111 l 1787.469 501.494 |
||||
1751.328 465.623 1706.703 465.623 c 1662.074 465.623 1626.215 501.49 1626.215 |
||||
546.111 c 1626.215 635.513 l h |
||||
1470.805 626.876 m 1515.438 626.876 1551.574 590.74 1551.574 546.111 c |
||||
1551.574 501.478 1515.438 465.341 1470.805 465.341 c 1426.176 465.341 1390.316 |
||||
501.478 1390.316 546.111 c 1390.316 590.74 1426.176 626.876 1470.805 626.876 |
||||
c h |
||||
1944.828 626.876 m 2026.43 626.876 l 2026.492 616.205 2026.938 542.685 |
||||
2026.43 514.638 c 2026.203 502.158 2019.355 489.634 2009.441 480.38 c 1999.527 |
||||
471.13 1986.695 465.623 1976.578 465.623 c 1944.828 465.623 l 1900.199 |
||||
465.623 1864.34 501.49 1864.34 546.111 c 1864.34 590.74 1900.199 626.876 |
||||
1944.828 626.876 c h |
||||
392.418 626.599 m 437.047 626.599 472.906 590.736 472.906 546.111 c 472.906 |
||||
501.482 437.047 465.623 392.418 465.623 c 347.793 465.623 311.652 501.482 |
||||
311.652 546.111 c 311.652 590.736 347.793 626.599 392.418 626.599 c h |
||||
392.418 626.599 m f |
||||
Q Q |
||||
showpage |
||||
%%Trailer |
||||
end restore |
||||
%%EOF |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
@ -0,0 +1,36 @@ |
||||
<?php |
||||
/** |
||||
* @author Olivier Paroz <owncloud@interfasys.ch> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Preview; |
||||
|
||||
class Bitmap extends Provider { |
||||
|
||||
public function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$fileName = 'testimage.eps'; |
||||
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); |
||||
$this->width = 2400; |
||||
$this->height = 1707; |
||||
$this->provider = new \OC\Preview\Postscript; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@ |
||||
<?php |
||||
/** |
||||
* @author Olivier Paroz <owncloud@interfasys.ch> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Preview; |
||||
|
||||
class Image extends Provider { |
||||
|
||||
public function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$fileName = 'testimage.jpg'; |
||||
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); |
||||
$this->width = 1680; |
||||
$this->height = 1050; |
||||
$this->provider = new \OC\Preview\JPEG(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,46 @@ |
||||
<?php |
||||
/** |
||||
* @author Olivier Paroz <owncloud@interfasys.ch> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Preview; |
||||
|
||||
class Movie extends Provider { |
||||
|
||||
public function setUp() { |
||||
$avconvBinary = \OC_Helper::findBinaryPath('avconv'); |
||||
$ffmpegBinary = ($avconvBinary) ? null : \OC_Helper::findBinaryPath('ffmpeg'); |
||||
|
||||
if ($avconvBinary || $ffmpegBinary) { |
||||
parent::setUp(); |
||||
|
||||
\OC\Preview\Movie::$avconvBinary = $avconvBinary; |
||||
\OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; |
||||
|
||||
$fileName = 'testimage.mp4'; |
||||
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); |
||||
$this->width = 560; |
||||
$this->height = 320; |
||||
$this->provider = new \OC\Preview\Movie; |
||||
} else { |
||||
$this->markTestSkipped('No Movie provider present'); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@ |
||||
<?php |
||||
/** |
||||
* @author Olivier Paroz <owncloud@interfasys.ch> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Preview; |
||||
|
||||
class MP3 extends Provider { |
||||
|
||||
public function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$fileName = 'testimage.mp3'; |
||||
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); |
||||
$this->width = 200; |
||||
$this->height = 200; |
||||
$this->provider = new \OC\Preview\MP3; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
<?php |
||||
/** |
||||
* @author Olivier Paroz <owncloud@interfasys.ch> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Preview; |
||||
|
||||
class Office extends Provider { |
||||
|
||||
public function setUp() { |
||||
$libreofficeBinary = \OC_Helper::findBinaryPath('libreoffice'); |
||||
$openofficeBinary = ($libreofficeBinary) ? null : \OC_Helper::findBinaryPath('openoffice'); |
||||
|
||||
if ($libreofficeBinary || $openofficeBinary) { |
||||
parent::setUp(); |
||||
|
||||
$fileName = 'testimage.odt'; |
||||
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); |
||||
$this->width = 595; |
||||
$this->height = 842; |
||||
$this->provider = new \OC\Preview\OpenDocument; |
||||
} else { |
||||
$this->markTestSkipped('No Office provider present'); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,187 @@ |
||||
<?php |
||||
/** |
||||
* @author Olivier Paroz <owncloud@interfasys.ch> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Preview; |
||||
|
||||
abstract class Provider extends \Test\TestCase { |
||||
|
||||
/** @var string */ |
||||
protected $imgPath; |
||||
/** @var int */ |
||||
protected $width; |
||||
/** @var int */ |
||||
protected $height; |
||||
/** @var \OC\Preview\Provider */ |
||||
protected $provider; |
||||
/** @var int */ |
||||
protected $maxWidth = 1024; |
||||
/** @var int */ |
||||
protected $maxHeight = 1024; |
||||
/** @var bool */ |
||||
protected $scalingUp = false; |
||||
/** @var int */ |
||||
protected $userId; |
||||
/** @var \OC\Files\View */ |
||||
protected $rootView; |
||||
/** @var \OC\Files\Storage\Storage */ |
||||
protected $storage; |
||||
|
||||
protected function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$userManager = \OC::$server->getUserManager(); |
||||
$userManager->clearBackends(); |
||||
$backend = new \OC_User_Dummy(); |
||||
$userManager->registerBackend($backend); |
||||
|
||||
$userId = $this->getUniqueID(); |
||||
$backend->createUser($userId, $userId); |
||||
$this->loginAsUser($userId); |
||||
|
||||
$this->storage = new \OC\Files\Storage\Temporary([]); |
||||
\OC\Files\Filesystem::mount($this->storage, [], '/' . $userId . '/'); |
||||
|
||||
$this->rootView = new \OC\Files\View(''); |
||||
$this->rootView->mkdir('/' . $userId); |
||||
$this->rootView->mkdir('/' . $userId . '/files'); |
||||
|
||||
$this->userId = $userId; |
||||
} |
||||
|
||||
protected function tearDown() { |
||||
$this->logout(); |
||||
|
||||
parent::tearDown(); |
||||
} |
||||
|
||||
public static function dimensionsDataProvider() { |
||||
return [ |
||||
[-rand(5, 100), -rand(5, 100)], |
||||
[rand(5, 100), rand(5, 100)], |
||||
[-rand(5, 100), rand(5, 100)], |
||||
[rand(5, 100), -rand(5, 100)], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* Launches all the tests we have |
||||
* |
||||
* @dataProvider dimensionsDataProvider |
||||
* |
||||
* @param int $widthAdjustment |
||||
* @param int $heightAdjustment |
||||
*/ |
||||
public function testGetThumbnail($widthAdjustment, $heightAdjustment) { |
||||
$ratio = round($this->width / $this->height, 2); |
||||
$this->maxWidth = $this->width - $widthAdjustment; |
||||
$this->maxHeight = $this->height - $heightAdjustment; |
||||
|
||||
// Testing code |
||||
/*print_r("w $this->width "); |
||||
print_r("h $this->height "); |
||||
print_r("r $ratio ");*/ |
||||
|
||||
$preview = $this->getPreview($this->provider); |
||||
// The TXT provider uses the max dimensions to create its canvas, |
||||
// so the ratio will always be the one of the max dimension canvas |
||||
if (!$this->provider instanceof \OC\Preview\TXT) { |
||||
$this->doesRatioMatch($preview, $ratio); |
||||
} |
||||
$this->doesPreviewFit($preview); |
||||
} |
||||
|
||||
/** |
||||
* Adds the test file to the filesystem |
||||
* |
||||
* @param string $fileName name of the file to create |
||||
* @param string $fileContent path to file to use for test |
||||
* |
||||
* @return string |
||||
*/ |
||||
protected function prepareTestFile($fileName, $fileContent) { |
||||
$imgData = file_get_contents($fileContent); |
||||
$imgPath = '/' . $this->userId . '/files/' . $fileName; |
||||
$this->rootView->file_put_contents($imgPath, $imgData); |
||||
|
||||
$scanner = $this->storage->getScanner(); |
||||
$scanner->scan(''); |
||||
|
||||
return $imgPath; |
||||
} |
||||
|
||||
/** |
||||
* Retrieves a max size thumbnail can be created |
||||
* |
||||
* @param \OC\Preview\Provider $provider |
||||
* |
||||
* @return bool|\OCP\IImage |
||||
*/ |
||||
private function getPreview($provider) { |
||||
$preview = $provider->getThumbnail($this->imgPath, $this->maxWidth, $this->maxHeight, $this->scalingUp, $this->rootView); |
||||
|
||||
$this->assertNotEquals(false, $preview); |
||||
$this->assertEquals(true, $preview->valid()); |
||||
|
||||
return $preview; |
||||
} |
||||
|
||||
/** |
||||
* Checks if the preview ratio matches the original ratio |
||||
* |
||||
* @param \OCP\IImage $preview |
||||
* @param int $ratio |
||||
*/ |
||||
private function doesRatioMatch($preview, $ratio) { |
||||
$previewRatio = round($preview->width() / $preview->height(), 2); |
||||
$this->assertEquals($ratio, $previewRatio); |
||||
} |
||||
|
||||
/** |
||||
* Tests if a max size preview of smaller dimensions can be created |
||||
* |
||||
* @param \OCP\IImage $preview |
||||
*/ |
||||
private function doesPreviewFit($preview) { |
||||
$maxDimRatio = round($this->maxWidth / $this->maxHeight, 2); |
||||
$previewRatio = round($preview->width() / $preview->height(), 2); |
||||
|
||||
// Testing code |
||||
/*print_r("mw $this->maxWidth "); |
||||
print_r("mh $this->maxHeight "); |
||||
print_r("mr $maxDimRatio "); |
||||
$pw = $preview->width(); |
||||
$ph = $preview->height(); |
||||
print_r("pw $pw "); |
||||
print_r("ph $ph "); |
||||
print_r("pr $previewRatio ");*/ |
||||
|
||||
if ($maxDimRatio < $previewRatio) { |
||||
$this->assertLessThanOrEqual($this->maxWidth, $preview->width()); |
||||
$this->assertLessThan($this->maxHeight, $preview->height()); |
||||
} elseif ($maxDimRatio > $previewRatio) { |
||||
$this->assertLessThan($this->maxWidth, $preview->width()); |
||||
$this->assertLessThanOrEqual($this->maxHeight, $preview->height()); |
||||
} else { // Original had to be resized |
||||
$this->assertLessThanOrEqual($this->maxWidth, $preview->width()); |
||||
$this->assertLessThanOrEqual($this->maxHeight, $preview->height()); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@ |
||||
<?php |
||||
/** |
||||
* @author Olivier Paroz <owncloud@interfasys.ch> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Preview; |
||||
|
||||
class SVG extends Provider { |
||||
|
||||
public function setUp() { |
||||
$checkImagick = new \Imagick(); |
||||
if (count($checkImagick->queryFormats('SVG')) === 1) { |
||||
parent::setUp(); |
||||
|
||||
$fileName = 'testimagelarge.svg'; |
||||
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); |
||||
$this->width = 3000; |
||||
$this->height = 2000; |
||||
$this->provider = new \OC\Preview\SVG; |
||||
} else { |
||||
$this->markTestSkipped('No SVG provider present'); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,37 @@ |
||||
<?php |
||||
/** |
||||
* @author Olivier Paroz <owncloud@interfasys.ch> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace Test\Preview; |
||||
|
||||
class TXT extends Provider { |
||||
|
||||
public function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$fileName = 'lorem-big.txt'; |
||||
$this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); |
||||
// Arbitrary width and length which won't be used to calculate the ratio |
||||
$this->width = 500; |
||||
$this->height = 200; |
||||
$this->provider = new \OC\Preview\TXT; |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue