Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rskrzypczak committed Nov 2, 2023
1 parent 918c9dc commit b46760f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 58 deletions.
58 changes: 29 additions & 29 deletions tests/App/Purifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,28 @@ public static function setUpBeforeClass(): void
$userRecordModel->set('hour_format', '24');
$userRecordModel->set('time_zone', \App\Fields\DateTime::getTimeZone());
$userRecordModel->save();
\date_default_timezone_set(\App\Fields\DateTime::getTimeZone());
date_default_timezone_set(\App\Fields\DateTime::getTimeZone());
}

/**
* Restore current user preferences.
*
* @throws \Exception
*/
public static function tearDownAfterClass(): void
{
$userModel = \Vtiger_Record_Model::getInstanceById(\App\User::getCurrentUserId(), 'Users');
$userModel->set('currency_decimal_separator', self::$separatorDecimal);
$userModel->set('currency_grouping_separator', self::$separatorGrouping);
$userModel->set('currency_symbol_placement', self::$symbolPlacement);
$userModel->set('currency_grouping_pattern', self::$patternGrouping);
$userModel->set('no_of_currency_decimals', self::$decimalNum);
$userModel->set('truncate_trailing_zeros', self::$truncateTrailingZeros);
$userModel->set('hour_format', self::$hourFormat);
$userModel->set('time_zone', self::$userTimeZone);
$userModel->save();
date_default_timezone_set(self::$timeZone);
parent::tearDownAfterClass();
}

/**
Expand All @@ -97,7 +118,7 @@ public static function setUpBeforeClass(): void
*/
public function dataProviderByType()
{
//$type, $assertion, $expected, $text, $message, $exception
// $type, $assertion, $expected, $text, $message, $exception
return [
['Standard', 'Same', 'Test-text-string-for-purifier', 'Test-text-string-for-purifier', 'Sample text should be unchanged', null],
['Standard', 'Same', ['Test-text-string-for-purifier', 'Test-text-string-for-purifier'], ['Test-text-string-for-purifier', 'Test-text-string-for-purifier'], 'Sample text should be unchanged(array)', null],
Expand All @@ -108,8 +129,8 @@ public function dataProviderByType()
[2, 'NotSame', 'Test_text_alnum_4_purifier%$54#T$#BR-', 'Test_text_alnum_4_purifier%$54#T$#BR-', 'Sample text should be purified', \App\Exceptions\IllegalValue::class],
['DateInUserFormat', 'Same', date('Y-m-d'), date('Y-m-d'), 'Sample text should be unchanged', null],
['DateInUserFormat', 'NotSame', date('Y.m.d'), date('Y.m.d'), 'Sample text should be purified', \App\Exceptions\IllegalValue::class],
['DateRangeUserFormat', 'Same', [date('Y-m-d'), date('Y-m-d', \strtotime('+1 day'))], date('Y-m-d') . ',' . date('Y-m-d', \strtotime('+1 day')), 'Sample text should be unchanged', null],
['DateRangeUserFormat', 'NotSame', date('Y.m.d') . ',' . date('Y.m.d', \strtotime('+1 day')), date('Y.m.d') . ',' . date('Y.m.d', \strtotime('+1 day')), 'Sample text should be purified', \App\Exceptions\IllegalValue::class],
['DateRangeUserFormat', 'Same', [date('Y-m-d'), date('Y-m-d', strtotime('+1 day'))], date('Y-m-d') . ',' . date('Y-m-d', strtotime('+1 day')), 'Sample text should be unchanged', null],
['DateRangeUserFormat', 'NotSame', date('Y.m.d') . ',' . date('Y.m.d', strtotime('+1 day')), date('Y.m.d') . ',' . date('Y.m.d', strtotime('+1 day')), 'Sample text should be purified', \App\Exceptions\IllegalValue::class],
['date', 'Same', date('Y-m-d'), date('Y-m-d'), 'Sample text should be unchanged', null],
['date', 'NotSame', '201X-07-26', '201X-07-26', 'Sample text should be purified', \App\Exceptions\IllegalValue::class],
['time', 'Same', date('H:i:s'), date('H:i:s'), 'Sample text should be unchanged', null],
Expand All @@ -131,9 +152,9 @@ public function dataProviderByType()
['Text', 'NotSame', 'ę€ółśążźćń23{}":?>><>?:"{}+_)(*&^%$#@!) &lt;svg/onabort=alert(3)// <svg/onload=alert(1) onfocus=alert(2)//', 'ę€ółśążźćń23{}":?>><>?:"{}+_)(*&^%$#@!) &lt;svg/onabort=alert(3)// <svg/onload=alert(1) onfocus=alert(2)//', 'Sample number should be purified', \App\Exceptions\IllegalValue::class],
['Default', 'Same', 'Test-text-string-for-purifier', 'Test-text-string-for-purifier', 'Sample number should be unchanged', null],
['Default', 'NotSame', 'ę€ółśążźćń23{}":?>><>?:"{}+_)(*&^%$#@!) &lt;svg/onabort=alert(3)// <svg/onload=alert(1) onfocus=alert(2)//', 'ę€ółśążźćń23{}":?>><>?:"{}+_)(*&^%$#@!) &lt;svg/onabort=alert(3)// <svg/onload=alert(1) onfocus=alert(2)//', 'Sample number should be purified', \App\Exceptions\IllegalValue::class],
['MailId', 'Same', '<[email protected]> (added by [email protected])', '<[email protected]> (added by [email protected])', 'Sample text should be unchanged', null],
['MailId', 'Same', '<30.123.12.JavaMail."admin.azure"@A-PROXY01>', '<30.123.12.JavaMail."admin.azure"@A-PROXY01>', 'Sample text should be unchanged', null],
['MailId', 'Same', '<[email protected]>', '<[email protected]>', 'Sample text should be unchanged', null],
['MailId', 'Same', '[email protected]> (added by [email protected])', '<[email protected]> (added by [email protected])', 'Sample text should be unchanged', null],
['MailId', 'Same', '30.123.12.JavaMail."admin.azure"@A-PROXY01', '<30.123.12.JavaMail."admin.azure"@A-PROXY01>', 'Sample text should be unchanged', null],
['MailId', 'Same', '[email protected]', '<[email protected]>', 'Sample text should be unchanged', null],
[\App\Purifier::PATH, 'NotSame', '../Test', '../Test', 'Path should be discarded', \App\Exceptions\IllegalValue::class],
[\App\Purifier::PATH, 'Same', '/Test/test', '/Test/test', 'Path should be unchanged', null],
];
Expand Down Expand Up @@ -246,7 +267,7 @@ public function purifyHtmlProviderSuccess(): array
['<div>Test-text-string-for-purifier</div>', '<div>Test-text-string-for-purifier</div>', true],
['ę€ółśążźćń23{}":?>><>?:"{}+_)', 'ę€ółśążźćń23{}":?&gt;&gt;&lt;&gt;?:"{}+_)', true],
['ę€ółśążźćń23{}":?>><>?:"{}+_)(*&^%$#@!)', 'ę€ółśążźćń23{}":?&gt;&gt;&lt;&gt;?:"{}+_)(*&amp;^%$#@!)', true],
[\file_get_contents(ROOT_DIRECTORY . '/tests/data/phpFile1.html'), \file_get_contents(ROOT_DIRECTORY . '/tests/data/phpFile2.html'), true],
[file_get_contents(ROOT_DIRECTORY . '/tests/data/phpFile1.html'), file_get_contents(ROOT_DIRECTORY . '/tests/data/phpFile2.html'), true],
['<p><yetiforce type="Documents" crm-id="70521" attachment-id="22855"></yetiforce></p>', '<p><yetiforce type="Documents" crm-id="70521" attachment-id="22855"></yetiforce></p>', true],
];
}
Expand All @@ -263,25 +284,4 @@ public function testPurifyHtmlSuccess(string $text, string $expected): void
{
$this->assertSame($expected, \App\Purifier::purifyHtml($text), 'Sample text should be unchanged');
}

