Compare commits

...

289 Commits

Author SHA1 Message Date
Simon Wisselink a3b5e4eaf9 fix php7.4 deprecation and remove php7.4 from travis allow_failures since php7.4 is current stable 2020-04-13 00:47:34 +02:00
Simon Wisselink cf8b820f2c synced unit tests with master codebase, noted TODO's, fixed phpunit scripts and travis config 2020-04-13 00:38:03 +02:00
Simon Wisselink 5db1746129 Removed unneeded files and replace dummy.txt with .gitignore files 2020-04-13 00:03:57 +02:00
Simon Wisselink 57d797fa1d Merge branch 'master' of smarty-php/smarty-phpunit into feature/merge_smarty-phpunit_into_tests_subfolder 2020-04-12 23:15:47 +02:00
Simon Wisselink 2142913e3b Add additional unit tests for several isset issues 2020-01-28 11:42:40 +01:00
Simon Wisselink e1ebc2ac8e Added test for foreachelse on arrayiterators and such https://github.com/smarty-php/smarty/issues/506 2020-01-27 16:01:22 +01:00
uwetews cd4fd962dc Merge pull request #3 from smarty-php/revert-1-fix-composer-deps
Revert "Reinstitute the phpunit/phpunit dependency the right way."
2018-12-09 04:53:14 +01:00
uwetews 7ff8bdb173 Revert "Reinstitute the phpunit/phpunit dependency the right way." 2018-12-09 04:51:05 +01:00
uwetews 9ec3d2d67b Merge pull request #1 from AnrDaemon/fix-composer-deps
Reinstitute the phpunit/phpunit dependency the right way.
2018-12-09 02:35:07 +01:00
AnrDaemon 317f05e348 Reinstitute the phpunit/phpunit dependency the right way. 2018-12-06 20:15:37 +03:00
uwetews 06c4eac7c0 fix {insert} test 2018-11-11 18:35:00 +01:00
uwetews adbcf8a014 Update insert tag tests https://github.com/smarty-php/smarty/issues/496 2018-10-09 06:27:32 +02:00
uwetews 578503c474 Update modifier test https://github.com/smarty-php/smarty/issues/491 2018-10-09 03:28:42 +02:00
uwetews e250f28db7 added test - bugfix some custom left and right delimiters like '{^' '^}' did not work
https://github.com/smarty-php/smarty/issues/450 https://github.com/smarty-php/smarty/pull/482
2018-08-31 17:29:59 +02:00
Uwe Tews 5359963c27 Disable test for now 2018-05-17 04:56:43 +02:00
Uwe Tews 05ce67754a added security test case 2018-04-26 21:37:38 +02:00
Uwe Tews 18d15d7669 add enableSecurity() 2018-04-26 18:00:17 +02:00
Uwe Tews 2f87c74cba update securitytests 2018-04-26 13:33:21 +02:00
Uwe Tews d59e6804fc Update for {fetch} plugin 2018-04-26 12:59:14 +02:00
Uwe Tews c4f3d4fb98 Update for {fetch} plugin 2018-04-25 15:40:25 +02:00
Uwe Tews ced3bf86d8 Update template function tests 2018-03-28 07:02:18 +02:00
Uwe Tews 8f8030805a fix @runInSeparateProcess 2018-03-28 00:55:14 +02:00
Uwe Tews 12b7512311 update new plugin handling 2018-03-27 02:03:37 +02:00
Uwe Tews a341b00676 new feature {parent} = {$smarty.block.parent} {child} = {$smarty.block.child} 2018-03-26 22:26:49 +02:00
Uwe Tews 5fb73cd3c1 short form of {section} attributes did not work https://github.com/smarty-php/smarty/issues/428 2018-03-21 15:17:56 +01:00
Uwe Tews dfdf343b2d https://github.com/smarty-php/smarty/issues/422 2018-03-21 07:35:25 +01:00
Uwe Tews a364e82c6b Test for issue 419 2018-03-16 18:28:49 +01:00
Uwe Tews cbf7e15e2a Update readme.md 2017-11-22 05:21:44 +01:00
Uwe Tews 1a11b61b73 Extend setfilter tag test 2017-11-20 11:26:25 +01:00
Uwe Tews 9d52ba99f7 Extend setfilter tag test 2017-11-20 11:10:45 +01:00
Uwe Tews 1e48db70cf Disable mysql tests 2017-11-20 04:14:57 +01:00
Uwe Tews afd68d7104 Update 2017-11-20 02:17:35 +01:00
Uwe Tews b3a64efa14 Update mysql tests 2017-11-20 00:55:43 +01:00
Uwe Tews ccefb46c30 Update msql resource test 2017-11-19 19:52:31 +01:00
Uwe Tews 0d8ddddc1b Update spacing tests 2017-11-19 10:50:49 +01:00
Uwe Tews bea59cdec4 add and rework tests
add spacing tests for newlines between tags and text
3.1.32-dev-36
2017-11-17 10:41:04 +01:00
Uwe Tews eabde8aaef remove redundant test 2017-11-11 16:19:10 +01:00
Uwe Tews ab726e92df add spacing tests 2017-11-11 14:52:51 +01:00
Uwe Tews ae900c9ebe Disable tests which do not run on PHP 5.4 and below 2017-11-06 04:32:19 +01:00
Uwe Tews 8a6f2493c6 Update exception messages 3.1.32-dev-33 2017-11-05 20:40:46 +01:00
Uwe Tews 51c813556c modified tests for custom delimiters 2017-10-21 12:35:08 +02:00
Uwe Tews 507b96a571 remove E_DEPRECATED for PHP 5.2 compatibility
restore @runTestsInSeparateProcess
2017-10-18 12:59:55 +02:00
Uwe Tews 37288b44e0 update tests to cover
https://github.com/smarty-php/smarty/issues/396 https://github.com/smarty-php/smarty/issues/397
    https://github.com/smarty-php/smarty/issues/391 https://github.com/smarty-php/smarty/issues/392
