mirror of https://github.com/craftcms/cms.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.5 KiB
94 lines
2.5 KiB
<?php
|
|
/**
|
|
* @link https://craftcms.com/
|
|
* @copyright Copyright (c) Pixel & Tonic, Inc.
|
|
* @license https://craftcms.github.io/license/
|
|
*/
|
|
|
|
namespace crafttests\unit\helpers;
|
|
|
|
use Codeception\Test\Unit;
|
|
use craft\helpers\Diff;
|
|
|
|
/**
|
|
* Unit tests for the Diff Helper class.
|
|
*
|
|
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
|
|
* @since 3.6.0
|
|
*/
|
|
class DiffHelperTest extends Unit
|
|
{
|
|
/**
|
|
* @dataProvider compareDataProvider
|
|
*
|
|
* @param bool $expected
|
|
* @param mixed $a
|
|
* @param mixed $b
|
|
* @param bool $strict
|
|
*/
|
|
public function testCompare(bool $expected, $a, $b, bool $strict)
|
|
{
|
|
self::assertSame($expected, Diff::compare($a, $b, $strict));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider diffDataProvider
|
|
*
|
|
* @param string $expected
|
|
* @param mixed $from
|
|
* @param mixed $to
|
|
* @param int $indent
|
|
* @param int $contextLines
|
|
*/
|
|
public function testDiff(string $expected, $from, $to, int $indent = 2, int $contextLines = 3)
|
|
{
|
|
self::assertSame($expected, Diff::diff($from, $to, $indent, $contextLines));
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function compareDataProvider(): array
|
|
{
|
|
return [
|
|
[true, 1, '1', false],
|
|
[false, 1, '1', true],
|
|
[true, ['foo' => ['bar' => 'baz']], ['foo' => ['bar' => 'baz']], true],
|
|
[false, ['foo' => ['bar' => 'baz']], ['foo' => ['bar' => 'qux']], true],
|
|
[false, ['foo' => true], ['foo' => true, 'bar' => true], true],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function diffDataProvider(): array
|
|
{
|
|
return [
|
|
['', 'foo', 'foo'],
|
|
["- foo\n+ bar", 'foo', 'bar'],
|
|
[
|
|
"- - foo\n- - bar\n- - baz\n+ - foo\n+ - bar\n+ - qux",
|
|
['foo', 'bar', 'baz'],
|
|
['foo', 'bar', 'qux']
|
|
],
|
|
[
|
|
" foo:\n- - bar\n- - baz\n+ - bar\n+ - qux",
|
|
['foo' => ['bar', 'baz']],
|
|
['foo' => ['bar', 'qux']]
|
|
],
|
|
[
|
|
"- - bar\n- - baz\n+ - bar\n+ - qux",
|
|
['foo' => ['bar', 'baz']],
|
|
['foo' => ['bar', 'qux']],
|
|
4,
|
|
0
|
|
],
|
|
[
|
|
" dateModified:\n- 1607544575\n+ 1607544576\n email:\n fromEmail:",
|
|
include dirname(__DIR__, 2) . '/_data/diff/a.php',
|
|
include dirname(__DIR__, 2) . '/_data/diff/b.php'
|
|
]
|
|
];
|
|
}
|
|
}
|