PageRenderTime 32ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/test/classes/Plugins/Transformations/TransformationPluginsTest.php

http://github.com/phpmyadmin/phpmyadmin
PHP | 1297 lines | 1216 code | 18 blank | 63 comment | 4 complexity | 0b04564cf4ce74c785d58940ad19633d MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Tests\Plugins\Transformations;
  4. use PhpMyAdmin\FieldMetadata;
  5. use PhpMyAdmin\Plugins\Transformations\Input\Image_JPEG_Upload;
  6. use PhpMyAdmin\Plugins\Transformations\Input\Text_Plain_FileUpload;
  7. use PhpMyAdmin\Plugins\Transformations\Input\Text_Plain_Iptolong;
  8. use PhpMyAdmin\Plugins\Transformations\Input\Text_Plain_RegexValidation;
  9. use PhpMyAdmin\Plugins\Transformations\Output\Application_Octetstream_Download;
  10. use PhpMyAdmin\Plugins\Transformations\Output\Application_Octetstream_Hex;
  11. use PhpMyAdmin\Plugins\Transformations\Output\Image_JPEG_Inline;
  12. use PhpMyAdmin\Plugins\Transformations\Output\Image_JPEG_Link;
  13. use PhpMyAdmin\Plugins\Transformations\Output\Image_PNG_Inline;
  14. use PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Dateformat;
  15. use PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_External;
  16. use PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Formatted;
  17. use PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Imagelink;
  18. use PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Sql;
  19. use PhpMyAdmin\Plugins\Transformations\Text_Plain_Link;
  20. use PhpMyAdmin\Plugins\Transformations\Text_Plain_Longtoipv4;
  21. use PhpMyAdmin\Plugins\Transformations\Text_Plain_PreApPend;
  22. use PhpMyAdmin\Plugins\Transformations\Text_Plain_Substring;
  23. use PhpMyAdmin\Tests\AbstractTestCase;
  24. use ReflectionMethod;
  25. use function date_default_timezone_set;
  26. use function function_exists;
  27. use function method_exists;
  28. use const MYSQLI_TYPE_STRING;
  29. use const MYSQLI_TYPE_TINY;
  30. /**
  31. * Tests for different input/output transformation plugins
  32. *
  33. * @coversNothing
  34. */
  35. class TransformationPluginsTest extends AbstractTestCase
  36. {
  37. /**
  38. * Sets up the fixture, for example, opens a network connection.
  39. * This method is called before a test is executed.
  40. *
  41. * @access protected
  42. */
  43. protected function setUp(): void
  44. {
  45. parent::setUp();
  46. parent::setLanguage();
  47. // For Application Octetstream Download plugin
  48. global $row, $fields_meta;
  49. $fields_meta = [];
  50. $row = [
  51. 'pma' => 'aaa',
  52. 'pca' => 'bbb',
  53. ];
  54. // For Image_*_Inline plugin
  55. parent::setGlobalConfig();
  56. $GLOBALS['Server'] = 1;
  57. // For Date Format plugin
  58. date_default_timezone_set('UTC');
  59. }
  60. /**
  61. * Data provider for testGetMulti
  62. */
  63. public function multiDataProvider(): array
  64. {
  65. return [
  66. // Test data for PhpMyAdmin\Plugins\Transformations\Input\Image_JPEG_Upload plugin
  67. [
  68. new Image_JPEG_Upload(),
  69. 'getName',
  70. 'Image upload',
  71. ],
  72. [
  73. new Image_JPEG_Upload(),
  74. 'getInfo',
  75. 'Image upload functionality which also displays a thumbnail.'
  76. . ' The options are the width and height of the thumbnail'
  77. . ' in pixels. Defaults to 100 X 100.',
  78. ],
  79. [
  80. new Image_JPEG_Upload(),
  81. 'getMIMEType',
  82. 'Image',
  83. ],
  84. [
  85. new Image_JPEG_Upload(),
  86. 'getMIMESubtype',
  87. 'JPEG',
  88. ],
  89. [
  90. new Image_JPEG_Upload(),
  91. 'getScripts',
  92. ['transformations/image_upload.js'],
  93. ],
  94. [
  95. new Image_JPEG_Upload(),
  96. 'getInputHtml',
  97. '<img src="" width="150" height="100" '
  98. . 'alt="Image preview here"><br><input type="file" '
  99. . 'name="fields_uploadtest" accept="image/*" class="image-upload">',
  100. [
  101. [],
  102. 0,
  103. 'test',
  104. ['150'],
  105. '',
  106. 'ltr',
  107. 0,
  108. 0,
  109. 0,
  110. ],
  111. ],
  112. [
  113. new Image_JPEG_Upload(),
  114. 'getInputHtml',
  115. '<input type="hidden" name="fields_prev2ndtest" '
  116. . 'value="736f6d657468696e67"><input type="hidden" '
  117. . 'name="fields2ndtest" value="736f6d657468696e67">'
  118. . '<img src="index.php?route=/transformation/wrapper&key=value&lang=en" width="100" '
  119. . 'height="100" alt="Image preview here"><br><input type="file" '
  120. . 'name="fields_upload2ndtest" accept="image/*" '
  121. . 'class="image-upload">',
  122. [
  123. [],
  124. 0,
  125. '2ndtest',
  126. [
  127. 'wrapper_link' => '?table=a',
  128. 'wrapper_params' => ['key' => 'value'],
  129. ],
  130. 'something',
  131. 'ltr',
  132. 0,
  133. 0,
  134. 0,
  135. ],
  136. ],
  137. // Test data for TextPlainFileupload plugin
  138. [
  139. new Text_Plain_FileUpload(),
  140. 'getName',
  141. 'Text file upload',
  142. ],
  143. [
  144. new Text_Plain_FileUpload(),
  145. 'getInfo',
  146. 'File upload functionality for TEXT columns. It does not have a textarea for input.',
  147. ],
  148. [
  149. new Text_Plain_FileUpload(),
  150. 'getMIMEType',
  151. 'Text',
  152. ],
  153. [
  154. new Text_Plain_FileUpload(),
  155. 'getMIMESubtype',
  156. 'Plain',
  157. ],
  158. [
  159. new Text_Plain_FileUpload(),
  160. 'getScripts',
  161. [],
  162. ],
  163. [
  164. new Text_Plain_FileUpload(),
  165. 'getInputHtml',
  166. '<input type="file" name="fields_uploadtest">',
  167. [
  168. [],
  169. 0,
  170. 'test',
  171. [],
  172. '',
  173. 'ltr',
  174. 0,
  175. 0,
  176. 0,
  177. ],
  178. ],
  179. [
  180. new Text_Plain_FileUpload(),
  181. 'getInputHtml',
  182. '<input type="hidden" name="fields_prev2ndtest" '
  183. . 'value="something"><input type="hidden" name="fields2ndtest" '
  184. . 'value="something"><input type="file" '
  185. . 'name="fields_upload2ndtest">',
  186. [
  187. [],
  188. 0,
  189. '2ndtest',
  190. [],
  191. 'something',
  192. 'ltr',
  193. 0,
  194. 0,
  195. 0,
  196. ],
  197. ],
  198. // Test data for Text_Plain_Regexvalidation plugin
  199. [
  200. new Text_Plain_RegexValidation(),
  201. 'getName',
  202. 'Regex Validation',
  203. ],
  204. [
  205. new Text_Plain_RegexValidation(),
  206. 'getInfo',
  207. 'Validates the string using regular expression '
  208. . 'and performs insert only if string matches it. '
  209. . 'The first option is the Regular Expression.',
  210. ],
  211. [
  212. new Text_Plain_RegexValidation(),
  213. 'getMIMEType',
  214. 'Text',
  215. ],
  216. [
  217. new Text_Plain_RegexValidation(),
  218. 'getMIMESubtype',
  219. 'Plain',
  220. ],
  221. [
  222. new Text_Plain_RegexValidation(),
  223. 'getInputHtml',
  224. '',
  225. [
  226. [],
  227. 0,
  228. '',
  229. [],
  230. '',
  231. 'ltr',
  232. 0,
  233. 0,
  234. 0,
  235. ],
  236. ],
  237. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Application_Octetstream_Download plugin
  238. [
  239. new Application_Octetstream_Download(),
  240. 'getName',
  241. 'Download',
  242. ],
  243. [
  244. new Application_Octetstream_Download(),
  245. 'getInfo',
  246. 'Displays a link to download the binary data of the column. You can'
  247. . ' use the first option to specify the filename, or use the second'
  248. . ' option as the name of a column which contains the filename. If'
  249. . ' you use the second option, you need to set the first option to'
  250. . ' the empty string.',
  251. ],
  252. [
  253. new Application_Octetstream_Download(),
  254. 'getMIMEType',
  255. 'Application',
  256. ],
  257. [
  258. new Application_Octetstream_Download(),
  259. 'getMIMESubtype',
  260. 'OctetStream',
  261. ],
  262. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Application_Octetstream_Hex plugin
  263. [
  264. new Application_Octetstream_Hex(),
  265. 'getName',
  266. 'Hex',
  267. ],
  268. [
  269. new Application_Octetstream_Hex(),
  270. 'getInfo',
  271. 'Displays hexadecimal representation of data. Optional first'
  272. . ' parameter specifies how often space will be added (defaults'
  273. . ' to 2 nibbles).',
  274. ],
  275. [
  276. new Application_Octetstream_Hex(),
  277. 'getMIMEType',
  278. 'Application',
  279. ],
  280. [
  281. new Application_Octetstream_Hex(),
  282. 'getMIMESubtype',
  283. 'OctetStream',
  284. ],
  285. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Image_JPEG_Inline plugin
  286. [
  287. new Image_JPEG_Inline(),
  288. 'getName',
  289. 'Inline',
  290. ],
  291. [
  292. new Image_JPEG_Inline(),
  293. 'getInfo',
  294. 'Displays a clickable thumbnail. The options are the maximum width'
  295. . ' and height in pixels. The original aspect ratio is preserved.',
  296. ],
  297. [
  298. new Image_JPEG_Inline(),
  299. 'getMIMEType',
  300. 'Image',
  301. ],
  302. [
  303. new Image_JPEG_Inline(),
  304. 'getMIMESubtype',
  305. 'JPEG',
  306. ],
  307. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Image_JPEG_Link plugin
  308. [
  309. new Image_JPEG_Link(),
  310. 'getName',
  311. 'ImageLink',
  312. ],
  313. [
  314. new Image_JPEG_Link(),
  315. 'getInfo',
  316. 'Displays a link to download this image.',
  317. ],
  318. [
  319. new Image_JPEG_Link(),
  320. 'getMIMEType',
  321. 'Image',
  322. ],
  323. [
  324. new Image_JPEG_Link(),
  325. 'getMIMESubtype',
  326. 'JPEG',
  327. ],
  328. [
  329. new Image_JPEG_Link(),
  330. 'applyTransformationNoWrap',
  331. null,
  332. ],
  333. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Image_PNG_Inline plugin
  334. [
  335. new Image_PNG_Inline(),
  336. 'getName',
  337. 'Inline',
  338. ],
  339. [
  340. new Image_PNG_Inline(),
  341. 'getInfo',
  342. 'Displays a clickable thumbnail. The options are the maximum width'
  343. . ' and height in pixels. The original aspect ratio is preserved.',
  344. ],
  345. [
  346. new Image_PNG_Inline(),
  347. 'getMIMEType',
  348. 'Image',
  349. ],
  350. [
  351. new Image_PNG_Inline(),
  352. 'getMIMESubtype',
  353. 'PNG',
  354. ],
  355. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Dateformat plugin
  356. [
  357. new Text_Plain_Dateformat(),
  358. 'getName',
  359. 'Date Format',
  360. ],
  361. [
  362. new Text_Plain_Dateformat(),
  363. 'getInfo',
  364. 'Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp'
  365. . ' column as formatted date. The first option is the offset (in'
  366. . ' hours) which will be added to the timestamp (Default: 0). Use'
  367. . ' second option to specify a different date/time format string.'
  368. . ' Third option determines whether you want to see local date or'
  369. . ' UTC one (use "local" or "utc" strings) for that. According to'
  370. . ' that, date format has different value - for "local" see the'
  371. . ' documentation for PHP\'s strftime() function and for "utc" it'
  372. . ' is done using gmdate() function.',
  373. ],
  374. [
  375. new Text_Plain_Dateformat(),
  376. 'getMIMEType',
  377. 'Text',
  378. ],
  379. [
  380. new Text_Plain_Dateformat(),
  381. 'getMIMESubtype',
  382. 'Plain',
  383. ],
  384. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_External plugin
  385. [
  386. new Text_Plain_External(),
  387. 'getName',
  388. 'External',
  389. ],
  390. [
  391. new Text_Plain_External(),
  392. 'getInfo',
  393. 'LINUX ONLY:'
  394. . ' Launches an external application and feeds it the column'
  395. . ' data via standard input. Returns the standard output of the'
  396. . ' application. The default is Tidy, to pretty-print HTML code.'
  397. . ' For security reasons, you have to manually edit the file'
  398. . ' libraries/classes/Plugins/Transformations/Abs/ExternalTransformationsPlugin'
  399. . '.php and list the tools you want to make available.'
  400. . ' The first option is then the number of the program you want to'
  401. . ' use. The second option should be blank for historical reasons.'
  402. . ' The third option, if set to 1, will convert the output using'
  403. . ' htmlspecialchars() (Default 1). The fourth option, if set to 1,'
  404. . ' will prevent wrapping and ensure that the output appears all on'
  405. . ' one line (Default 1).',
  406. ],
  407. [
  408. new Text_Plain_External(),
  409. 'getMIMEType',
  410. 'Text',
  411. ],
  412. [
  413. new Text_Plain_External(),
  414. 'getMIMESubtype',
  415. 'Plain',
  416. ],
  417. [
  418. new Text_Plain_External(),
  419. 'applyTransformationNoWrap',
  420. true,
  421. [
  422. [
  423. '/dev/null -i -wrap -q',
  424. '/dev/null -i -wrap -q',
  425. ],
  426. ],
  427. ],
  428. [
  429. new Text_Plain_External(),
  430. 'applyTransformationNoWrap',
  431. true,
  432. [
  433. [
  434. '/dev/null -i -wrap -q',
  435. '/dev/null -i -wrap -q',
  436. '/dev/null -i -wrap -q',
  437. 1,
  438. ],
  439. ],
  440. ],
  441. [
  442. new Text_Plain_External(),
  443. 'applyTransformationNoWrap',
  444. true,
  445. [
  446. [
  447. '/dev/null -i -wrap -q',
  448. '/dev/null -i -wrap -q',
  449. '/dev/null -i -wrap -q',
  450. '1',
  451. ],
  452. ],
  453. ],
  454. [
  455. new Text_Plain_External(),
  456. 'applyTransformationNoWrap',
  457. false,
  458. [
  459. [
  460. '/dev/null -i -wrap -q',
  461. '/dev/null -i -wrap -q',
  462. '/dev/null -i -wrap -q',
  463. 2,
  464. ],
  465. ],
  466. ],
  467. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Formatted plugin
  468. [
  469. new Text_Plain_Formatted(),
  470. 'getName',
  471. 'Formatted',
  472. ],
  473. [
  474. new Text_Plain_Formatted(),
  475. 'getInfo',
  476. 'Displays the contents of the column as-is, without running it'
  477. . ' through htmlspecialchars(). That is, the column is assumed'
  478. . ' to contain valid HTML.',
  479. ],
  480. [
  481. new Text_Plain_Formatted(),
  482. 'getMIMEType',
  483. 'Text',
  484. ],
  485. [
  486. new Text_Plain_Formatted(),
  487. 'getMIMESubtype',
  488. 'Plain',
  489. ],
  490. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Imagelink plugin
  491. [
  492. new Text_Plain_Imagelink(),
  493. 'getName',
  494. 'Image Link',
  495. ],
  496. [
  497. new Text_Plain_Imagelink(),
  498. 'getInfo',
  499. 'Displays an image and a link; '
  500. . 'the column contains the filename. The first option'
  501. . ' is a URL prefix like "https://www.example.com/". '
  502. . 'The second and third options'
  503. . ' are the width and the height in pixels.',
  504. ],
  505. [
  506. new Text_Plain_Imagelink(),
  507. 'getMIMEType',
  508. 'Text',
  509. ],
  510. [
  511. new Text_Plain_Imagelink(),
  512. 'getMIMESubtype',
  513. 'Plain',
  514. ],
  515. // Test data for PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Sql plugin
  516. [
  517. new Text_Plain_Sql(),
  518. 'getName',
  519. 'SQL',
  520. ],
  521. [
  522. new Text_Plain_Sql(),
  523. 'getInfo',
  524. 'Formats text as SQL query with syntax highlighting.',
  525. ],
  526. [
  527. new Text_Plain_Sql(),
  528. 'getMIMEType',
  529. 'Text',
  530. ],
  531. [
  532. new Text_Plain_Sql(),
  533. 'getMIMESubtype',
  534. 'Plain',
  535. ],
  536. // Test data for PhpMyAdmin\Plugins\Transformations\Text_Plain_Link plugin
  537. [
  538. new Text_Plain_Link(),
  539. 'getName',
  540. 'TextLink',
  541. ],
  542. [
  543. new Text_Plain_Link(),
  544. 'getInfo',
  545. 'Displays a link; the column contains the filename. The first option'
  546. . ' is a URL prefix like "https://www.example.com/".'
  547. . ' The second option is a title for the link.',
  548. ],
  549. [
  550. new Text_Plain_Link(),
  551. 'getMIMEType',
  552. 'Text',
  553. ],
  554. [
  555. new Text_Plain_Link(),
  556. 'getMIMESubtype',
  557. 'Plain',
  558. ],
  559. // Test data for PhpMyAdmin\Plugins\Transformations\Text_Plain_Longtoipv4 plugin
  560. [
  561. new Text_Plain_Longtoipv4(),
  562. 'getName',
  563. 'Long To IPv4',
  564. ],
  565. [
  566. new Text_Plain_Longtoipv4(),
  567. 'getInfo',
  568. 'Converts an (IPv4) Internet network address stored as a BIGINT'
  569. . ' into a string in Internet standard dotted format.',
  570. ],
  571. [
  572. new Text_Plain_Longtoipv4(),
  573. 'getMIMEType',
  574. 'Text',
  575. ],
  576. [
  577. new Text_Plain_Longtoipv4(),
  578. 'getMIMESubtype',
  579. 'Plain',
  580. ],
  581. // Test data for Text_Plain_PreApPend plugin
  582. [
  583. new Text_Plain_PreApPend(),
  584. 'getName',
  585. 'PreApPend',
  586. ],
  587. [
  588. new Text_Plain_PreApPend(),
  589. 'getInfo',
  590. 'Prepends and/or Appends text to a string. First option is text'
  591. . ' to be prepended, second is appended (enclosed in single'
  592. . ' quotes, default empty string).',
  593. ],
  594. [
  595. new Text_Plain_PreApPend(),
  596. 'getMIMEType',
  597. 'Text',
  598. ],
  599. [
  600. new Text_Plain_PreApPend(),
  601. 'getMIMESubtype',
  602. 'Plain',
  603. ],
  604. // Test data for PhpMyAdmin\Plugins\Transformations\Text_Plain_Substring plugin
  605. [
  606. new Text_Plain_Substring(),
  607. 'getName',
  608. 'Substring',
  609. ],
  610. [
  611. new Text_Plain_Substring(),
  612. 'getInfo',
  613. 'Displays a part of a string. The first option is the number '
  614. . 'of characters to skip from the beginning of the string '
  615. . '(Default 0). The second option is the number of characters '
  616. . 'to return (Default: until end of string). The third option is '
  617. . 'the string to append and/or prepend when truncation occurs '
  618. . '(Default: "…").',
  619. ],
  620. [
  621. new Text_Plain_Substring(),
  622. 'getMIMEType',
  623. 'Text',
  624. ],
  625. [
  626. new Text_Plain_Substring(),
  627. 'getMIMESubtype',
  628. 'Plain',
  629. ],
  630. [
  631. new Text_Plain_Substring(),
  632. 'getOptions',
  633. [
  634. 'foo',
  635. 'bar',
  636. 'baz',
  637. ],
  638. [
  639. [],
  640. [
  641. 'foo',
  642. 'bar',
  643. 'baz',
  644. ],
  645. ],
  646. ],
  647. [
  648. new Text_Plain_Substring(),
  649. 'getOptions',
  650. [
  651. 'foo',
  652. 'bar',
  653. 'baz',
  654. ],
  655. [
  656. [
  657. 'foo',
  658. 'bar',
  659. 'baz',
  660. ],
  661. [
  662. 'foo',
  663. 'bar',
  664. 'baz',
  665. ],
  666. ],
  667. ],
  668. [
  669. new Text_Plain_Substring(),
  670. 'getOptions',
  671. [
  672. 'foo',
  673. 'bar',
  674. 'baz',
  675. ],
  676. [
  677. [
  678. 'foo',
  679. 'bar',
  680. 'baz',
  681. ],
  682. [
  683. 1,
  684. 2,
  685. 3,
  686. ],
  687. ],
  688. ],
  689. ];
  690. }
  691. /**
  692. * Tests for getInfo, getName, getMIMEType, getMIMESubtype
  693. * getScripts, applyTransformationNoWrap, getOptions
  694. *
  695. * @param object $object instance of the plugin
  696. * @param string $method the method name
  697. * @param mixed $expected the expected output
  698. * @param array $args the array of arguments
  699. *
  700. * @dataProvider multiDataProvider
  701. * @group medium
  702. */
  703. public function testGetMulti($object, string $method, $expected, array $args = []): void
  704. {
  705. if (! method_exists($object, $method)) {
  706. return;
  707. }
  708. $reflectionMethod = new ReflectionMethod($object, $method);
  709. $this->assertEquals(
  710. $expected,
  711. $reflectionMethod->invokeArgs($object, $args)
  712. );
  713. }
  714. /**
  715. * Data provider for testTransformation
  716. */
  717. public function transformationDataProvider(): array
  718. {
  719. $result = [
  720. [
  721. new Image_JPEG_Upload(),
  722. [
  723. 'test',
  724. [
  725. 150,
  726. 100,
  727. ],
  728. ],
  729. 'test',
  730. ],
  731. [
  732. new Text_Plain_FileUpload(),
  733. [
  734. 'test',
  735. [],
  736. ],
  737. 'test',
  738. ],
  739. [
  740. new Text_Plain_RegexValidation(),
  741. [
  742. 'phpMyAdmin',
  743. ['/php/i'],
  744. ],
  745. 'phpMyAdmin',
  746. true,
  747. '',
  748. ],
  749. [
  750. new Text_Plain_RegexValidation(),
  751. [
  752. 'qwerty',
  753. ['/^a/'],
  754. ],
  755. 'qwerty',
  756. false,
  757. 'Validation failed for the input string qwerty.',
  758. ],
  759. [
  760. new Application_Octetstream_Download(),
  761. [
  762. 'PMA_BUFFER',
  763. [
  764. 0 => 'filename',
  765. 'wrapper_link' => 'PMA_wrapper_link',
  766. 'wrapper_params' => ['key' => 'value'],
  767. ],
  768. ],
  769. '<a href="index.php?route=/transformation/wrapper&key=value'
  770. . '&ct=application%2Foctet-stream&cn=filename&lang=en" '
  771. . 'title="filename" class="disableAjax">filename</a>',
  772. ],
  773. [
  774. new Application_Octetstream_Download(),
  775. [
  776. 'PMA_BUFFER',
  777. [
  778. 0 => '',
  779. 1 => 'cloumn',
  780. 'wrapper_link' => 'PMA_wrapper_link',
  781. 'wrapper_params' => ['key' => 'value'],
  782. ],
  783. ],
  784. '<a href="index.php?route=/transformation/wrapper&key=value'
  785. . '&ct=application%2Foctet-stream&cn=binary_file.dat&lang=en" '
  786. . 'title="binary_file.dat" class="disableAjax">binary_file.dat</a>',
  787. ],
  788. [
  789. new Application_Octetstream_Hex(),
  790. [
  791. '11111001',
  792. [3],
  793. ],
  794. '313 131 313 130 303 1 ',
  795. ],
  796. [
  797. new Application_Octetstream_Hex(),
  798. [
  799. '11111001',
  800. [0],
  801. ],
  802. '3131313131303031',
  803. ],
  804. [
  805. new Application_Octetstream_Hex(),
  806. [
  807. '11111001',
  808. [],
  809. ],
  810. '31 31 31 31 31 30 30 31 ',
  811. ],
  812. [
  813. new Image_JPEG_Link(),
  814. [
  815. 'PMA_IMAGE_LINK',
  816. [
  817. 0 => './image/',
  818. 1 => '200',
  819. 'wrapper_link' => 'PMA_wrapper_link',
  820. 'wrapper_params' => ['key' => 'value'],
  821. ],
  822. ],
  823. '<a class="disableAjax" target="_blank" rel="noopener noreferrer"'
  824. . ' href="index.php?route=/transformation/wrapper&key=value&lang=en"'
  825. . ' alt="[PMA_IMAGE_LINK]">[BLOB]</a>',
  826. ],
  827. [
  828. new Text_Plain_Dateformat(),
  829. [
  830. 12345,
  831. [0],
  832. new FieldMetadata(MYSQLI_TYPE_TINY, 0, (object) []),
  833. ],
  834. '<dfn onclick="alert(\'12345\');" title="12345">Jan 01, 1970 at 03:25 AM</dfn>',
  835. ],
  836. [
  837. new Text_Plain_Dateformat(),
  838. [
  839. 12345678,
  840. [0],
  841. new FieldMetadata(MYSQLI_TYPE_STRING, 0, (object) []),
  842. ],
  843. '<dfn onclick="alert(\'12345678\');" title="12345678">May 23, 1970 at 09:21 PM</dfn>',
  844. ],
  845. [
  846. new Text_Plain_Dateformat(),
  847. [
  848. 123456789,
  849. [0],
  850. new FieldMetadata(-1, 0, (object) []),
  851. ],
  852. '<dfn onclick="alert(\'123456789\');" title="123456789">Nov 29, 1973 at 09:33 PM</dfn>',
  853. ],
  854. [
  855. new Text_Plain_Dateformat(),
  856. [
  857. '20100201',
  858. [0],
  859. new FieldMetadata(-1, 0, (object) []),
  860. ],
  861. '<dfn onclick="alert(\'20100201\');" title="20100201">Feb 01, 2010 at 12:00 AM</dfn>',
  862. ],
  863. [
  864. new Text_Plain_Dateformat(),
  865. [
  866. '1617153941',
  867. [
  868. '0',
  869. '%B %d, %Y at %I:%M %p',
  870. 'local',
  871. ],
  872. new FieldMetadata(-1, 0, (object) []),
  873. ],
  874. '<dfn onclick="alert(\'1617153941\');" title="1617153941">Mar 31, 2021 at 01:25 AM</dfn>',
  875. ],
  876. [
  877. new Text_Plain_Dateformat(),
  878. [
  879. '1617153941',
  880. [
  881. '0',
  882. '',// Empty uses the "Y-m-d H:i:s" format
  883. 'utc',
  884. ],
  885. new FieldMetadata(-1, 0, (object) []),
  886. ],
  887. '<dfn onclick="alert(\'1617153941\');" title="1617153941">2021-03-31 01:25:41</dfn>',
  888. ],
  889. [
  890. new Text_Plain_Dateformat(),
  891. [
  892. '1617153941',
  893. [
  894. '0',
  895. '',// Empty uses the "%B %d, %Y at %I:%M %p" format
  896. 'local',
  897. ],
  898. new FieldMetadata(-1, 0, (object) []),
  899. ],
  900. '<dfn onclick="alert(\'1617153941\');" title="1617153941">Mar 31, 2021 at 01:25 AM</dfn>',
  901. ],
  902. [
  903. new Text_Plain_Dateformat(),
  904. [
  905. '1617153941',
  906. [
  907. '0',
  908. 'H:i:s Y-d-m',
  909. 'utc',
  910. ],
  911. new FieldMetadata(-1, 0, (object) []),
  912. ],
  913. '<dfn onclick="alert(\'1617153941\');" title="1617153941">01:25:41 2021-31-03</dfn>',
  914. ],
  915. [
  916. new Text_Plain_External(),
  917. [
  918. 'PMA_BUFFER',
  919. [
  920. '/dev/null -i -wrap -q',
  921. '/dev/null -i -wrap -q',
  922. ],
  923. ],
  924. 'PMA_BUFFER',
  925. ],
  926. [
  927. new Text_Plain_Formatted(),
  928. [
  929. "<a ref='https://www.example.com/'>PMA_BUFFER</a>",
  930. [
  931. 'option1',
  932. 'option2',
  933. ],
  934. ],
  935. "<iframe srcdoc=\"<a ref='https://www.example.com/'>PMA_BUFFER</a>\" sandbox=\"\"></iframe>",
  936. ],
  937. [
  938. new Text_Plain_Formatted(),
  939. [
  940. '<a ref="https://www.example.com/">PMA_BUFFER</a>',
  941. [
  942. 'option1',
  943. 'option2',
  944. ],
  945. ],
  946. "<iframe srcdoc=\"<a ref='https://www.example.com/'>PMA_BUFFER</a>\" sandbox=\"\"></iframe>",
  947. ],
  948. [
  949. new Text_Plain_Imagelink(),
  950. [
  951. 'PMA_IMAGE',
  952. [
  953. 'http://image/',
  954. '200',
  955. ],
  956. ],
  957. '<a href="http://image/PMA_IMAGE" rel="noopener noreferrer" target="_blank">' . "\n"
  958. . ' <img src="http://image/PMA_IMAGE" border="0" width="200" height="50">' . "\n"
  959. . ' PMA_IMAGE' . "\n"
  960. . '</a>' . "\n",
  961. ],
  962. [
  963. new Text_Plain_Imagelink(),
  964. [
  965. 'PMA_IMAGE',
  966. [
  967. './image/',
  968. '200',
  969. ],
  970. ],
  971. './image/PMA_IMAGE',
  972. ],
  973. [
  974. new Text_Plain_Sql(),
  975. [
  976. 'select *',
  977. [
  978. 'option1',
  979. 'option2',
  980. ],
  981. ],
  982. '<code class="sql"><pre>' . "\n"
  983. . 'select *' . "\n"
  984. . '</pre></code>',
  985. ],
  986. [
  987. new Text_Plain_Link(),
  988. [
  989. 'PMA_TXT_LINK',
  990. [
  991. './php/',
  992. 'text_name',
  993. ],
  994. ],
  995. './php/PMA_TXT_LINK',
  996. ],
  997. [
  998. new Text_Plain_Link(),
  999. [
  1000. 'PMA_TXT_LINK',
  1001. [],
  1002. ],
  1003. 'PMA_TXT_LINK',
  1004. ],
  1005. [
  1006. new Text_Plain_Link(),
  1007. [
  1008. 'https://example.com/PMA_TXT_LINK',
  1009. [],
  1010. ],
  1011. '<a href="https://example.com/PMA_TXT_LINK" title=""'
  1012. . ' target="_blank" rel="noopener noreferrer">https://example.com/PMA_TXT_LINK</a>',
  1013. ],
  1014. [
  1015. new Text_Plain_Link(),
  1016. [
  1017. 'PMA_TXT_LINK',
  1018. [
  1019. './php/',
  1020. 'text_name',
  1021. ],
  1022. ],
  1023. './php/PMA_TXT_LINK',
  1024. ],
  1025. [
  1026. new Text_Plain_Longtoipv4(),
  1027. [
  1028. 42949672,
  1029. [
  1030. 'option1',
  1031. 'option2',
  1032. ],
  1033. ],
  1034. '2.143.92.40',
  1035. ],
  1036. [
  1037. new Text_Plain_Longtoipv4(),
  1038. [
  1039. 4294967295,
  1040. [
  1041. 'option1',
  1042. 'option2',
  1043. ],
  1044. ],
  1045. '255.255.255.255',
  1046. ],
  1047. [
  1048. new Text_Plain_PreApPend(),
  1049. [
  1050. 'My',
  1051. [
  1052. 'php',
  1053. 'Admin',
  1054. ],
  1055. ],
  1056. 'phpMyAdmin',
  1057. ],
  1058. [
  1059. new Text_Plain_Substring(),
  1060. [
  1061. 'PMA_BUFFER',
  1062. [
  1063. 1,
  1064. 3,
  1065. 'suffix',
  1066. ],
  1067. ],
  1068. 'suffixMA_suffix',
  1069. ],
  1070. [
  1071. new Text_Plain_Substring(),
  1072. [
  1073. 'PMA_BUFFER',
  1074. [
  1075. '1',
  1076. '3',
  1077. 'suffix',
  1078. ],
  1079. ],
  1080. 'suffixMA_suffix',
  1081. ],
  1082. [
  1083. new Text_Plain_Substring(),
  1084. [
  1085. 'PMA_BUFFER',
  1086. ['2'],
  1087. ],
  1088. '…A_BUFFER',
  1089. ],
  1090. [
  1091. new Text_Plain_Substring(),
  1092. [
  1093. 'PMA_BUFFER',
  1094. [2],
  1095. ],
  1096. '…A_BUFFER',
  1097. ],
  1098. [
  1099. new Text_Plain_Substring(),
  1100. [
  1101. 'PMA_BUFFER',
  1102. [0],
  1103. ],
  1104. 'PMA_BUFFER',
  1105. ],
  1106. [
  1107. new Text_Plain_Substring(),
  1108. [
  1109. 'PMA_BUFFER',
  1110. ['0'],
  1111. ],
  1112. 'PMA_BUFFER',
  1113. ],
  1114. [
  1115. new Text_Plain_Substring(),
  1116. [
  1117. 'PMA_BUFFER',
  1118. [
  1119. -1,
  1120. ],
  1121. ],
  1122. '…R…',
  1123. ],
  1124. [
  1125. new Text_Plain_Substring(),
  1126. [
  1127. 'PMA_BUFFER',
  1128. ['-1'],
  1129. ],
  1130. '…R…',
  1131. ],
  1132. [
  1133. new Text_Plain_Substring(),
  1134. [
  1135. 'PMA_BUFFER',
  1136. [
  1137. 0,
  1138. 2,
  1139. ],
  1140. ],
  1141. 'PM…',
  1142. ],
  1143. [
  1144. new Text_Plain_Substring(),
  1145. [
  1146. 'PMA_BUFFER',
  1147. [
  1148. '0',
  1149. '2',
  1150. ],
  1151. ],
  1152. 'PM…',
  1153. ],
  1154. [
  1155. new Text_Plain_Substring(),
  1156. [
  1157. 2,
  1158. [],
  1159. ],
  1160. '2',
  1161. ],
  1162. [
  1163. new Text_Plain_Longtoipv4(),
  1164. [168496141],
  1165. '10.11.12.13',
  1166. ],
  1167. [
  1168. new Text_Plain_Longtoipv4(),
  1169. ['168496141'],
  1170. '10.11.12.13',
  1171. ],
  1172. [
  1173. new Text_Plain_Longtoipv4(),
  1174. ['my ip'],
  1175. 'my ip',
  1176. ],
  1177. [
  1178. new Text_Plain_Longtoipv4(),
  1179. ['<my ip>'],
  1180. '&lt;my ip&gt;',
  1181. ],
  1182. [
  1183. new Text_Plain_Iptolong(),
  1184. ['10.11.12.13'],
  1185. 168496141,
  1186. ],
  1187. [
  1188. new Text_Plain_Iptolong(),
  1189. ['10.11.12.913'],
  1190. '10.11.12.913',
  1191. ],
  1192. [
  1193. new Text_Plain_Iptolong(),
  1194. ['my ip'],
  1195. 'my ip',
  1196. ],
  1197. [
  1198. new Text_Plain_Iptolong(),
  1199. ['<my ip>'],
  1200. '<my ip>',
  1201. ],
  1202. ];
  1203. if (function_exists('imagecreatetruecolor')) {
  1204. $result[] = [
  1205. new Image_JPEG_Inline(),
  1206. [
  1207. 'PMA_JPEG_Inline',
  1208. [
  1209. 0 => './image/',
  1210. 1 => '200',
  1211. 'wrapper_link' => 'PMA_wrapper_link',
  1212. 'wrapper_params' => ['key' => 'value'],
  1213. ],
  1214. ],
  1215. '<a href="index.php?route=/transformation/wrapper&key=value&lang=en" '
  1216. . 'rel="noopener noreferrer" target="_blank"><img src="index.php?route=/transformation/wrapper'
  1217. . '&key=value&resize=jpeg&newWidth=0&'
  1218. . 'newHeight=200&lang=en" alt="[PMA_JPEG_Inline]" border="0"></a>',
  1219. ];
  1220. $result[] = [
  1221. new Image_PNG_Inline(),
  1222. [
  1223. 'PMA_PNG_Inline',
  1224. [
  1225. 0 => './image/',
  1226. 1 => '200',
  1227. 'wrapper_link' => 'PMA_wrapper_link',
  1228. 'wrapper_params' => ['key' => 'value'],
  1229. ],
  1230. ],
  1231. '<a href="index.php?route=/transformation/wrapper&key=value&lang=en"'
  1232. . ' rel="noopener noreferrer" target="_blank"><img src="index.php?route=/transformation/wrapper'
  1233. . '&key=value&resize=jpeg&newWidth=0&newHeight=200&lang=en" '
  1234. . 'alt="[PMA_PNG_Inline]" border="0"></a>',
  1235. ];
  1236. }
  1237. return $result;
  1238. }
  1239. /**
  1240. * Tests for applyTransformation, isSuccess, getError
  1241. *
  1242. * @param object $object instance of the plugin
  1243. * @param array $applyArgs arguments for applyTransformation
  1244. * @param string|int $transformed the expected output of applyTransformation
  1245. * @param bool $success the expected output of isSuccess
  1246. * @param string $error the expected output of getError
  1247. *
  1248. * @dataProvider transformationDataProvider
  1249. * @group medium
  1250. */
  1251. public function testTransformation(
  1252. $object,
  1253. array $applyArgs,
  1254. $transformed,
  1255. bool $success = true,
  1256. string $error = ''
  1257. ): void {
  1258. $reflectionMethod = new ReflectionMethod($object, 'applyTransformation');
  1259. $this->assertEquals(
  1260. $transformed,
  1261. $reflectionMethod->invokeArgs($object, $applyArgs)
  1262. );
  1263. // For output transformation plugins, this method may not exist
  1264. if (method_exists($object, 'isSuccess')) {
  1265. $this->assertEquals(
  1266. $success,
  1267. $object->isSuccess()
  1268. );
  1269. }
  1270. // For output transformation plugins, this method may not exist
  1271. if (! method_exists($object, 'getError')) {
  1272. return;
  1273. }
  1274. $this->assertEquals(
  1275. $error,
  1276. $object->getError()
  1277. );
  1278. }
  1279. }