2017-10-18 09:12:59 +02:00
Uwe Tews fd1846a286 Update double qouted string test 2017-10-12 20:03:28 +02:00
Uwe Tews f41afe355f Update block extends tests https://github.com/smarty-php/smarty/issues/393 2017-10-12 08:11:30 +02:00
Uwe Tews df97b8a14d do not ignore vendor folder because of travis tests 2017-10-09 19:11:35 +02:00
Uwe Tews 3c7f0826d3 Update error_reporting setting 2017-10-09 10:21:16 +02:00
Uwe Tews 462efddfdf Update for 3.1.32-dev-23 2017-10-07 08:22:00 +02:00
Uwe Tews e3e8088029 Add test for boolean and null 2017-09-03 04:49:33 +02:00
Uwe Tews a202d5b464 add test for issue 327 2017-08-26 11:46:33 +02:00
Uwe Tews 661ffe75ef update for 3.1.32-dev 2017-08-09 12:50:32 +02:00
Uwe Tews 2302db0b78 revert last change 2017-07-30 05:07:27 +02:00
Uwe Tews 3c0cc4da1c Update because of https://github.com/smarty-php/smarty/pull/377 2017-07-21 07:00:28 +02:00
uwetews 5c4871a842 Update tests 2017-05-27 12:33:02 +02:00
uwetews 3db8beb54a Update tests 2017-05-27 12:17:09 +02:00
uwetews 889fd2debf Update tests 2017-05-27 11:27:50 +02:00
uwetews 52f84dc39d PHP 5.2 compatibility 2017-05-21 19:14:39 +02:00
uwetews ae311ee2e8 disable closure for PHP 5.2 2017-05-21 18:57:16 +02:00
uwetews 6fcb23196a disable closure for PHP 5.2 2017-05-21 18:54:13 +02:00
uwetews 03900cec3a disable closure for PHP 5.2 2017-05-21 18:41:44 +02:00
uwetews 4f41768ef7 disable closure for PHP 5.2 2017-05-21 18:32:19 +02:00
uwetews 99b782b257 add PHP function tests 2017-04-17 04:20:34 +02:00
uwetews 5fe8455e87 remove coverage from phpunit.xml 2017-04-14 13:08:10 +02:00
uwetews c3afe0bc9d Update for PHPunit >= 5 2017-04-14 12:16:33 +02:00
uwetews 2652c5ef26 reomove require for phpunit 2017-04-14 05:37:17 +02:00
uwetews 62cc0c0e2a Update for PHPunit >= 5 2017-04-14 02:25:56 +02:00
uwetews 279240f76d Delete composer.lock 2017-04-13 19:42:55 +02:00
uwetews 31a515470d Update for PHPunit 5.7 2017-04-13 19:32:44 +02:00
uwetews 7645ae0512 remove version check code 2016-11-19 18:02:13 +01:00
uwetews 5f92ee4ea0 delete wrong test 2016-11-19 07:50:24 +01:00
uwetews eea6256875 gh312 bug test 2016-11-12 09:31:48 +01:00
uwetews f026729c5c gh312 bug test 2016-11-12 09:31:20 +01:00
uwetews 43eb0f3986 update 2016-11-12 01:32:26 +01:00
uwetews b7f845f5a9 test will run sinc php 5.6 2016-11-11 23:03:46 +01:00
uwetews 9bfc85b045 test requires php 5.5 2016-11-11 21:54:08 +01:00
uwetews c0110c1051 add tests for issuse 312 2016-11-11 20:10:23 +01:00
uwetews 6c5e729c9c add test for config variable overloading 2016-10-27 05:28:23 +02:00
uwetews 8e42150426 Test template function call in fetched template 2016-10-27 05:24:08 +02:00
uwetews bfb502b633 {make_nocache} add space test 2016-10-19 20:40:41 +02:00
uwetews 411390b579 update {make_nocache} tests 2016-10-19 19:35:05 +02:00
uwetews 48a954e2e5 Add test for Smarty::$extends_recursion property 2016-09-29 03:44:49 +02:00
uwetews e1ad0ece66 Test <?xml ?> tags in subtemplate 2016-09-28 23:32:01 +02:00
uwetews 81852c085f Test isset() 0n $smarty.foreache special variables 2016-09-20 14:17:17 +02:00
uwetews 75432afb05 Update clear compiled tests 2016-09-20 10:18:08 +02:00
uwetews eebbecf603 Update clear compiled tests 2016-09-19 22:25:57 +02:00
uwetews da69e4d7af Updates because new release update checks 2016-09-19 08:02:34 +02:00
uwetews 268368f2a4 Updates because new release update checks 2016-09-19 07:36:20 +02:00
uwetews 30f7c15d01 update string resource test 2016-09-15 09:25:11 +02:00
uwetews 998b28dcc8 update resource tests 2016-09-15 09:09:00 +02:00
uwetews 0d5dab3b66 Extended {foreach} tests 2016-09-09 22:41:25 +02:00
uwetews 2e9ee3b2a0 add test for getConfigVariable() 2016-09-08 22:19:07 +02:00
uwetews be86d1eb6d replace constant DS with DIRECTORY_SEPARATOR 2016-08-23 07:56:09 +02:00
uwetews 490fb5eaa5 upate unit test 2016-08-14 11:24:22 +02:00
uwetews 1d76572e9a update scope with test for {assign.. noscope} 2016-08-14 03:11:10 +02:00
uwetews e3f5e325ab disable mysql because msql setup problems under HHVM 2016-08-07 20:09:46 +02:00
uwetews 0aab6c9ff6 enable mysql 2016-08-07 19:35:17 +02:00
uwetews fd8f010b05 update config tests 2016-08-07 12:57:48 +02:00
uwetews f8420363b8 Update default handler teste 2016-08-05 21:22:23 +02:00
uwetews 3155e9ce8e Update compiler error 2016-07-25 20:36:36 +02:00
uwetews 419bfe2bc2 update resource tests 2016-07-25 20:32:58 +02:00
uwetews 4354315bb2 add plugins_dir and template_dir normalization test 2016-07-25 20:27:26 +02:00
uwetews e494f65a77 Extend default handler 2016-07-12 23:37:51 +02:00
uwetews bfca72e71b update compiler plugin test 2016-07-12 23:01:29 +02:00
uwetews 93bc56e14f Update security test 2016-07-12 02:28:56 +02:00
uwetews 688151e06f Update capture test 2016-07-12 00:25:14 +02:00
uwetews b823237d67 update unit teste 2016-05-15 11:12:04 +02:00
uwetews 8a8c0cd081 Update inheritance tests 2016-05-01 23:49:04 +02:00
uwetews ec1caa0905 Update strip tests 2016-04-29 00:14:59 +02:00
uwetews 6245f65402 Update capture test 2016-04-14 21:06:51 +02:00
uwetews 66f6c54281 Update {extends} test 2016-04-13 03:30:32 +02:00
uwetews b08b8f1d3a Update capture test 2016-03-27 18:34:13 +02:00
uwetews f6a0749845 revert 2016-03-11 05:57:58 +01:00
uwetews 9802c9291d disable msql 2016-03-11 05:54:32 +01:00
uwetews c6a60a82ca enable memcache amd msql 2016-03-11 05:49:03 +01:00
uwetews 9a291b8da4 add clearCompiledTemplate() tests 2016-03-11 03:29:57 +01:00
uwetews d744c408fe update php resource tests 2016-03-10 20:56:33 +01:00
uwetews 531df47a97 Update scope tests 2016-03-09 00:29:15 +01:00
uwetews d717439a6b Update path normalization test 2016-02-25 23:30:32 +01:00
uwetews 788aa58632 Update strip text 2016-02-20 17:17:21 +01:00
uwetews 13c7a912d9 clear static tag compiler object cache 2016-02-15 14:19:01 +01:00
uwetews 3dcb718b5d update attribute test 2016-02-14 19:46:11 +01:00
uwetews a073234fe3 Add test for new {make_nocache} tag 2016-02-14 03:04:50 +01:00
uwetews 0bcf2127d1 Add test for new {make_nocache} tag 2016-02-14 02:49:22 +01:00
uwetews 2dba744fcb Update function plugin teste 2016-02-10 21:06:19 +01:00
uwetews 90a4a5c28e add more tests for strip 2016-02-10 21:05:36 +01:00
uwetews db8553be32 update test 2016-02-10 03:16:12 +01:00
uwetews 150d24822d update strip test 2016-02-10 01:08:01 +01:00
uwetews 2f7c0f0a99 update if test 2016-02-09 04:18:30 +01:00
uwetews ac5070ea87 update scope tests 2016-02-09 01:40:34 +01:00
uwetews e0d4e4b1fa new core functions 2016-02-09 01:32:50 +01:00
uwetews c48e16c5fe add {break} test 2016-02-01 20:23:25 +01:00
uwetews 33bdb44723 add {break} and {continue} tests 2016-01-29 02:33:40 +01:00
uwetews 39631cce4b add test for block plugin tag stack 2016-01-29 01:08:54 +01:00
uwetews dcb0d4be63 add {extends} tests with relative path 2016-01-27 04:44:05 +01:00
uwetews dd935863bd add output filter tests for caching and nocache code 2016-01-27 00:28:36 +01:00
uwetews 2b7615e23d add nocache teste 2016-01-03 08:18:52 +01:00
uwetews 7bfe828d70 add block plugin caching test 2016-01-02 21:27:37 +01:00
uwetews 7611bedfb5 dummy 2016-01-02 16:59:37 +01:00
uwetews 9307076ffa update block plugin tests 2016-01-02 16:59:02 +01:00
uwetews 42b864b707 update block plugin tests 2016-01-02 11:48:31 +01:00
uwetews 5f7417d495 update block plugin tests 2016-01-02 11:39:16 +01:00
uwetews a56e36c811 update block plugin tests 2016-01-02 11:33:29 +01:00
uwetews a194dd0950 update block plugin tests 2016-01-02 11:17:12 +01:00
uwetews 585850230c update block plugin tests 2016-01-02 04:56:22 +01:00
uwetews fb7908d710 add missing plugin 2016-01-02 02:53:18 +01:00
uwetews c26d0ed365 update scope tests for {config_load} 2016-01-02 02:37:14 +01:00
uwetews 978d7c88c5 update scope tests for {include} 2016-01-02 02:12:31 +01:00
uwetews bac6e3c069 remove old scope tests 2016-01-02 01:33:52 +01:00
uwetews 7caf793eeb add scope tests for {assign} 2016-01-02 00:48:20 +01:00
uwetews eee2bc3a77 add prefilter 2016-01-02 00:43:44 +01:00
uwetews cc68ce89ec disable memcache 2016-01-01 18:51:57 +01:00
uwetews 3b5ff51e0e test if class exists 2015-12-31 06:32:20 +01:00
uwetews ffe0095b80 enable memcache test 2015-12-31 06:30:16 +01:00
uwetews 622bea89f9 PHP 5.2 compatibility 2015-12-31 06:03:21 +01:00
uwetews e363a78e28 replace __DIR__ 2015-12-31 05:38:36 +01:00
uwetews 83e7c90c20 replace __DIR__ 2015-12-31 05:36:00 +01:00
uwetews 66fa8ce092 remove closure test 2015-12-31 05:26:58 +01:00
uwetews 9a61f1511c skip closure on php 5.2 2015-12-31 05:20:00 +01:00
uwetews 1981dd8016 replace __DIR__ 2015-12-31 05:04:07 +01:00
uwetews db914a947d disable mysql for travis because problems under hhvm 2015-12-31 04:06:44 +01:00
uwetews 06b37842dd disable memcached for travis 2015-12-31 03:48:06 +01:00
uwetews 039f1f72f6 enable memcached for travis 2015-12-31 03:43:55 +01:00
uwetews 9b87168a14 disable memcached for travis 2015-12-31 03:34:32 +01:00
uwetews 5c6b9dd186 set time zone 2015-12-31 03:30:14 +01:00
uwetews bf93a7b356 Update 2015-12-31 03:20:56 +01:00
uwetews 3086b4e53d Fix msql test 2015-12-31 03:02:34 +01:00
uwetews ac996820cc enable mysql and memcached tests for travis 2015-12-31 02:48:20 +01:00
uwetews 97b02e9a2e Update {assign] tests 2015-12-31 02:06:18 +01:00
uwetews e390da71e2 https://github.com/smarty-php/smarty/issues/147 2015-12-30 22:27:16 +01:00
uwetews d0f29ae730 add {$smarty.template} and {$smarty.current_dir} tests 2015-12-30 21:24:31 +01:00
uwetews b887f18acf update configuration of disabled resource tests 2015-12-30 21:14:22 +01:00
uwetews 1800432c4c Test E_NOTICE suppression on undefined variables https://github.com/smarty-php/smarty/issues/145 2015-12-30 18:23:46 +01:00
uwetews 7ce2a7dd41 Add SmartyBC tests 2015-12-30 17:45:11 +01:00
uwetews 43237f1526 Add SmartyBC tests 2015-12-30 01:08:02 +01:00
uwetews 25108d3636 Add SmartyBC tests 2015-12-30 00:54:20 +01:00
uwetews e506550ef2 Add SmartyBC tests 2015-12-30 00:46:09 +01:00
uwetews d72ced4e70 Smarty2 wrapper tests 2015-12-30 00:28:27 +01:00
uwetews 9ffad00177 Smarty2 wrapper tests 2015-12-29 21:14:32 +01:00
uwetews 3229f0563b Smarty2 wrapper tests 2015-12-29 20:51:56 +01:00
uwetews 1d1c9bc59e Smarty2 wrapper tests 2015-12-29 19:24:15 +01:00
uwetews 381556a290 Update {foreach} tests 2015-12-28 00:51:28 +01:00
uwetews a4e6d6d609 Update {block} {extends} test 2015-12-27 05:05:54 +01:00
uwetews 3c4361c1c4 Update test 2015-12-25 09:58:40 +01:00
uwetews 3d4fbb88c6 Update extends test 2015-12-25 08:48:25 +01:00
uwetews 6b9648a1dc add post filter test https://github.com/smarty-php/smarty/issues/144 2015-12-24 06:27:11 +01:00
uwetews b4613146b4 Update 2015-12-24 01:56:38 +01:00
uwetews 09d29deeea Add tests for changed template_dir settings 2015-12-24 01:54:50 +01:00
uwetews 007de1fefa Update for file uid changes of 3.1.30 2015-12-24 01:52:30 +01:00
uwetews 1723095862 caching observes now template_dir setting 2015-12-23 04:27:56 +01:00
uwetews 954ea7d963 add test for direct access of protected xxx_dir properties 2015-12-22 01:14:00 +01:00
uwetews 5f9e853035 update strip test 2015-12-21 23:33:41 +01:00
uwetews 5af36fa255 add filepath normalization tests 2015-12-21 22:45:49 +01:00
uwetews cd1d7c4d6a add test where extendsall is default resource 2015-12-21 02:13:46 +01:00
uwetews b1bd7dd347 extend runtime parameter because timing problem on travis 2015-12-20 15:36:57 +01:00
uwetews 781a355436 fix test class name 2015-12-20 14:52:23 +01:00
uwetews 77149f22f6 add Smarty special variable teste 2015-12-20 14:45:25 +01:00
uwetews b4cf3c3d5c insert dummy.txt 2015-12-20 11:25:37 +01:00
uwetews 669bf0ddcd delet dummy.txt (reverted from commit 8c9fe47fa36702daf3c7acb255b442c7c04f685b) (reverted from commit f66230d6df15615e9b33b54f2a97ca7c46be474d) 2015-12-20 11:02:44 +01:00
uwetews 90564a8fb0 delet dummy.txt (reverted from commit 8c9fe47fa36702daf3c7acb255b442c7c04f685b) 2015-12-20 11:00:35 +01:00
uwetews cd5cc546a9 delet dummy.txt 2015-12-20 10:55:45 +01:00
uwetews e9e473da65 add test for chained prepend 2015-12-18 03:58:53 +01:00
uwetews 3d7a1d57dc update strip test 2015-12-09 01:31:15 +01:00
uwetews cee9d19fba Update test for 3.1.28 master 2015-10-24 04:12:28 +02:00
uwetews e4ed69f174 fix test 2015-10-20 01:28:39 +02:00
uwetews 4c24ec6e20 split tests because of hhvm 2015-10-20 01:21:37 +02:00
uwetews 03daa2880c run all test in separate process 2015-10-20 00:50:22 +02:00
uwetews 3975172178 config change 2015-10-18 20:53:31 +02:00
uwetews d44e283eb7 add dummy 2015-10-18 20:43:38 +02:00
uwetews dde9a906b0 add dummies 2015-10-18 20:33:53 +02:00
uwetews 749eaad939 run some tests in separate process for HHVM compatibillity 2015-10-18 20:23:49 +02:00
uwetews 75663948f2 move configuration constants in PHP file that they are seen also in isolated tests 2015-10-18 20:22:11 +02:00
uwetews 48676467ce no log file 2015-10-18 07:21:06 +02:00
uwetews 48b7147869 some test must run in separate process under because of HHVM 2015-10-18 05:41:46 +02:00
uwetews 538ffd3af2 Update forr 3.1.28 2015-10-18 03:33:17 +02:00
uwetews 60f73dfcb7 Extend tests 2015-09-01 02:47:13 +02:00
uwetews d5c9859241 Update tests 2015-08-29 14:23:14 +02:00
uwetews 4645b78e8b add dummy files to keep folder in reprository 2015-08-23 18:32:10 +02:00
uwetews 5c416f2f0f Update for 3.1.28 2015-08-23 15:04:21 +02:00
Uwe Tews 75adb86450 fix timestamp 2015-08-06 21:11:41 +02:00
Uwe Tews 1a5654040f fix exception results 2015-08-02 21:02:56 +02:00
Uwe Tews 621d99643c remove check of uid from exception result 2015-08-01 14:10:37 +02:00
Uwe Tews b829b94df8 Update 2015-07-30 02:02:53 +02:00
Uwe Tews a6f6f6fd6d update 2015-07-30 01:50:45 +02:00
Uwe Tews 5f0c8fd58a disable test7 2015-07-30 00:00:56 +02:00
Uwe Tews cf2b0c8aed Update section tests 2015-07-29 23:28:57 +02:00
Uwe Tews 63b3f4c522 remove PHP_ALLOW test for <script language='php'> for PHP 7 as it is not supported 2015-07-28 01:47:08 +02:00
Uwe Tews b4dc05df12 remove PHP_ALLOW test for <script language='php'> for PHP 7 as it is not supported 2015-07-28 01:35:24 +02:00
Uwe Tews 84dbaa901b Fix tests for HHVM 2015-07-28 00:50:27 +02:00
Uwe Tews b1ffb59c3c Update 2015-07-07 18:35:49 +02:00
Uwe Tews 62d0c170a0 Update file resource tests 2015-07-07 17:11:05 +02:00
Uwe Tews a0f18578e2 Update file resource tests 2015-07-07 00:49:20 +02:00
Uwe Tews cb70b219ad update $source->getContent() 2015-07-01 16:57:50 +02:00
Uwe Tews 5f8f92d75b Update 2015-07-01 03:13:32 +02:00
Uwe Tews 441ac8e100 Add closure test 2015-06-19 03:00:20 +02:00
Uwe Tews 9400c6307f Delete 2015-06-18 03:26:46 +02:00
Uwe Tews 77abff1e53 normalize path 2015-06-18 03:07:19 +02:00
Uwe Tews cbeede4f8c update 2015-06-18 02:04:13 +02:00
Uwe Tews c34c178053 check plugin loading 2015-06-18 01:45:13 +02:00
Uwe Tews e5b3da5b38 Update path normalization 2015-06-18 00:17:57 +02:00
Uwe Tews c1d6ae68f4 Test simplw plugin nocache 2015-06-17 20:59:56 +02:00
Uwe Tews 609ae0d708 Update for 3.1.25 2015-06-14 02:56:18 +02:00
Uwe Tews 1500b2e655 update for <?xml tags including template variables 2015-06-01 22:14:41 +02:00
Uwe Tews b55f4cf551 New PHP tests 2015-05-23 18:53:25 +02:00
Uwe Tews 66f127cab1 New PHP tests 2015-05-23 18:49:46 +02:00
Uwe Tews cb31ef2df1 New PHP tests 2015-05-23 18:49:27 +02:00
Uwe Tews e3c82a8f06 Test long comment 2015-05-23 18:48:27 +02:00
Uwe Tews 15abaf4842 Test long comment 2015-05-23 18:48:04 +02:00
Uwe Tews 5bb2c5c26f Update bootstrap 2015-05-21 00:53:04 +02:00
Uwe Tews 47b6fab3d9 fix result 2015-05-20 05:05:28 +02:00
Uwe Tews 2614b1aacb fix true 2015-05-18 08:11:50 +02:00
Uwe Tews 37d327ce12 Update 2015-05-18 05:36:37 +02:00
Uwe Tews 9cd0734f70 Modified Php tag tests to multiple php lines. 2015-05-16 14:57:14 +02:00
Uwe Tews f6b369263e Modified Php tag tests to multiple php lines. 2015-05-16 14:48:38 +02:00
Uwe Tews e1a34fbc87 added recursive template function tests 2015-05-14 15:03:55 +02:00
Uwe Tews 59de25809e added recursive template function tests 2015-05-14 15:02:52 +02:00
Uwe Tews 5bef25a262 Added unit test for issue 28 and 29 2015-05-12 20:44:52 +02:00
Uwe Tews 4a09745c41 Update for Linux results 2015-05-12 03:50:24 +02:00
Uwe Tews eed5b1ddf3 add lockfile for phpunit 2015-05-12 02:36:43 +02:00
Uwe Tews 78e0072c15 Delete 2015-05-10 23:05:55 +02:00
Uwe Tews a451662760 update 2015-05-10 22:59:33 +02:00
Uwe Tews 8d75f927aa add travis.yml 2015-05-10 22:57:17 +02:00
Uwe Tews 79f1d70d97 added tests for cache locking 2015-05-10 12:52:00 +02:00
Uwe Tews 41c4c598af add tests for cache locking 2015-05-06 22:54:41 +02:00
Uwe Tews ce756af4ca Update tests 2015-05-05 23:45:28 +02:00
Uwe Tews bca7eaeba5 test 2015-05-05 04:18:56 +02:00
Uwe Tews a97f68068d test 2015-05-05 04:15:20 +02:00
Uwe Tews 6fa1f3c6a4 test 2015-05-05 04:13:18 +02:00
Uwe Tews 0a1d2c20c7 test 2015-05-05 04:11:44 +02:00
Uwe Tews e9b9ba2d40 test 2015-05-05 04:03:41 +02:00
Uwe Tews 619c1d2830 try to catch excluded files right 2015-05-05 01:06:43 +02:00
Uwe Tews ef317b50ae try to catch excluded files right 2015-05-05 01:05:27 +02:00
Uwe Tews 81aae13e55 Smarty 3.1.22 code change
- improvement use is_file() checks to avoid errors suppressed by @ which could still cause problems (https://github.com/smarty-php/smarty/issues/24)
2015-05-05 01:03:12 +02:00
Uwe Tews 8056c27602 3.1.21 2015-05-04 04:08:56 +02:00
Uwe Tews cf11a8a4b9 3.1.20 2015-05-04 04:06:29 +02:00
Uwe Tews 69b2f86d91 3.1.20 2015-05-04 04:03:09 +02:00
Uwe Tews 26146a67a6 3.1.19 2015-05-04 04:01:13 +02:00
Uwe Tews 0566d8a657 3.1.18 2015-05-04 03:58:51 +02:00
Uwe Tews 94545f2d4e 3.1.17 2015-05-04 03:56:51 +02:00
Uwe Tews 4cc66c650a 3.1.16 2015-05-04 03:54:54 +02:00
Uwe Tews 819b852809 3.1.15 2015-05-04 03:52:20 +02:00
Uwe Tews d3e78d81bc 3.1.14 2015-05-04 03:12:52 +02:00
Uwe Tews 7ad54c9887 3.1.13 2015-05-04 03:10:52 +02:00
Uwe Tews fe8598515f 3.1.12 2015-05-04 03:07:10 +02:00
Uwe Tews 0dea9f271c 3.1.11 2015-05-04 03:00:52 +02:00
Uwe Tews 1834622d94 Revert "3.1.11"
This reverts commit d3af847798ed757770a5a0d336fa04780a7ec2cd.
2015-05-04 02:23:23 +02:00
Uwe Tews 429229d6b6 3.1.11 2015-05-04 02:22:20 +02:00
Uwe Tews 5feb5b44dd Update 2015-05-04 02:21:34 +02:00
Uwe Tews 27addcf628 init 2015-05-04 02:17:48 +02:00
uwetews 6eedb590e1 Initial commit 2015-05-04 02:14:20 +02:00
875 changed files with 26924 additions and 6 deletions
-1
View File
@@ -11,4 +11,3 @@ utilies/*.php
phpunit*
vendor/*
composer.lock
templates_c/*
+2 -5
View File
@@ -11,11 +11,10 @@ matrix:
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4snapshot
- php: 7.4
- php: nightly
fast_finish: true
allow_failures:
- php: 7.4snapshot
- php: nightly
services:
@@ -30,8 +29,6 @@ before_install:
install:
- travis_retry composer install
- git clone --depth=50 --branch=master git://github.com/smarty-php/smarty-phpunit.git
script:
- cd smarty-phpunit
- ../vendor/bin/phpunit ./
- ./phpunit.sh
+69
View File
@@ -0,0 +1,69 @@
# Todo
## Add unit test for strip issue in correct branch
tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php
```
@@ -76,6 +76,7 @@ class CompileStripTest extends PHPUnit_Smarty
array("{'Var'}\n <b></b> <c></c>", 'Var<b></b> <c></c>', '', $i ++),
array("\n<b></b> <c></c>", '<b></b> <c></c>', '', $i ++),
array("\n<b></b>\n <c></c>", '<b></b><c></c>', '', $i ++),
+ array("\n<b>\n {* a comment *}\n <c>", '<b><c>', '', $i ++),
);
}
```
## Add unit test for isset issue in correct branch
tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php
```php
/**
* test PHP isset() on (non-)variables
* @dataProvider dataTestIsset3
* @param string $strTemplate template to test
* @param string $result expected result
*/
public function testIsset3($strTemplate, $result)
{
$this->smarty->disableSecurity();
$this->smarty->assign('varobject', new TestIsset());
$this->smarty->assign('vararray', $vararray = [
'keythatexists' => false,
'keywitharray' => [1 => 1],
'keywithobject' => new TestIsset()]
);
$this->smarty->assign('key', 'A');
$this->smarty->assign('_varsimpleA', 1);
$this->smarty->assign('varsimpleB', 0);
$this->smarty->assign('varsimpleC', null);
$this->assertEquals($result, $this->smarty->fetch('string:' . $strTemplate));
}
/**
* Data provider for testIsset3
*/
public function dataTestIsset3()
{
return array(
array('{if isset($varobject->arr)}true{else}false{/if}', 'true'),
array('{if isset($vararray["keywitharray"])}true{else}false{/if}', 'true'),
array('{if isset($vararray["keythatexists"])}true{else}false{/if}', 'true'),
array('{if isset($vararray["nonexistingkey"])}true{else}false{/if}', 'false'),
array('{if isset($_GET["sscr6hr6cz34j6"])}true{else}false{/if}', 'false'),
array('{if isset(count([\'hi\']))}true{else}false{/if}', 'true'),
array('{if isset($vararray[\'keywitharray\'][intval(\'1\')])}true{else}false{/if}', 'true'),
array('{if isset($vararray[\'keywithobject\']->arr[\'isSet\'])}true{else}false{/if}', 'true'),
array('{if isset($vararray[\'keywithobject\']->arr[\'isNull\'])}true{else}false{/if}', 'false'),
array('{if isset($varobject->arr[\'isSet\'])}true{else}false{/if}', 'true'),
array('{if isset($varobject->arr[\'isNull\'])}true{else}false{/if}', 'false'),
array('{if isset($_varsimpleA)}true{else}false{/if}', 'true'),
array('{if isset($varsimpleB)}true{else}false{/if}', 'true'),
array('{if isset($varsimpleC)}true{else}false{/if}', 'false'),
array('{if isset($_varsimpleA && varsimpleB)}true{else}false{/if}', 'true'),
array('{if isset($_varsimpleA && varsimpleC)}true{else}false{/if}', 'true'),
array('{if isset($_varsimple{$key})}true{else}false{/if}', 'true'),
);
}
```
Executable
+2
View File
@@ -0,0 +1,2 @@
#! /bin/bash
vendor/phpunit/phpunit/phpunit tests/UnitTests
+43
View File
@@ -0,0 +1,43 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
bootstrap="tests/Bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticAttributes="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="false">
<filter>
<testsuites>
<testsuite name="Smarty Test Suite">
<directory>tests/UnitTests</directory>
</testsuite>
</testsuites>
<blacklist>
<directory suffix=".php">tests</directory>
<directory suffix=".php">tests/cache</directory>
<directory suffix=".php">tests/templates_c</directory>
</blacklist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">libs</directory>
<directory suffix=".php">libs/plugins</directory>
<directory suffix=".php">libs/sysplugins</directory>
<directory suffix=".php">demo/plugins</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="tests/TestResults.tap"/>
</logging>
</phpunit>
+11
View File
@@ -0,0 +1,11 @@
.idea
# Unit test / coverage reports
.coverage
.tox
#Smarty
testdox.html
TestResults.tap
TestResults.txt
+28
View File
@@ -0,0 +1,28 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*
*/
/*
* Smarty PHPUnit Bootstrap
*/
require_once dirname(__FILE__) . '/Config.php';
require_once dirname(__FILE__) . '/../vendor/autoload.php';
require_once dirname(__FILE__) . '/../libs/bootstrap.php';
if (!class_exists('\PHPUnit_Framework_TestCase') && class_exists('\PHPUnit\Framework\TestCase')) {
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
class_alias('\PHPUnit\Framework\Error\Notice', '\PHPUnit_Framework_Error_Notice');
class_alias('\PHPUnit\Framework\Error\Error', '\PHPUnit_Framework_Error_Error');
class_alias('\PHPUnit\Framework\Error\Warning', '\PHPUnit_Framework_Error_Warning');
class_alias('\PHPUnit\Framework\Error\Warning', '\PHPUnit_Framework_Error_Deprecated');
class_alias('\PHPUnit\Util\Configuration', '\PHPUnit_Util_Configuration');
}
require_once 'PHPUnit_Smarty.php';
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'Europe/Berlin');
}
+18
View File
@@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*
*/
/*
* Smarty PHPUnit Config
*/
define('individualFolders', true);
define('MemCacheEnable', false);
define('ApcCacheEnable', false);
define('MysqlCacheEnable', false);
define('PdoCacheEnable', false);
define('PdoGzipCacheEnable', false);
define('MysqlResourceEnable', false);
define('DB_DSN', "mysql:dbname=test;host=localhost");
define('DB_USER', "travis");
define('DB_PASSWD', "");
@@ -0,0 +1,5 @@
<?php
function smarty_function_plugin1($params, $template)
{
return 'plugin1';
}
@@ -0,0 +1,5 @@
<?php
function smarty_function_plugin2($params, $template)
{
return 'plugin2';
}
@@ -0,0 +1 @@
include_test2
@@ -0,0 +1 @@
include_test4
@@ -0,0 +1 @@
{include 'include_test4.tpl'}
+1
View File
@@ -0,0 +1 @@
include path root
+699
View File
@@ -0,0 +1,699 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*
*/
/**
* Smarty Test Case Fixture
*/
class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
{
/**
* Smarty object
*
* @var SmartyBC
*/
public $smartyBC = null;
/**
* SmartyBC object
*
* @var Smarty
*/
public $smarty = null;
/**
* Flag if test is using the Smarty object
*
* @var bool
*/
public $loadSmarty = true;
/**
* Flag if test is using the SmartyBC object
*
* @var bool
*/
public $loadSmartyBC = false;
/**
* Flag for initialization at first test
*
* @var bool
*/
public static $init = true;
/**
* Count test number
*
* @var bool
*/
public static $testNumber = 0;
/**
* Configuration data from config.xml
*
* @var array
*/
public static $config = null;
/**
* Saved current working directory
*
* @var null
*/
public static $cwd = null;
/**
* PDO object for Mysql tests
*
* @var PDO
*/
public static $pdo = null;
public static $pluginsdir = null;
/**
* Default blacklist
*
* @var array
*/
protected $backupStaticAttributesBlacklist = array('PHPUnit_Smarty' => array('config', 'pdo', 'init',
'testNumver', 'pluginsdir'),);
/**
* This method is called before the first test of this test class is run.
*
*/
public static function setUpBeforeClass()
{
error_reporting(E_ALL & ~E_STRICT);
self::$init = true;
self::$pluginsdir =self::getSmartyPluginsDir();
}
/**
* This method is called after the last test of this test class is run.
*
*/
public static function tearDownAfterClass()
{
//self::$pdo = null;
self::$testNumber = 0;
}
/**
* Constructs a test case with the given name.
*
* @param string $name
* @param array $data
* @param string $dataName
*/
public function __construct($name = null, array $data = array(), $dataName = '')
{
date_default_timezone_set('Europe/Berlin');
if (!defined('individualFolders')) {
define('individualFolders', true);
}
parent::__construct($name, $data, $dataName);
$this->backupStaticAttributesBlacklist[ get_class($this) ] = array('init', 'config', 'pdo', 'testNumber');
}
/**
* Setup Smarty instance called for each test
*
* @param null $dir working directory
*/
public function setUpSmarty($dir = null)
{
static $s_dir;
// set up current working directory
chdir($dir);
self::$cwd = getcwd();
// create missing folders for test
if (self::$init) {
if (!is_dir($dir . '/templates')) {
mkdir($dir . '/templates');
}
if (!is_dir($dir . '/configs')) {
mkdir($dir . '/configs');
}
if (individualFolders != 'true') {
if (!isset($s_dir[ $dir ])) {
$this->cleanDir($dir . '/templates_c');
$this->cleanDir($dir . '/cache');
if (is_dir($dir . '/templates_tmp')) {
$this->cleanDir($dir . '/templates_tmp');
}
$s_dir[ $dir ] = true;
}
$dir = dirname(__FILE__);
}
if (!is_dir($dir . '/templates_c')) {
mkdir($dir . '/templates_c');
}
chmod($dir . '/templates_c', 0775);
if (!is_dir($dir . '/cache')) {
mkdir($dir . '/cache');
chmod($dir . '/cache', 0775);
}
self::$init = false;
}
clearstatcache();
// instance Smarty class
if ($this->loadSmarty) {
$this->smarty = new Smarty;
if (individualFolders != 'true') {
$this->smarty->setCompileDir(dirname(__FILE__) . '/templates_c');
$this->smarty->setCacheDir(dirname(__FILE__) . '/cache');
}
}
// instance SmartyBC class
if ($this->loadSmartyBC) {
$this->smartyBC = new SmartyBC;
if (individualFolders != 'true') {
$this->smartyBC->setCompileDir(dirname(__FILE__) . '/templates_c');
$this->smartyBC->setCacheDir(dirname(__FILE__) . '/cache');
}
}
$smarty = $this->getSmartyObj();
}
/**
* Create Mysql PDO object
*
*/
final public function getConnection()
{
if (PHPUnit_Smarty::$pdo == null) {
try {
PHPUnit_Smarty::$pdo = new PDO(DB_DSN, DB_USER, DB_PASSWD);
}
catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
}
$timezone = date_default_timezone_get();
$j = PHPUnit_Smarty::$pdo->exec("SET time_zone = '{$timezone}';");
}
}
/**
* Create table for Mysql resource
*
*/
public function initMysqlResource()
{
$this->getConnection();
PHPUnit_Smarty::$pdo->exec("DROP TABLE `templates`");
PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `templates` (
`name` varchar(100) NOT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`source` text,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
}
/**
* Create table for Mysql cache resource
*
*/
public function initMysqlCache()
{
$this->getConnection();
PHPUnit_Smarty::$pdo->exec("DROP TABLE `output_cache`");
PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` (
`name` varchar(256) NOT NULL,
`id` char(40) NOT NULL,
`cache_id` varchar(250) DEFAULT NULL,
`compile_id` varchar(250) DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`content` mediumblob NOT NULL,
PRIMARY KEY (`id`),
KEY `cache_id` (`cache_id`),
KEY `compile_id` (`compile_id`),
KEY `modified` (`modified`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
// PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` (
//`id` char(40) NOT NULL,
//`name` varchar(250) NOT NULL,
//`cache_id` varchar(250) DEFAULT NULL,
//`compile_id` varchar(250) DEFAULT NULL,
//`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
//`expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
//`content` mediumblob NOT NULL,
///PRIMARY KEY (`id`),
//KEY `name` (`name`),
//KEY `cache_id` (`cache_id`),
//KEY `compile_id` (`compile_id`),
//KEY `modified` (`modified`),
//KEY `expire` (`expire`)
//) ENGINE=InnoDB DEFAULT CHARSET=utf8");
}
/**
* Delete files in templates_c and cache folders
*
*/
public function cleanDirs()
{
$this->cleanCompileDir();
$this->cleanCacheDir();
if (is_dir(self::$cwd . '/templates_tmp')) {
$this->cleanDir(self::$cwd . '/templates_tmp');
}
$this->assertTrue(true);
}
/**
* Make temporary template file
*
*/
public function makeTemplateFile($name, $code)
{
if (!is_dir(self::$cwd . '/templates_tmp')) {
mkdir(self::$cwd . '/templates_tmp');
chmod(self::$cwd . '/templates_tmp', 0775);
}
$fileName = self::$cwd . '/templates_tmp/' . "{$name}";
file_put_contents($fileName, $code);
}
/**
* Delete files in templates_c folder
*
*/
public function cleanCompileDir()
{
$smarty = $this->getSmartyObj();
if (isset($smarty)) {
$dir = $smarty->getCompileDir();
$this->cleanDir($dir);
}
}
/**
* Delete files in cache folder
*
*/
public function cleanCacheDir()
{
$smarty = $this->getSmartyObj();
if (isset($smarty)) {
$dir = $smarty->getCacheDir();
$this->cleanDir($dir);
}
}
/**
* Delete files and sub folders
*
* @param string $dir
*/
public function cleanDir($dir)
{
$di = new RecursiveDirectoryIterator($dir);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($ri as $file) {
if (substr(basename($file->getPathname()), 0, 1) === '.' || substr((string)$file,-4) === '.txt') {
continue;
}
// directory ?
if ($file->isDir()) {
if (!$ri->isDot()) {
// delete folder if empty
@rmdir($file->getPathname());
}
} else {
unlink($file->getPathname());
}
}
}
/**
* Get PDO object
*
* @return null|PDO
*/
final public function getPDO()
{
return PHPUnit_Smarty::$pdo;
}
/**
* Remove "\r" and replace "\t" with spaces
*
* @param string $in
*
* @return mixed
*/
public function normalizeString($in)
{
if (is_string($in)) {
return str_replace(array("\r", "\t"), array('', ' '), $in);
} else {
return $in;
}
}
/**
* Remove all spaces
*
* @param string $in
*
* @return mixed
*/
public function strip($in)
{
if (is_string($in)) {
return preg_replace('/\s/', '', $in);
} else {
return $in;
}
}
/**
* Return source path
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
*
* @return string
* @throws \Exception
*/
public function buildSourcePath($tpl, $name = null, $type = null, $dir = null)
{
$name = isset($name) ? $name : $tpl->source->name;
$type = isset($type) ? $type : $tpl->source->type;
$dir = isset($dir) ? $dir : $this->smarty->getTemplateDir(0);
switch ($type) {
case 'file':
case 'filetest':
case 'php':
return $this->normalizePath($dir . $name);
case 'mysqltest':
case 'mysql':
return sha1($type . ':' . $name);
case 'string':
$this->smarty->getTemplateDir();
return sha1($name . $this->smarty->_joined_template_dir);
default:
throw new Exception("Unhandled source resource type '{$type}'");
}
}
/**
* Build template uid
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param null|string $value
* @param null|string $name optional template name
* @param null|string $type optional template type
*
* @return string
* @throws \Exception
*/
public function buildUid($tpl, $value = null, $name = null, $type = null)
{
$type = isset($type) ? $type : $tpl->source->type;
$name = isset($name) ? $name : $tpl->source->name;
switch ($type) {
case 'php':
case 'file':
case 'filetest':
if ($tpl instanceof Smarty) {
return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name) .
$this->smarty->_joined_template_dir);
}
return sha1($tpl->source->filepath . $this->smarty->_joined_template_dir);
case 'mysqltest':
case 'mysql':
return sha1($type . ':' . $name);
case 'string':
$this->smarty->getTemplateDir();
return sha1($name . $this->smarty->_joined_template_dir);
default:
throw new Exception("Unhandled source resource type '{$type}'");
}
}
/**
* Normalize path
* - remove /./ and /../
* - make it absolute
*
* @param string $path file path
*
* @return string
*/
public function normalizePath($path, $ds =null ,$absolute = true)
{
$ds = isset($ds) ? $ds : DIRECTORY_SEPARATOR;
$nds = $ds == '/' ? '\\' : '/';
$getcwd = getcwd();
// normalize $ds
$path = str_replace($nds, $ds, $path);
preg_match('#^([a-zA-Z][:])?([.]{1,2}[\/\\\]+)?([\\\])?([.]{0,2}[\/\\\]+)?([[:print:]]*)#', $path, $match);
if ($match[1] === '') {
if ($match[ 2 ] !== '' || $match[ 2 ] . $match[ 3 ] . $match[ 4 ] === '') {
$path = $getcwd . $ds . $path;
} else if (Smarty::$_IS_WINDOWS && $match[ 3 ] !== '') {
$path = substr($getcwd, 0, 2) . $path;
}
}
$path = preg_replace('#[\\\/]+([.][\\\/]+)*#', $ds, $path);
while (strrpos($path, '.' . $ds) !== false) {
$path =
preg_replace('#([\\\/]([^\\\/]+[\\\/]){2}([.][.][\\\/]){2})|([\\\/][^\\\/]+[\\\/][.][.][\\\/])#', $ds,
$path);
}
$cwd = preg_replace('#[\\\/]#', $ds, $getcwd);
$path = str_ireplace($cwd,$getcwd, $path);
if (!$absolute) {
$path = preg_replace('#'.$getcwd.'#', '', $path);
}
return $path;
}
/**
* Return base name
*
* @param \Smarty_Internal_Template|\Smarty_Internal_TemplateBase $tpl template object
* @param null|string $name optional template name
* @param null|string $type optional template type
*
* @return null|string
*/
public function getBasename(Smarty_Internal_Template $tpl, $name = null, $type = null)
{
$name = isset($name) ? $name : $tpl->source->name;
$type = isset($type) ? $type : $tpl->source->type;
switch ($type) {
case 'file':
case 'filetest':
if (($_pos = strpos($name, ']')) !== false) {
$name = substr($name, $_pos + 1);
}
return basename($name);
case 'mysqltest':
case 'mysql':
return $name;
case 'string':
return '';
default:
return null;
}
}
/**
* Return compiled file path
*
* @param \Smarty_Internal_Template|\Smarty_Internal_TemplateBase $tpl template object
* @param bool $sub use sub directory flag
* @param bool $caching caching flag
* @param null|string $compile_id optional compile id
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
*
* @return string
* @throws \Exception
*/
public function buildCompiledPath(Smarty_Internal_Template $tpl, $sub = true, $caching = false, $compile_id = null,
$name = null, $type = null, $dir = null)
{
$sep = DIRECTORY_SEPARATOR;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_flag = '';
if (isset($tpl->source) && $tpl->source->isConfig) {
$_flag = '_' . ((int) $tpl->smarty->config_read_hidden + (int) $tpl->smarty->config_booleanize * 2 +
(int) $tpl->smarty->config_overwrite * 4);
} else {
$_flag = '_' . ((int) $tpl->smarty->merge_compiled_includes + (int) $tpl->smarty->escape_html * 2);
}
$_filepath = $uid . $_flag;
// if use_sub_dirs, break file into directories
if ($sub) {
$_filepath =
substr($_filepath, 0, 2) . $sep . substr($_filepath, 2, 2) . $sep . substr($_filepath, 4, 2) . $sep .
$_filepath;
}
$_compile_dir_sep = $sub ? $sep : '^';
if (isset($_compile_id)) {
$_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
}
// caching token
if ($caching) {
$_cache = '.cache';
} else {
$_cache = '';
}
$_compile_dir = $tpl->smarty->getCompileDir();
// set basename if not specified
$_basename = $this->getBasename($tpl, $name, $type);
if ($_basename === null) {
$_basename = basename(preg_replace('![^\w\/]+!', '_', $name));
}
// separate (optional) basename by dot
if ($_basename) {
$_basename = '.' . $_basename;
}
return $_compile_dir . $_filepath . '.' . $type . $_basename . $_cache . '.php';
}
/**
* Return cache file path
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param bool $sub use sub directory flag
* @param null|string $cache_id optional cache id
* @param null|string $compile_id optional compile id
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
* @param null|string $cacheType optional cache resource type
*
* @return string
* @throws \Exception
*/
public function buildCachedPath($tpl, $sub = true, $cache_id = null, $compile_id = null, $name = null, $type = null,
$dir = null, $cacheType = null)
{
$cacheType = isset($cacheType) ? $cacheType : $tpl->smarty->caching_type;
switch ($cacheType) {
case 'file':
case 'filetest':
$sep = DIRECTORY_SEPARATOR;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_filepath = sha1($uid . $this->smarty->_joined_template_dir);
// if use_sub_dirs, break file into directories
if ($sub) {
$_filepath =
substr($_filepath, 0, 2) . $sep . substr($_filepath, 2, 2) . $sep . substr($_filepath, 4, 2) .
$sep . $_filepath;
}
$_compile_dir_sep = $sub ? $sep : '^';
if (isset($_cache_id)) {
$_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
} else {
$_cache_id = '';
}
if (isset($_compile_id)) {
$_compile_id = $_compile_id . $_compile_dir_sep;
} else {
$_compile_id = '';
}
$smarty = isset($tpl->smarty) ? $tpl->smarty : $tpl;
$_cache_dir = $smarty->getCacheDir();
return $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($sp) . '.php';
case 'mysql':
case 'mysqltest':
case 'pdo':
case 'foobar':
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
return sha1($uid . $_cache_id . $_compile_id);
case 'memcachetest':
case 'acp':
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
return sha1($uid) . '#' . preg_replace('#[^\w\|]+#S', '_', $tpl->template_resource) . '#' . $_cache_id .
'#' . $_compile_id;
default:
throw new Exception("Unhandled cache resource type '{$cacheType}'");
}
}
/**
* prefilter to insert test number
*
* @param string $source
* @param \Smarty_Internal_Template $tpl
*
* @return string
*/
public function prefilterTest($source, Smarty_Internal_Template $tpl)
{
return str_replace('#test#', "test:{\$test nocache} compiled:{$tpl->getTemplateVars('test')} rendered:{\$test}",
$source);
}
/**
* Gat Smarty object
* @return null|\Smarty|\SmartyBC
*/
public function getSmartyObj(){
return isset($this->smarty) ? $this->smarty : (isset($this->smartyBC) ? $this->smartyBC : null);
}
public static function getSmartyPluginsDir(){
if (is_dir(dirname(__FILE__) . '/../smarty/libs/plugins')) {
return dirname(__FILE__) . '/../smarty/libs/plugins';
} else if(is_dir(dirname(__FILE__) . '/../libs/plugins')) {
return dirname(__FILE__) . '/../libs/plugins';
}
}
/**
* Tears down the fixture
* This method is called after a test is executed.
*
*/
protected function tearDown()
{
if (class_exists('Smarty_Internal_TemplateCompilerBase') &&
isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects)
) {
Smarty_Internal_TemplateCompilerBase::$_tag_objects = array();
}
if (isset($this->smarty->smarty)) {
$this->smarty->smarty = null;
}
if (isset($this->smarty)) {
$this->smarty = null;
}
if (isset($this->smartyBC->smarty)) {
$this->smartyBC->smarty = null;
}
if (isset($this->smartyBC)) {
$this->smartyBC = null;
}
}
}
@@ -0,0 +1,78 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*/
/**
* class for path normalization tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class PathNormalizationTest extends PHPUnit_Smarty
{
/*
* Setup test fixture
*/
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testNormalizeToAbsolute() {
$d = $this->smarty->_realpath('./foo/a.foo', true);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
/**public function testNormalizeAbsolute() {
if (DIRECTORY_SEPARATOR == '/') {
$d = $this->smarty->_realpath('\\foo\\a.foo', true);
$this->assertEquals('/foo/a.foo', $d);
} else {
$d = $this->smarty->_realpath('/foo/a.foo', true);
$this->assertEquals(substr(getcwd(), 0, 2) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
$d = $this->smarty->_realpath(substr(getcwd(), 0, 2) . '/foo/a.foo', true);
$this->assertEquals(substr(getcwd(), 0, 2) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
}
* */
public function testNormalizeToAbsoluteNoStart() {
$d = $this->smarty->_realpath('foo/a.foo', true);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
public function testNormalizeToAbsoluteNoStart2() {
$d = $this->smarty->_realpath('a.foo', true);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
public function testNormalizeToAbsolutePathLeadingDot() {
$d = $this->smarty->_realpath('.foo/a.foo', true);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . '.foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
public function testNormalizeToAbsolutePathTrailingDot() {
$d = $this->smarty->_realpath('./foo./a.foo', true);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo.' . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
public function testNormalizeToAbsolutePathBubbleUp() {
$ds = '\\' . DIRECTORY_SEPARATOR;
$prefix = preg_replace("#[{$ds}][^{$ds}]+$#", '', getcwd());
$d = $this->smarty->_realpath('./../a.foo', true);
$this->assertEquals($prefix . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
public function testNormalizeToAbsolutePathBubbleUp2() {
$ds = '\\' . DIRECTORY_SEPARATOR;
$prefix = preg_replace("#[{$ds}][^{$ds}]+$#", '', getcwd());
$d = $this->smarty->_realpath('././../././a.foo', true);
$this->assertEquals($prefix . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
public function testNormalizeToAbsolutePathBubbleUp3() {
$ds = '\\' . DIRECTORY_SEPARATOR;
$prefix = preg_replace("#[{$ds}][^{$ds}]+[{$ds}][^{$ds}]+$#", '', getcwd());
$d = $this->smarty->_realpath('././.././.././a.foo', true);
$this->assertEquals($prefix . DIRECTORY_SEPARATOR . 'a.foo', $d);
}
public function testNormalizeToAbsoluteKomplex() {
$d = $this->smarty->_realpath('./foo/\\./bar/jo/wie/so/../..///.././././../aa/bb/cc/../../go/a.foo', true);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'aa'. DIRECTORY_SEPARATOR . 'go' . DIRECTORY_SEPARATOR .'a.foo', $d);
}
}
@@ -0,0 +1,145 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*/
/**
* class for path normalization tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class PluginNormalizationTest extends PHPUnit_Smarty
{
/*
* Setup test fixture
*/
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testGetPluginsDefaultDir()
{
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->assertEquals(SMARTY_PLUGINS_DIR, $result[ 0 ]);
}
public function testGetPluginsDefaultDir2()
{
$this->smarty->addPluginsDir('./foo/');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(2, count($result));
$this->assertEquals(SMARTY_PLUGINS_DIR, $result[ 0 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 1 ]);
}
public function testSetPluginsDir1()
{
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->smarty->setPluginsDir('foo');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetPluginsDir2()
{
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->smarty->setPluginsDir('foo/');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetPluginsDir3()
{
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->smarty->setPluginsDir('foo/.');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetPluginsDir4()
{
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->smarty->setPluginsDir('foo/./');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetPluginsDir5()
{
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->smarty->setPluginsDir('.foo');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . '.foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetPluginsDir6()
{
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->smarty->setPluginsDir('..foo');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . '..foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetPluginsDir7()
{
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->smarty->setPluginsDir('../foo');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(1, count($result));
$this->assertEquals(substr(getcwd(), 0, - strlen(basename(getcwd()))) . 'foo' . DIRECTORY_SEPARATOR,
$result[ 0 ]);
}
public function testSetPluginsDir8()
{
$this->smarty->setPluginsDir(array('foo', 'bah'));
$result = $this->smarty->getPluginsDir();
$this->assertEquals(2, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]);
}
public function testSetPluginsDir9()
{
$this->smarty->setPluginsDir(array('foo', 'bah'));
$result = $this->smarty->getPluginsDir();
$this->assertEquals(2, count($result));
$this->smarty->addPluginsDir('blar');
$result = $this->smarty->getPluginsDir();
$this->assertEquals(3, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'blar' . DIRECTORY_SEPARATOR, $result[ 2 ]);
}
public function testSetPluginsDir10()
{
$this->smarty->setPluginsDir(array('foo', 'bah'));
$result = $this->smarty->getPluginsDir();
$this->assertEquals(2, count($result));
$this->smarty->addPluginsDir(array('blar', 'smarty'));
$result = $this->smarty->getPluginsDir();
$this->assertEquals(4, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'blar' . DIRECTORY_SEPARATOR, $result[ 2 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR, $result[ 3 ]);
}
}
@@ -0,0 +1,137 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*/
/**
* class for path normalization tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class TemplateNormalizationTest extends PHPUnit_Smarty
{
/*
* Setup test fixture
*/
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testGetTemplateDir()
{
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetTemplateDir1()
{
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->smarty->setTemplateDir('foo');
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetTemplateDir2()
{
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->smarty->setTemplateDir('foo/');
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetTemplateDir3()
{
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->smarty->setTemplateDir('foo/.');
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetTemplateDir4()
{
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->smarty->setTemplateDir('foo/./');
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetTemplateDir5()
{
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->smarty->setTemplateDir('.foo');
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . '.foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetTemplateDir6()
{
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->smarty->setTemplateDir('..foo');
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . '..foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
}
public function testSetTemplateDir7()
{
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->smarty->setTemplateDir('../foo');
$result = $this->smarty->getTemplateDir();
$this->assertEquals(1, count($result));
$this->assertEquals(substr(getcwd(), 0, - strlen(basename(getcwd()))) . 'foo' . DIRECTORY_SEPARATOR,
$result[ 0 ]);
}
public function testSetTemplateDir8()
{
$this->smarty->setTemplateDir(array('foo', 'bah'));
$result = $this->smarty->getTemplateDir();
$this->assertEquals(2, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]);
}
public function testSetTemplateDir9()
{
$this->smarty->setTemplateDir(array('foo', 'bah'));
$result = $this->smarty->getTemplateDir();
$this->assertEquals(2, count($result));
$this->smarty->addTemplateDir('blar');
$result = $this->smarty->getTemplateDir();
$this->assertEquals(3, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'blar' . DIRECTORY_SEPARATOR, $result[ 2 ]);
}
public function testSetTemplateDir10()
{
$this->smarty->setTemplateDir(array('foo', 'bah'));
$result = $this->smarty->getTemplateDir();
$this->assertEquals(2, count($result));
$this->smarty->addTemplateDir(array('blar', 'smarty'));
$result = $this->smarty->getTemplateDir();
$this->assertEquals(4, count($result));
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'blar' . DIRECTORY_SEPARATOR, $result[ 2 ]);
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR, $result[ 3 ]);
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,226 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*/
/**
* class for protected $template_dir, $compile_dir, $cache_dir, $config_dir, $plugins_dir property tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class ProtectedFolderVarsTest extends PHPUnit_Smarty
{
/*
* Setup test fixture
*/
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
/*
* template_dir
*/
public function testTemplateDirDirectRelative()
{
$s = new Smarty();
$s->template_dir = './foo';
$d = $s->getTemplateDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
public function testTemplateDirDirectRelativeArray()
{
$s = new Smarty();
$s->template_dir = array('./foo', './bar/');
$d = $s->template_dir;
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]);
}
public function testTemplateDirDirectRelativeArrayAdd()
{
$s = new Smarty();
$s->template_dir = './foo';
$s->addTemplateDir('./bar/');
$d = $s->getTemplateDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]);
}
public function testTemplateDirDirectRelativeExtends()
{
$s = new FolderT();
$d = $s->getTemplateDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
public function testTemplateDirDirectRelativeExtends2()
{
$s = new FolderT();
$s->template_dir = './bar';
$d = $s->getTemplateDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
/*
* config_dir
*/
public function testConfigDirDirectRelative()
{
$s = new Smarty();
$s->config_dir = './foo';
$d = $s->getConfigDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
public function testConfigDirDirectRelativeArray()
{
$s = new Smarty();
$s->config_dir = array('./foo', './bar/');
$d = $s->config_dir;
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]);
}
public function testConfigDirDirectRelativeArrayAdd()
{
$s = new Smarty();
$s->config_dir = './foo';
$s->addConfigDir('./bar/');
$d = $s->getConfigDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]);
}
public function testConfigDirDirectRelativeExtends()
{
$s = new FolderT();
$d = $s->getConfigDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
public function testConfigDirDirectRelativeExtends2()
{
$s = new FolderT();
$s->config_dir = './bar';
$d = $s->getConfigDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
/*
* plugins_dir
*/
public function testPluginDirDirectRelative()
{
$s = new Smarty();
$s->plugins_dir = './foo';
$d = $s->getPluginsDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
public function testPluginDirDirectRelativeArray()
{
$s = new Smarty();
$s->plugins_dir = array('./foo', './bar/');
$d = $s->plugins_dir;
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]);
}
public function testPluginDirDirectRelativeArrayAdd()
{
$s = new Smarty();
$s->plugins_dir = './foo';
$s->addPluginsDir('./bar/');
$d = $s->getPluginsDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]);
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]);
}
public function testPluginDirDirectRelativeExtends()
{
$s = new FolderT();
$d = $s->getPluginsDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'plug' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
public function testPluginDirDirectRelativeExtends2()
{
$s = new FolderT();
$s->plugins_dir = './bar';
$d = $s->getPluginsDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 0 ]);
}
/*
* compile_dir
*/
public function testCompileDirDirectRelative()
{
$s = new Smarty();
$s->compile_dir = './foo';
$d = $s->getCompileDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d);
}
public function testCompileDirDirectRelativeExtends()
{
$s = new FolderT();
$d = $s->getCompileDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'comp' . DIRECTORY_SEPARATOR, $d);
}
public function testCompileDirDirectRelativeExtends2()
{
$s = new FolderT();
$s->compile_dir = './bar';
$d = $s->getCompileDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d);
}
/*
* cache_dir
*/
public function testCacheDirDirectRelative()
{
$s = new Smarty();
$s->cache_dir = './foo';
$d = $s->getCacheDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d);
}
public function testCacheDirDirectRelativeExtends()
{
$s = new FolderT();
$d = $s->getCacheDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR, $d);
}
public function testCacheDirDirectRelativeExtends2()
{
$s = new FolderT();
$s->cache_dir = './bar';
$d = $s->getCacheDir();
$this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d);
}
}
class FolderT extends Smarty
{
protected $template_dir = './foo';
protected $compile_dir = './comp/';
protected $plugins_dir = './plug/';
protected $cache_dir = './cache/';
protected $config_dir = array('./conf/');
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,74 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*/
/**
* class for protected $template_dir, $compile_dir, $cache_dir, $config_dir, $plugins_dir property tests
*
* @backupStaticAttributes enabled
*/
class UndefinedTemplateVarTest extends PHPUnit_Smarty
{
/*
* Setup test fixture
*/
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
error_reporting(E_ALL | E_STRICT);
}
public function testInit()
{
$this->cleanDirs();
}
/**
* Test E_NOTICE suppression template fetched by Smarty object
*/
public function testE_NoticeDisabled()
{
$e1 = error_reporting();
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
$this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl'));
$e2 = error_reporting();
$this->assertEquals($e1, $e2);
}
/**
* Test E_NOTICE suppression template fetched by template object
*/
public function testE_NoticeDisabledTplObject_1()
{
$e1 = error_reporting();
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
$tpl = $this->smarty->createTemplate('001_main.tpl');
$this->assertEquals('undefined = ', $tpl->fetch());
$e2 = error_reporting();
$this->assertEquals($e1, $e2);
}
public function testE_NoticeDisabledTplObject_2()
{
$e1 = error_reporting();
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
$tpl = $this->smarty->createTemplate('001_main.tpl');
$this->assertEquals('undefined = ', $this->smarty->fetch($tpl));
$e2 = error_reporting();
$this->assertEquals($e1, $e2);
}
/**
* Throw E_NOTICE message
*
* @expectedException PHPUnit_Framework_Error_Notice
* @expectedExceptionMessage Undefined index: foo
*/
public function testE_Notice()
{
$e1 = error_reporting();
$this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl'));
$e2 = error_reporting();
$this->assertEquals($e1, $e2);
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1 @@
undefined = {$foo}
@@ -0,0 +1 @@
{include '001_include.tpl'}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,33 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*/
/**
* class for 'escapeHtml' property tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class AutoEscapeTest extends PHPUnit_Smarty
{
/*
* Setup test fixture
*/
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
$this->smarty->setEscapeHtml(true);
}
/**
* test 'escapeHtml' property
*/
public function testAutoEscape()
{
$tpl = $this->smarty->createTemplate('eval:{$foo}');
$tpl->assign('foo', '<a@b.c>');
$this->assertEquals("&lt;a@b.c&gt;", $this->smarty->fetch($tpl));
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,14 @@
<?php
/**
* test registered pre filter closure
* @requires PHP 5.3
*/
$this->smarty->registerFilter(Smarty::FILTER_PRE, function ($input) {
return '{$foo}' . $input;
});
$tpl = $this->smarty->createTemplate('eval:{" hello world"}');
$tpl->assign('foo', 'buh');
$this->assertEquals("buh hello world", $this->smarty->fetch($tpl));
@@ -0,0 +1,279 @@
<?php
/**
* Smarty PHPunit tests of filter
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for filter tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class FilterTest extends PHPUnit_Smarty
{
public $loadSmartyBC = true;
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test autoload output filter
*/
public function testAutoloadOutputFilter()
{
$this->smarty->autoload_filters[ 'output' ] = 'trimwhitespace';
$tpl = $this->smarty->createTemplate('eval:{" <br>hello world"}');
$this->assertEquals("<br>hello world", $this->smarty->fetch($tpl));
}
/**
* test autoload variable filter
*/
public function testAutoloadVariableFilter()
{
$this->smarty->autoload_filters[ 'variable' ] = 'htmlspecialchars';
$tpl = $this->smarty->createTemplate('eval:{"<test>"}');
$this->assertEquals("&lt;test&gt;", $this->smarty->fetch($tpl));
}
/**
* test loaded filter
*/
public function testLoadedOutputFilter()
{
$this->smarty->loadFilter(Smarty::FILTER_OUTPUT, 'trimwhitespace');
$tpl = $this->smarty->createTemplate('string:{" <br>hello world"}');
$this->assertEquals("<br>hello world", $this->smarty->fetch($tpl));
}
public function testLoadedOutputFilterWrapper()
{
$this->smartyBC->load_filter(Smarty::FILTER_OUTPUT, 'trimwhitespace');
$tpl = $this->smartyBC->createTemplate('eval:{" <br>hello world"}');
$this->assertEquals("<br>hello world", $this->smartyBC->fetch($tpl));
}
/**
* test registered output filter
*/
public function testRegisteredOutputFilter()
{
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter');
$tpl = $this->smarty->createTemplate('eval:{"hello world"}');
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
}
/**
* test registered output filter not cached
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRegisteredOutputFilter_001()
{
$this->smarty->assign('foo', 1);
$this->smarty->assign('bar', 2);
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
$this->assertEquals('1 filter 2', $this->smarty->fetch('output_001.tpl'));
}
/**
* test registered output filter not cached 2"
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRegisteredOutputFilter_001_2()
{
$this->smarty->assign('foo', 3);
$this->smarty->assign('bar', 4);
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
$this->assertEquals('3 filter 4', $this->smarty->fetch('output_001.tpl'));
}
/**
* test registered output filter cached 1"
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRegisteredOutputFilter_001_3()
{
$this->smarty->setCaching(true);
$this->smarty->assign('foo', 5);
$this->smarty->assign('bar', 6);
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
$this->assertEquals('5 filter 6', $this->smarty->fetch('output_001.tpl'));
}
/**
* test registered output filter cached 1"
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRegisteredOutputFilter_001_4()
{
$this->smarty->setCaching(true);
$this->smarty->assign('foo', 7);
$this->smarty->assign('bar', 8);
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
$this->assertEquals('5 filter 6', $this->smarty->fetch('output_001.tpl'));
}
/**
* test registered output filter cached nocache"
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRegisteredOutputFilter_002_1()
{
$this->smarty->setCaching(true);
$this->smarty->assign('foo', 10);
$this->smarty->assign('bar', 11);
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
$this->assertEquals('10 filter 11', $this->smarty->fetch('output_002.tpl'));
}
/**
* test registered output filter cached nocache"
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRegisteredOutputFilter_002_2()
{
$this->smarty->setCaching(true);
$this->smarty->assign('foo', 12);
$this->smarty->assign('bar', 13);
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
$this->assertEquals('12 filter 13', $this->smarty->fetch('output_002.tpl'));
}
public function testRegisteredOutputFilterWrapper()
{
$this->smartyBC->register_outputfilter('myoutputfilter');
$tpl = $this->smartyBC->createTemplate('eval:{"hello world"}');
$this->assertEquals("hello world", $this->smartyBC->fetch($tpl));
}
/**
* test registered pre filter
*/
public function testRegisteredPreFilter()
{
function myprefilter($input)
{
return '{$foo}' . $input;
}
$this->smarty->registerFilter(Smarty::FILTER_PRE, 'myprefilter');
$tpl = $this->smarty->createTemplate('eval:{" hello world"}');
$tpl->assign('foo', 'bar');
$this->assertEquals("bar hello world", $this->smarty->fetch($tpl));
}
/**
* test registered pre filter closure
* @requires PHP 5.3
*/
public function testRegisteredPreFilterClosure()
{
if (version_compare(PHP_VERSION,'5.3','<'))
{
$this->markTestSkipped('does not run for PHP 5.2');
} else {
include 'FilterClosure.php';
}
}
/**
* test registered pre filter class
*/
public function testRegisteredPreFilterClass()
{
$this->smarty->registerFilter(Smarty::FILTER_PRE, array('myprefilterclass', 'myprefilter'));
$tpl = $this->smarty->createTemplate('eval:{" hello world"}');
$tpl->assign('foo', 'bar');
$this->assertEquals("bar hello world", $this->smarty->fetch($tpl));
}
/**
* test registered post filter
*/
public function testRegisteredPostFilter()
{
function mypostfilter($input)
{
return '{$foo}' . $input;
}
$this->smarty->registerFilter(Smarty::FILTER_POST, 'mypostfilter');
$tpl = $this->smarty->createTemplate('eval:{" hello world"}');
$tpl->assign('foo', 'bar');
$this->assertEquals('{$foo} hello world', $this->smarty->fetch($tpl));
}
/**
* test variable filter
*/
public function testLoadedVariableFilter()
{
$this->smarty->loadFilter("variable", "htmlspecialchars");
$tpl = $this->smarty->createTemplate('eval:{$foo}');
$tpl->assign('foo', '<?php ?>');
$this->assertEquals('&lt;?php ?&gt;', $this->smarty->fetch($tpl));
}
/**
* test registered post filter
*/
public function testRegisteredVariableFilter2()
{
$var = new VarFilter();
$this->smarty->registerFilter(Smarty::FILTER_VARIABLE, array($var, 'variablefilter'));
$tpl = $this->smarty->createTemplate('string:{$foo}');
$tpl->assign('foo', 'bar');
$this->assertEquals('var{$foo}bar', $this->smarty->fetch($tpl));
}
}
Class VarFilter
{
function variablefilter($input, $smarty)
{
return 'var{$foo}' . $input;
}
}
function myoutputfilter($input)
{
return str_replace(' ', ' ', $input);
}
function myoutputfilter2($input, $tpl)
{
return $input . ' filter ' . $tpl->tpl_vars[ 'bar' ];
}
class myprefilterclass
{
static function myprefilter($input)
{
return '{$foo}' . $input;
}
}
@@ -0,0 +1,31 @@
<?php
/**
* Smarty PHPunit tests loadFilter method
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for loadFilter method tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class LoadFilterTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
/**
* test loadFilter method
*/
public function testLoadFilter()
{
$this->smarty->loadFilter('output', 'trimwhitespace');
$this->assertTrue(is_callable($this->smarty->registered_filters['output']['smarty_outputfilter_trimwhitespace']));
}
}
@@ -0,0 +1,158 @@
<?php
/**
* Smarty PHPunit tests register_filter / unregister_filter methods
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for register_filter / unregister_filter methods tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class RegisterFilterTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
/**
* test register->preFilter method for function
*/
public function testRegisterPrefilterFunction()
{
$this->smarty->registerFilter(Smarty::FILTER_PRE, 'myfilter');
$this->assertTrue(is_callable($this->smarty->registered_filters['pre']['myfilter']));
}
/**
* test register->preFilter method for class method
*/
public function testRegisterPrefiltermethod()
{
$this->smarty->registerFilter(Smarty::FILTER_PRE, array('myfilterclass', 'execute'));
$this->assertTrue(is_callable($this->smarty->registered_filters['pre']['myfilterclass_execute']));
}
/**
* test register->preFilter method for class object
*/
public function testRegisterPrefilterObject()
{
$this->smarty->registerFilter(Smarty::FILTER_PRE, array(new myfilterclass, 'execute'));
$this->assertTrue(is_callable($this->smarty->registered_filters['pre']['myfilterclass_execute']));
}
/**
* test unregister->preFilter method for function
*/
public function testUnegisterPrefilterFunction()
{
$this->smarty->registerFilter(Smarty::FILTER_PRE, 'myfilter');
$this->smarty->unregisterFilter(Smarty::FILTER_PRE, 'myfilter');
$this->assertFalse(isset($this->smarty->registered_filters['pre']['myfilter']));
}
/**
* test unregister->preFilter method for class method
*/
public function testUnregisterPrefiltermethod()
{
$this->smarty->registerFilter(Smarty::FILTER_PRE, array('myfilterclass', 'execute'));
$this->smarty->unregisterFilter(Smarty::FILTER_PRE, array('myfilterclass', 'execute'));
$this->assertFalse(isset($this->smarty->registered_filters['pre']['myfilterclass_execute']));
}
/**
* test register->postFilter method for function
*/
public function testRegisterPostfilterFunction()
{
$this->smarty->registerFilter(Smarty::FILTER_POST, 'myfilter');
$this->assertTrue(is_callable($this->smarty->registered_filters['post']['myfilter']));
}
/**
* test register->postFilter method for class method
*/
public function testRegisterPostfiltermethod()
{
$this->smarty->registerFilter(Smarty::FILTER_POST, array('myfilterclass', 'execute'));
$this->assertTrue(is_callable($this->smarty->registered_filters['post']['myfilterclass_execute']));
}
/**
* test unregister->postFilter method for function
*/
public function testUnegisterPostfilterFunction()
{
$this->smarty->registerFilter(Smarty::FILTER_POST, 'myfilter');
$this->smarty->unregisterFilter(Smarty::FILTER_POST, 'myfilter');
$this->assertFalse(isset($this->smarty->registered_filters['post']['myfilter']));
}
/**
* test unregister->postFilter method for class method
*/
public function testUnregisterPostfiltermethod()
{
$this->smarty->registerFilter(Smarty::FILTER_POST, array('myfilterclass', 'execute'));
$this->smarty->unregisterFilter(Smarty::FILTER_POST, array('myfilterclass', 'execute'));
$this->assertFalse(isset($this->smarty->registered_filters['post']['myfilterclass_execute']));
}
/**
* test register->outputFilter method for function
*/
public function testRegisterOutputfilterFunction()
{
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myfilter');
$this->assertTrue(is_callable($this->smarty->registered_filters['output']['myfilter']));
}
/**
* test register->outputFilter method for class method
*/
public function testRegisterOutputfiltermethod()
{
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, array('myfilterclass', 'execute'));
$this->assertTrue(is_callable($this->smarty->registered_filters['output']['myfilterclass_execute']));
}
/**
* test unregister->outputFilter method for function
*/
public function testUnegisterOutputfilterFunction()
{
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myfilter');
$this->smarty->unregisterFilter(Smarty::FILTER_OUTPUT, 'myfilter');
$this->assertFalse(isset($this->smarty->registered_filters['output']['myfilter']));
}
/**
* test unregister->outputFilter method for class method
*/
public function testUnregisterOutputfiltermethod()
{
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, array('myfilterclass', 'execute'));
$this->smarty->unregisterFilter(Smarty::FILTER_OUTPUT, array('myfilterclass', 'execute'));
$this->assertFalse(isset($this->smarty->registered_filters['output']['myfilterclass_execute']));
}
}
function myfilter($input)
{
return $input;
}
class myfilterclass
{
static function execute($input)
{
return $input;
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1 @@
{$foo}
@@ -0,0 +1 @@
{$foo nocache}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,75 @@
<?php
/**
* Smarty PHPunit tests of generic getter/setter
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for generic getter/setter tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class GetterSetterTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test setter on Smarty object
*/
public function testSmartySetter()
{
$this->smarty->setLeftDelimiter('<{');
$this->smarty->setRightDelimiter('}>');
$this->assertEquals('<{', $this->smarty->left_delimiter);
$this->assertEquals('}>', $this->smarty->right_delimiter);
}
/**
* test getter on Smarty object
*/
public function testSmartyGetter()
{
$this->smarty->setLeftDelimiter('<{');
$this->smarty->setRightDelimiter('}>');
$this->assertEquals('<{', $this->smarty->getLeftDelimiter());
$this->assertEquals('}>', $this->smarty->getRightDelimiter());
}
/**
* test setter on Template object
*/
public function testTemplateSetter()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$tpl->setLeftDelimiter('<{');
$tpl->setRightDelimiter('}>');
$this->assertEquals('<{', $tpl->smarty->left_delimiter);
$this->assertEquals('}>', $tpl->smarty->right_delimiter);
$this->assertEquals('{', $this->smarty->left_delimiter);
$this->assertEquals('}', $this->smarty->right_delimiter);
}
/**
* test getter on Template object
*/
public function testTemplateGetter()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$tpl->setLeftDelimiter('<{');
$tpl->setRightDelimiter('}>');
$this->assertEquals('<{', $tpl->getLeftDelimiter());
$this->assertEquals('}>', $tpl->getRightDelimiter());
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,182 @@
<?php
/**
* Smarty PHPunit tests deault plugin handler
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for plugin handler tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class DefaultPluginHandlerTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
$this->smarty->setForceCompile(true);
$this->smarty->disableSecurity();
$this->smarty->registerDefaultPluginHandler('my_plugin_handler');
}
public function testInit()
{
$this->cleanDirs();
}
public function testDefaultFunctionScript()
{
$this->assertEquals("scriptfunction foo bar", $this->smarty->fetch('test_default_function_script.tpl'));
}
public function testDefaultFunctionScriptNotCachable1()
{
$this->smarty->assign('foo', 'foo');
$this->smarty->caching = 1;
$this->assertEquals("scriptfunction foo", $this->smarty->fetch('test_default_function_script_notcachable.tpl'));
}
public function testDefaultFunctionScriptNotCachable2()
{
$this->smarty->assign('foo', 'bar');
$this->smarty->caching = 1;
$this->assertEquals("scriptfunction bar", $this->smarty->fetch('test_default_function_script_notcachable.tpl'));
}
public function testDefaultFunctionLocal()
{
$this->assertEquals("localfunction foo bar", $this->smarty->fetch('test_default_function_local.tpl'));
}
public function testDefaultCompilerFunctionScript()
{
$this->assertEquals("echo 'scriptcompilerfunction '.'foo bar';", $this->smarty->fetch('test_default_compiler_function_script.tpl'));
}
public function testDefaultCompilerObject()
{
$this->assertEquals('Public World', $this->smarty->fetch('test_default_compiler_object.tpl'));
}
public function testDefaultBlockScript()
{
$this->assertEquals("scriptblock foo bar", $this->smarty->fetch('test_default_block_script.tpl'));
}
public function testDefaultModifierScript()
{
$this->smarty->assign('foo', 'bar');
$this->assertEquals("scriptmodifier default bar", $this->smarty->fetch('test_default_modifier_script.tpl'));
}
public function testDefaultModifier()
{
$this->smarty->assign('foo', 'bar');
$this->assertEquals("localmodifier bar", $this->smarty->fetch('test_default_modifier.tpl'));
}
public function testDefaultModifierStaticClassMethodCaching1()
{
$this->smarty->assign('foo', 'bar');
$this->smarty->caching = 1;
$this->assertEquals("staticmodifier bar", $this->smarty->fetch('test_default_static_modifier.tpl'));
}
public function testDefaultModifierStaticClassMethodCaching2()
{
$this->smarty->assign('foo', 'bar');
$this->smarty->caching = 1;
$this->assertEquals("staticmodifier bar", $this->smarty->fetch('test_default_static_modifier.tpl'));
}
}
function my_plugin_handler($tag, $type, $template, &$callback, &$script, &$cachable)
{
switch ($type) {
case Smarty::PLUGIN_FUNCTION:
switch ($tag) {
case 'scriptfunction':
$script = './scripts/script_function_tag.php';
$callback = 'default_script_function_tag';
return true;
case 'scriptfunctionnotcachable':
$script = './scripts/script_function_tag.php';
$callback = 'default_script_function_tag';
$cachable = false;
return true;
case 'localfunction':
$callback = 'default_local_function_tag';
return true;
default:
return false;
}
case Smarty::PLUGIN_COMPILER:
switch ($tag) {
case 'scriptcompilerfunction':
$script = './scripts/script_compiler_function_tag.php';
$callback = 'default_script_compiler_function_tag';
return true;
case 'compilerobject':
$callback = array(new CompilerDefaultPluginClass, 'compile');
return true;
default:
return false;
}
case Smarty::PLUGIN_BLOCK:
switch ($tag) {
case 'scriptblock':
$script = './scripts/script_block_tag.php';
$callback = 'default_script_block_tag';
return true;
default:
return false;
}
case Smarty::PLUGIN_MODIFIER:
switch ($tag) {
case 'scriptmodifier':
$script = './scripts/script_modifier.php';
$callback = 'default_script_modifier';
return true;
case 'mydefaultmodifier':
$callback = 'default_local_modifier';
return true;
case 'mydefaultstaticmodifier':
$script = './scripts/script_default_static_modifier.php';
$callback = array('DefModifier', 'default_static_modifier');
return true;
default:
return false;
}
default:
return false;
}
}
function default_local_function_tag($params, $template)
{
return 'localfunction ' . $params['value'];
}
function default_local_modifier($input)
{
return 'localmodifier ' . $input;
}
class CompilerDefaultPluginClass
{
static function statCompile ($params, $compiler) {
return '<?php echo \'Static World\';?>';
}
public function compile ($params, $compiler) {
return '<?php echo \'Public World\';?>';
}
}
@@ -0,0 +1,51 @@
<?php
/**
* Smarty PHPunit tests for File resources
*
* @package PHPunit
* @author Rodney Rehm
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class IncludePathTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
$this->smarty->use_include_path = true;
$this->smarty->setPluginsDir(array('./include','./include1'));
$this->smarty->enableSecurity();
$ds = DIRECTORY_SEPARATOR;
set_include_path($this->smarty->_realpath(dirname(__FILE__) . "{$ds}..{$ds}..{$ds}..{$ds}Include_Path{$ds}Plugins{$ds}", true) . PATH_SEPARATOR . get_include_path());
}
/**
* Tears down the fixture
* This method is called after a test is executed.
*
*/
protected function tearDown()
{
ini_restore('include_path');
$this->smarty->disableSecurity();
parent::tearDown();
}
public function testInit()
{
$this->cleanDirs();
}
public function testInclude1()
{
$this->assertContains('plugin1', $this->smarty->fetch('test_include_path1.tpl'));
}
public function testInclude2()
{
$this->assertContains('plugin2', $this->smarty->fetch('test_include_path2.tpl'));
}
public function testInclude3()
{
$this->assertContains('plugin3', $this->smarty->fetch('test_include_path3.tpl'));
}
}
@@ -0,0 +1,54 @@
<?php
/**
* Smarty PHPunit basic core function tests
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class core function tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class LoadPluginTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
/**
* loadPlugin test unkown plugin
*/
public function testLoadPluginErrorReturn()
{
$this->assertFalse($this->smarty->loadPlugin('Smarty_Not_Known'));
}
/**
* loadPlugin test Smarty_Internal_Debug exists
*/
public function testLoadPluginSmartyInternalDebug()
{
$this->assertTrue($this->smarty->loadPlugin('Smarty_Internal_Debug') == true);
}
/**
* loadPlugin test $template_class exists
*/
public function testLoadPluginSmartyTemplateClass()
{
$this->assertTrue($this->smarty->loadPlugin($this->smarty->template_class) == true);
}
/**
* loadPlugin test loaging from plugins_dir
*/
public function testLoadPluginSmartyPluginCounter()
{
$this->assertTrue($this->smarty->loadPlugin('Smarty_Function_Counter') == true);
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,5 @@
<?php
function smarty_function_plugin3($params, $template)
{
return 'plugin3';
}
@@ -0,0 +1,7 @@
<?php
function default_script_block_tag($params, $content, $template, &$repeat)
{
if (isset($content)) {
return 'scriptblock ' . $content;
}
}
@@ -0,0 +1,5 @@
<?php
function default_script_compiler_function_tag($params, $template)
{
return "echo 'scriptcompilerfunction '." . $params['value'] . ";";
}
@@ -0,0 +1,10 @@
<?php
if (!class_exists('DefModifier')) {
Class DefModifier
{
static function default_static_modifier($input)
{
return 'staticmodifier ' . $input;
}
}
}
@@ -0,0 +1,5 @@
<?php
function default_script_function_tag($params, $template)
{
return 'scriptfunction ' . $params['value'];
}
@@ -0,0 +1,5 @@
<?php
function default_script_modifier($input, $text = null)
{
return $text . $input;
}
@@ -0,0 +1,2 @@
<?php
echo 'test include php';
@@ -0,0 +1 @@
{scriptblock}foo bar{/scriptblock}
@@ -0,0 +1 @@
{scriptcompilerfunction value='foo bar'}
@@ -0,0 +1 @@
{compilerobject value='foo bar'}
@@ -0,0 +1 @@
{localfunction value='foo bar'}
@@ -0,0 +1 @@
{scriptfunction value='foo bar'}
@@ -0,0 +1 @@
{scriptfunctionnotcachable value=$foo}
@@ -0,0 +1 @@
{$foo|mydefaultmodifier}
@@ -0,0 +1 @@
{$foo|scriptmodifier:'scriptmodifier default '}
@@ -0,0 +1 @@
{$foo|mydefaultstaticmodifier nocache}
@@ -0,0 +1 @@
{plugin1}
@@ -0,0 +1 @@
{plugin2}
@@ -0,0 +1 @@
{plugin3}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,123 @@
<?php
/**
* Smarty PHPunit tests of filter
*
* @package PHPunit
* @author Rodney Rehm
*/
/**
* class for filter tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class MuteExpectedErrorsTest extends PHPUnit_Smarty
{
protected $_errors = array();
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testInit()
{
$this->cleanDirs();
}
public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
{
$this->_errors[] = $errfile . ' line ' . $errline;
}
public function testMuted()
{
set_error_handler(array($this, 'error_handler'));
Smarty::muteExpectedErrors();
$this->smarty->clearCache('default.tpl');
$this->smarty->clearCompiledTemplate('default.tpl');
$this->smarty->fetch('default.tpl');
$this->assertEquals($this->_errors, array());
@filemtime('ckxladanwijicajscaslyxck');
$error = array(__FILE__ . ' line ' . (__LINE__ - 1));
$this->assertEquals($this->_errors, $error);
Smarty::unmuteExpectedErrors();
restore_error_handler();
}
/**
*
* @rrunInSeparateProcess
*
*/
public function testUnmuted()
{
set_error_handler(array($this, 'error_handler'));
$this->smarty->clearCache('default.tpl');
$this->smarty->clearCompiledTemplate('default.tpl');
$this->smarty->fetch('default.tpl');
$this->assertEquals(Smarty::$_IS_WINDOWS ? 2 : 2, count($this->_errors));
@filemtime('ckxladanwijicajscaslyxck');
$this->assertEquals(Smarty::$_IS_WINDOWS ? 3 : 3, count($this->_errors));
restore_error_handler();
}
/**
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testMutedCaching()
{
set_error_handler(array($this, 'error_handler'));
Smarty::muteExpectedErrors();
$this->smarty->caching = true;
$this->smarty->clearCache('default.tpl');
$this->smarty->clearCompiledTemplate('default.tpl');
$this->smarty->fetch('default.tpl');
$this->assertEquals($this->_errors, array());
@filemtime('ckxladanwijicajscaslyxck');
$error = array(__FILE__ . ' line ' . (__LINE__ - 1));
$this->assertEquals($error, $this->_errors);
Smarty::unmuteExpectedErrors();
restore_error_handler();
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testUnmutedCaching()
{
set_error_handler(array($this, 'error_handler'));
$this->smarty->caching = true;
$this->smarty->clearCache('default.tpl');
$this->smarty->clearCompiledTemplate('default.tpl');
$this->smarty->fetch('default.tpl');
$this->assertEquals(Smarty::$_IS_WINDOWS ? 2 : 2, count($this->_errors));
@filemtime('ckxladanwijicajscaslyxck');
$error = array(__FILE__ . ' line ' . (__LINE__ - 1));
$this->assertEquals(Smarty::$_IS_WINDOWS ? 3 : 3, count($this->_errors));
restore_error_handler();
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1 @@
{$foo|default:""} /* should compile something with @silence error suppression */
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,7 @@
<?php
function smarty_function_chain1($params, $tpl)
{
$tpl->smarty->loadPlugin('smarty_function_chain2');
return smarty_function_chain2($params, $tpl);
}
@@ -0,0 +1,7 @@
<?php
function smarty_function_chain2($params, $tpl)
{
$tpl->smarty->loadPlugin('smarty_function_chain3');
return smarty_function_chain3($params, $tpl);
}
@@ -0,0 +1,5 @@
<?php
function smarty_function_chain3($params, $tpl)
{
return 'from chain3';
}
@@ -0,0 +1,33 @@
<?php
/**
* Smarty PHPunit tests chained loading of dependend pluglind
*
* @package PHPunit
* @author Rodney Rehm
*/
/**
* class for modifier tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class PluginChainedLoadTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testInit()
{
$this->cleanDirs();
}
public function testPluginChainedLoad()
{
$this->smarty->addPluginsDir(dirname(__FILE__) . "/PHPunitplugins/");
$this->assertContains('from chain3', $this->smarty->fetch('test_plugin_chained_load.tpl'));
}
}
@@ -0,0 +1,29 @@
<?php
/**
* Smarty PHPunit tests of shared plugin functions
*
* @package PHPunit
* @author Rodney Rehm
*/
/**
* class for function tests
*/
class SharedFunctionsTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
/**
* test smarty_function_escape_special_chars()
*/
public function testEscapeSpecialChars()
{
require_once SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php';
$this->assertEquals('hello&lt;world &copy;', smarty_function_escape_special_chars('hello<world &copy;'));
$this->assertEquals('ö€', smarty_function_escape_special_chars('ö€'));
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,26 @@
<?php
class _object_toString
{
protected $string = null;
public function __construct($string)
{
$this->string = (string) $string;
}
public function __toString()
{
return $this->string;
}
}
class _object_noString
{
protected $string = null;
public function __construct($string)
{
$this->string = (string) $string;
}
}
@@ -0,0 +1 @@
{chain1}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,37 @@
<?php
/**
* Smarty PHPunit tests SmartyBC code
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class SmartyBC class tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class SmartyBcTest extends PHPUnit_Smarty
{
public $loadSmartyBC = true;
public $loadSmarty = false;
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test {php} tag
*/
public function testSmartyPhpTag()
{
$this->assertEquals('hello world', $this->smartyBC->fetch('string:{php} echo "hello world"; {/php}'));
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,148 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for cache resource file tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class HttpModifiedSinceTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->markTestSkipped('modified since tests are disabled');
$this->setUpSmarty(dirname(__FILE__));
}
public function testInit()
{
$this->cleanDirs();
}
/**
*
*/
public function testDisabled()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(false);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$this->smarty->display('helloworld.tpl');
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$this->assertEquals('', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
/**
*
*/
public function testEnabledUncached()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = false;
$this->smarty->cache_lifetime = 20;
ob_start();
$this->smarty->display('helloworld.tpl');
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$this->assertEquals('', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
/**
*
*/
public function testEnabledCached()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l1 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l2 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$t1 = time();
$t2 = strtotime(substr( $_SERVER['SMARTY_PHPUNIT_HEADERS'][0],15));
$this->assertTrue(($t2-$t1) <= 1);
}
/**
*
*/
public function testEnabledCached2()
{
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', time() - 3600) . ' GMT';
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l3 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l4 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$t1 = time();
$t2 = strtotime(substr( $_SERVER['SMARTY_PHPUNIT_HEADERS'][0],15));
$this->assertTrue(($t2-$t1) <= 1);
}
/**
*
*/
public function testEnabledCached3()
{
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', time() + 10) . ' GMT';
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l5 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l6 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('', $output);
$this->assertEquals('304 Not Modified', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1 @@
hello world
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,36 @@
<?php
/**
* Smarty PHPunit tests for cache resource Apc
*
* @package PHPunit
* @author Uwe Tews
*/
if (ApcCacheEnable == true) {
include_once dirname(__FILE__) . '/../Memcache/CacheResourceCustomMemcacheTest.php';
/**
* class for cache resource file tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest
{
public function setUp()
{
if (ApcCacheEnable != true) {
$this->markTestSkipped('Apc tests are disabled');
} else {
if (!function_exists('apc_cache_info') || ini_get('apc.enable_cli')) {
$this->markTestSkipped('APC cache not available');
}
}
$this->setUpSmarty(dirname(__FILE__));
parent::setUp();
$this->smarty->setCachingType('apc');
$this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/');
}
}
}
@@ -0,0 +1,383 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
include_once dirname(__FILE__) . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource file tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class CacheResourceFileTest extends CacheResourceTestCommon
{
public function setUp()
{
$this->setUpSmarty(dirname(__FILE__));
parent::setUp();
$this->smarty->setCachingType('filetest');
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test getCachedFilepath with configuration['useSubDirs'] enabled
*/
public function testGetCachedFilepathSubDirs()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCachedPath($tpl, true, null, null, 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id
*/
public function testGetCachedFilepathCacheId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', null, 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with compile_id
*/
public function testGetCachedFilepathCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar', 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id and compile_id
*/
public function testGetCachedFilepathCacheIdCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar', 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
}
/**
* test cache->clear_all with cache_id and compile_id
*/
public function testClearCacheAllCacheIdCompileId()
{
$this->cleanCacheDir();
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertEquals(1, $this->smarty->clearAllCache());
}
/**
* test cache->clear with cache_id and compile_id
*/
public function testClearCacheCacheIdCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->cleanCacheDir();
$this->smarty->setUseSubDirs(false);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, 'foo|bar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId2()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(false);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId2Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId3()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->cleanCacheDir();
$this->smarty->setUseSubDirs(false);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId3Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->cleanCacheDir();
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId4()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(false);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId4Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId5()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(false);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, null, 'blar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId5Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, null, 'blar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheFile()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(false);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', null, 'bar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar');
$this->writeCachedContent($tpl3);
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$this->writeCachedContent($tpl4);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
$this->assertEquals(3, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
}
public function testClearCacheCacheFileSub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', null, 'bar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar');
$this->writeCachedContent($tpl3);
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$this->writeCachedContent($tpl4);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
$this->assertEquals(3, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
}
/**
* test cache->clear_all method
*/
public function testClearCacheAll()
{
$this->cleanCacheDir();
file_put_contents($this->smarty->getCacheDir() . 'dummy.php', 'test');
$this->assertEquals(1, $this->smarty->clearAllCache());
}
/**
* test cache->clear_all method not expired
*/
public function testClearCacheAllNotExpired()
{
$this->cleanCacheDir();
file_put_contents($this->smarty->getCacheDir() . 'dummy.php', 'test');
touch($this->smarty->getCacheDir() . 'dummy.php', time() - 1000);
clearstatcache();
$this->assertEquals(0, $this->smarty->clearAllCache(2000));
}
/**
* test cache->clear_all method expired
*/
public function testClearCacheAllExpired()
{
$this->cleanCacheDir();
file_put_contents($this->smarty->getCacheDir() . 'dummy.php', 'test');
touch($this->smarty->getCacheDir() . 'dummy.php', time() - 1000);
clearstatcache();
$this->assertEquals(1, $this->smarty->clearAllCache(500));
}
private function writeCachedContent($tpl)
{
$tpl->writeCachedContent("echo 'hello world';\n");
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,97 @@
<?php
/**
* Smarty PHPunit tests for cache resource memcache
*
* @package PHPunit
* @author Uwe Tews
*/
include_once dirname(__FILE__) . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource memcache tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
{
/**
* Sets up the fixture
* This method is called before a test is executed.
*
*/
public function setUp()
{
if (MemCacheEnable != true) {
$this->markTestSkipped('Memcache tests are disabled');
} else {
if (!class_exists('Memcache')) {
$this->markTestSkipped('Memcache not available');
}
}
$this->setUpSmarty(dirname(__FILE__));
parent::setUp();
$this->smarty->setCachingType('memcachetest');
}
public function testInit()
{
$this->cleanDirs();
}
protected function doClearCacheAssertion($a, $b)
{
$this->assertEquals(- 1, $b);
}
public function testGetCachedFilepathSubDirs()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$tpl->loadCached();
$sha1 = $tpl->source->uid . '#helloworld_tpl##';
$this->assertEquals($sha1, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id
*/
public function testGetCachedFilepathCacheId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');
$tpl->loadCached();
$sha1 = $tpl->source->uid . '#helloworld_tpl#foo|bar#';
$this->assertEquals($sha1, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with compile_id
*/
public function testGetCachedFilepathCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$tpl->loadCached();
$sha1 = $tpl->source->uid . '#helloworld_tpl##blar';
$this->assertEquals($sha1, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id and compile_id
*/
public function testGetCachedFilepathCacheIdCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->loadCached();
$sha1 = $tpl->source->uid . '#helloworld_tpl#foo|bar#blar';
$this->assertEquals($sha1, $tpl->cached->filepath);
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,43 @@
<?php
/**
* Smarty PHPunit tests for cache resource mysql
*
* @package PHPunit
* @author Uwe Tews
*/
if (MysqlCacheEnable == true) {
include_once dirname(__FILE__) . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource file tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class CacheResourceCustomMysqlTest extends CacheResourceTestCommon
{
public function setUp()
{
if (MysqlCacheEnable != true) {
$this->markTestSkipped('mysql tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(dirname(__FILE__));
parent::setUp();
$this->smarty->setCachingType('mysqltest');
}
public function testInit()
{
$this->cleanDirs();
$this->initMysqlCache();
}
}
}
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,2 @@
# Ignore anything in here, but keep this directory
*
@@ -0,0 +1,47 @@
<?php
/**
* Smarty PHPunit tests for cache resource Pdo
*
* @package PHPunit
* @author Uwe Tews
*/
if (PdoCacheEnable == true) {
include_once dirname(__FILE__) . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource file tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class CacheResourceCustomPDOTest extends CacheResourceTestCommon
{
public function setUp($dir = null, $clear = true)
{
if (PdoCacheEnable != true) {
$this->markTestSkipped('mysql Pdo tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(dirname(__FILE__));
parent::setUp();
$this->smarty->setCachingType('pdo');
$this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/');
$this->assertTrue(false !== $this->smarty->loadPlugin('Smarty_CacheResource_Pdotest'),
'loadPlugin() could not load PDO cache resource');
$this->smarty->registerCacheResource('pdo',
new Smarty_CacheResource_Pdotest($this->getPDO(), 'output_cache'));
}
public function testInit()
{
$this->cleanDirs();
$this->initMysqlCache();
}
}
}
@@ -0,0 +1,45 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
if (PdoGzipCacheEnable == true) {
include_once dirname(__FILE__) . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource file tests
*
* @backupStaticAttributes enabled
*/
class CacheResourceCustomPDOGzipTest extends CacheResourceTestCommon
{
public function setUp($dir = null, $clear = true)
{
if (PdoGzipCacheEnable != true) {
$this->markTestSkipped('mysql Pdo Gzip tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(dirname(__FILE__));
parent::setUp();
$this->smarty->setCachingType('pdo');
$this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/');
$this->assertTrue(false !== $this->smarty->loadPlugin('Smarty_CacheResource_Pdo_Gziptest'),
'loadPlugin() could not load PDOGzip cache resource');
$this->smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdo_Gziptest($this->getPDO(),
'output_cache'));
}
public function testInit()
{
$this->cleanDirs();
$this->initMysqlCache();
}
}
}
@@ -0,0 +1,44 @@
<?php
/**
* Smarty PHPunit tests for cache resource registered
*
* @package PHPunit
* @author Uwe Tews
*/
if (MysqlCacheEnable == true) {
include_once dirname(__FILE__) . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource file tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon
{
public function setUp()
{
if (MysqlCacheEnable != true) {
$this->markTestSkipped('mysql tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(dirname(__FILE__));
parent::setUp();
if (!class_exists('Smarty_CacheResource_Mysqltest', false)) {
require_once(dirname(__FILE__) . "/../_shared/PHPunitplugins/cacheresource.mysqltest.php");
}
$this->smarty->setCachingType('foobar');
$this->smarty->registerCacheResource('foobar', new Smarty_CacheResource_Mysqltest());
}
public function testInit()
{
$this->cleanDirs();
$this->initMysqlCache();
}
}
}

Some files were not shown because too many files have changed in this diff Show More