/**
* Restore current user preferences.
*
* @throws \Exception
*/
public static function tearDownAfterClass(): void
{
$userModel = \Vtiger_Record_Model::getInstanceById(\App\User::getCurrentUserId(), 'Users');
$userModel->set('currency_decimal_separator', self::$separatorDecimal);
$userModel->set('currency_grouping_separator', self::$separatorGrouping);
$userModel->set('currency_symbol_placement', self::$symbolPlacement);
$userModel->set('currency_grouping_pattern', self::$patternGrouping);
$userModel->set('no_of_currency_decimals', self::$decimalNum);
$userModel->set('truncate_trailing_zeros', self::$truncateTrailingZeros);
$userModel->set('hour_format', self::$hourFormat);
$userModel->set('time_zone', self::$userTimeZone);
$userModel->save();
\date_default_timezone_set(self::$timeZone);
parent::tearDownAfterClass();
}
}
39 changes: 10 additions & 29 deletions tests/Base/Z_ResetingRecordNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public static function setUpBeforeClass(): void
self::$transaction = \App\Db::getInstance()->beginTransaction();
}

/**
* Cleaning after tests.
*/
public static function tearDownAfterClass(): void
{
self::$transaction->rollBack();
\App\Cache::clear();
}

/**
* Test method "DateMock".
*/
Expand Down Expand Up @@ -135,25 +144,6 @@ public function testIncrementNumberStandard()
}
}

/**
* Test method "Parse".
* Test parsing method for record numbers on different dates.
*/
public function testParse()
{
$instance = RecordNumber::getInstance('FInvoice');
foreach (RecordNumber::$dates as $index => $date) {
RecordNumber::$currentDateIndex = $index;
$parts = explode('-', $date);
$instance->set('prefix', '{{DD}}/');
$this->assertSame($parts[2] . '/1', $instance->parseNumber(1));
$instance->set('prefix', '{{MM}}/');
$this->assertSame($parts[1] . '/1', $instance->parseNumber(1));
$instance->set('prefix', '{{YYYY}}/');
$this->assertSame($parts[0] . '/1', $instance->parseNumber(1));
}
}

/**
* Test method "IncrementNumberDay".
* Test record number resetting with new day.
Expand Down Expand Up @@ -344,7 +334,7 @@ public function testLeadingZeros(): void
$currentNumber = 1;
$currentDate = $sequence;
}
$currentNumber = \str_pad($currentNumber, $leadingZeros, '0', STR_PAD_LEFT);
$currentNumber = str_pad($currentNumber, $leadingZeros, '0', STR_PAD_LEFT);
$this->assertSame("$date/$currentNumber", $instance->getIncrementNumber());
$number = RecordNumber::getInstance('FInvoice');
$this->assertSame($currentNumber + 1, $number->get('cur_id'));
Expand All @@ -356,13 +346,4 @@ public function testLeadingZeros(): void
}
}
}

/**
* Cleaning after tests.
*/
public static function tearDownAfterClass(): void
{
self::$transaction->rollBack();
\App\Cache::clear();
}
}

0 comments on commit b46760f

Please sign in to comment.