2014-05-14 13:24:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use System\Classes\VersionManager;
|
|
|
|
|
|
|
|
|
|
class VersionManagerTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
|
{
|
2015-02-10 06:45:07 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
include_once base_path().'/tests/fixtures/plugins/october/tester/Plugin.php';
|
|
|
|
|
include_once base_path().'/tests/fixtures/plugins/october/sample/Plugin.php';
|
|
|
|
|
include_once base_path().'/tests/fixtures/plugins/october/noupdates/Plugin.php';
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Tests
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
public function testGetLatestFileVersion()
|
|
|
|
|
{
|
|
|
|
|
$manager = VersionManager::instance();
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = self::callProtectedMethod($manager, 'getLatestFileVersion', ['\October\\Tester']);
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$this->assertNotNull($result);
|
|
|
|
|
$this->assertEquals('1.0.5', $result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetFileVersions()
|
|
|
|
|
{
|
|
|
|
|
$manager = VersionManager::instance();
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = self::callProtectedMethod($manager, 'getFileVersions', ['\October\\Tester']);
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$this->assertCount(5, $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.1', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.2', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.3', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.4', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.5', $result);
|
|
|
|
|
|
|
|
|
|
$sample = $result['1.0.1'];
|
|
|
|
|
$comment = array_shift($sample);
|
|
|
|
|
$this->assertEquals("Added some upgrade file and some seeding", $comment);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test junk file
|
|
|
|
|
*/
|
|
|
|
|
$result = self::callProtectedMethod($manager, 'getFileVersions', ['\October\\Sample']);
|
|
|
|
|
$this->assertCount(5, $result);
|
|
|
|
|
$this->assertArrayHasKey('junk', $result);
|
|
|
|
|
$this->assertArrayHasKey('1', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.*', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.x', $result);
|
2016-01-04 07:10:35 +00:00
|
|
|
$this->assertArrayHasKey('10.3', $result);
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$sample = array_shift($result);
|
|
|
|
|
$comment = array_shift($sample);
|
|
|
|
|
$this->assertEquals("JUNK JUNK JUNK", $comment);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test empty file
|
|
|
|
|
*/
|
|
|
|
|
$result = self::callProtectedMethod($manager, 'getFileVersions', ['\October\\NoUpdates']);
|
2015-07-25 01:49:26 +00:00
|
|
|
$this->assertEmpty($result);
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetNewFileVersions()
|
|
|
|
|
{
|
|
|
|
|
$manager = VersionManager::instance();
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = self::callProtectedMethod($manager, 'getNewFileVersions', ['\October\\Tester', '1.0.3']);
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$this->assertCount(2, $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.4', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.5', $result);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When at version 0, should return everything
|
|
|
|
|
*/
|
|
|
|
|
$manager = VersionManager::instance();
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = self::callProtectedMethod($manager, 'getNewFileVersions', ['\October\\Tester']);
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$this->assertCount(5, $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.1', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.2', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.3', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.4', $result);
|
|
|
|
|
$this->assertArrayHasKey('1.0.5', $result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 17:11:43 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider versionInfoProvider
|
|
|
|
|
*
|
|
|
|
|
* @param $versionInfo
|
|
|
|
|
* @param $expectedComments
|
|
|
|
|
* @param $expectedScripts
|
|
|
|
|
*/
|
|
|
|
|
public function testExtractScriptsAndComments($versionInfo, $expectedComments, $expectedScripts)
|
|
|
|
|
{
|
|
|
|
|
$manager = VersionManager::instance();
|
|
|
|
|
list($comments, $scripts) = self::callProtectedMethod($manager, 'extractScriptsAndComments', [$versionInfo]);
|
|
|
|
|
|
|
|
|
|
$this->assertInternalType('array', $comments);
|
|
|
|
|
$this->assertInternalType('array', $scripts);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($expectedComments, $comments);
|
|
|
|
|
$this->assertEquals($expectedScripts, $scripts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function versionInfoProvider()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'A single update comment string',
|
|
|
|
|
[
|
|
|
|
|
'A single update comment string'
|
|
|
|
|
],
|
|
|
|
|
[]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'A classic update comment string followed by script',
|
|
|
|
|
'update_script.php'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'A classic update comment string followed by script'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'update_script.php'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'scripts_can_go_first.php',
|
|
|
|
|
'An update comment string after the script',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'An update comment string after the script'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'scripts_can_go_first.php'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'scripts_can_go_first.php',
|
|
|
|
|
'An update comment string after the script',
|
|
|
|
|
'scripts_can_go_anywhere.php',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'An update comment string after the script'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'scripts_can_go_first.php',
|
|
|
|
|
'scripts_can_go_anywhere.php'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'scripts_can_go_first.php',
|
|
|
|
|
'The first update comment',
|
|
|
|
|
'scripts_can_go_anywhere.php',
|
|
|
|
|
'The second update comment',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'The first update comment',
|
|
|
|
|
'The second update comment'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'scripts_can_go_first.php',
|
|
|
|
|
'scripts_can_go_anywhere.php'
|
|
|
|
|
]
|
2019-03-25 15:57:06 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'file.name.with.dots.php',
|
|
|
|
|
'The first update comment',
|
|
|
|
|
'1.0.2.scripts_can_go_anywhere.php',
|
|
|
|
|
'The second update comment',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'The first update comment',
|
|
|
|
|
'The second update comment'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'file.name.with.dots.php',
|
|
|
|
|
'1.0.2.scripts_can_go_anywhere.php'
|
|
|
|
|
]
|
2019-03-31 14:46:33 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'subdirectory/file.name.with.dots.php',
|
|
|
|
|
'The first update comment',
|
|
|
|
|
'subdirectory\1.0.2.scripts_can_go_anywhere.php',
|
|
|
|
|
'The second update comment',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'The first update comment',
|
|
|
|
|
'The second update comment'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'subdirectory/file.name.with.dots.php',
|
|
|
|
|
'subdirectory\1.0.2.scripts_can_go_anywhere.php'
|
|
|
|
|
]
|
2019-02-19 17:11:43 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
2017-04-24 11:38:19 +00:00
|
|
|
}
|