Skip to content

Commit

Permalink
Feature/merge smarty-phpunit into tests subfolder (#580)
Browse files Browse the repository at this point in the history
* Removed unneeded files and replace dummy.txt with .gitignore files
* Synced unit tests with master codebase, noted TODO's, fixed phpunit scripts and travis config
* fix php7.4 deprecation and remove php7.4 from travis allow_failures since php7.4 is current stable

Co-authored-by: Uwe Tews <uwe.tews@googlemail.com>
Co-authored-by: Uwe Tews <uwe.tews@gmail.com>
Co-authored-by: AnrDaemon <anrdaemon@yandex.ru>
  • Loading branch information
4 people authored Apr 13, 2020
1 parent 61e7412 commit 17d4d43
Show file tree
Hide file tree
Showing 875 changed files with 26,924 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ utilies/*.php
phpunit*
vendor/*
composer.lock
templates_c/*
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 changes: 69 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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'),
);
}
```
2 changes: 2 additions & 0 deletions phpunit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /bin/bash
vendor/phpunit/phpunit/phpunit tests/UnitTests
43 changes: 43 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea

# Unit test / coverage reports
.coverage
.tox

#Smarty
testdox.html
TestResults.tap
TestResults.txt

28 changes: 28 additions & 0 deletions tests/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions tests/Config.php
Original file line number Diff line number Diff line change
@@ -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', "");
5 changes: 5 additions & 0 deletions tests/Include_Path/Plugins/include/function.plugin1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
function smarty_function_plugin1($params, $template)
{
return 'plugin1';
}
5 changes: 5 additions & 0 deletions tests/Include_Path/Plugins/include1/function.plugin2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
function smarty_function_plugin2($params, $template)
{
return 'plugin2';
}
1 change: 1 addition & 0 deletions tests/Include_Path/Tpl/include/include_test2.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include_test2
1 change: 1 addition & 0 deletions tests/Include_Path/Tpl/include/include_test4.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include_test4
1 change: 1 addition & 0 deletions tests/Include_Path/Tpl/templates_2/test4.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{include 'include_test4.tpl'}
1 change: 1 addition & 0 deletions tests/Include_Path/Tpl/test5.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include path root
Loading

0 comments on commit 17d4d43

Please sign in to comment.