Fix PHPunit errors with InlineImageMock.php and UtilsTest

HTMLDOMSanitizerTest : fix "Fatal error: Cannot declare class InlineImage, because the name is already in use in /var/www/html/iTop/test/core/sanitizer/InlineImageMock.php"
We are now injecting the class to mock, instead of declaring another class with the same name (was working before but why ?!???)

\UtilsTest::testSanitizer : no more testing the "class" filter, because it is a simple indirection, and we need to load datamodel which is causing multiple problems (see the comment in the test method dataprovider)
This commit is contained in:
Pierre Goiffon
2022-05-20 10:42:48 +02:00
parent 16fcddc249
commit f57d1f1de3
5 changed files with 76 additions and 50 deletions

View File

@@ -14,7 +14,6 @@ abstract class AbstractDOMSanitizerTest extends ItopTestCase
parent::setUp();
require_once(APPROOT.'application/utils.inc.php');
require_once(APPROOT.'core/htmlsanitizer.class.inc.php');
require_once(APPROOT.'test/core/sanitizer/InlineImageMock.php');
}
protected function ReadTestFile($sFileToTest, $sFolderName)

View File

@@ -2,16 +2,12 @@
namespace Combodo\iTop\Test\UnitTest\Core\Sanitizer;
use HTMLDOMSanitizer;
use InlineImageMock;
require_once __DIR__.'/AbstractDOMSanitizerTest.php';
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
*/
class HTMLDOMSanitizerTest extends AbstractDOMSanitizerTest
{
/**
@@ -222,15 +218,17 @@ class HTMLDOMSanitizerTest extends AbstractDOMSanitizerTest
/**
* @dataProvider CallInlineImageProcessImageTagProvider
* @uses \InlineImageMock
*/
public function testDoSanitizeCallInlineImageProcessImageTag($sHtml, $iExpectedCount)
{
require_once APPROOT.'test/core/sanitizer/InlineImageMock.php';
InlineImageMock::ResetCallCounter();
$oSanitizer = new HTMLDOMSanitizer();
$oSanitizer = new HTMLDOMSanitizer(InlineImageMock::class);
$oSanitizer->DoSanitize($sHtml);
$iCalledCount = \InlineImage::GetCallCounter();
$iCalledCount = \InlineImageMock::GetCallCounter();
$this->assertEquals($iExpectedCount, $iCalledCount);
}

View File

@@ -1,4 +1,6 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpIllegalPsrClassPathInspection */
/**
* Copyright (C) 2010-2021 Combodo SARL
*
@@ -20,10 +22,11 @@
*/
/**
* Mock class used by @see \Combodo\iTop\Test\UnitTest\Core\HTMLDOMSanitizerTest
* Mock class used to count number of calls for the ProcessImage static method
*
* @used-by \Combodo\iTop\Test\UnitTest\Core\Sanitizer\HTMLDOMSanitizerTest::testDoSanitizeCallInlineImageProcessImageTag()
*/
class InlineImage
class InlineImageMock
{
private static $iCallCounter = 0;
@@ -32,6 +35,11 @@ class InlineImage
self::$iCallCounter++;
}
public static function ResetCallCounter()
{
self::$iCallCounter = 0;
}
public static function GetCallCounter()
{
return self::$iCallCounter;