diff options
author | Tom Needham <needham.thomas@gmail.com> | 2014-02-18 17:35:49 +0100 |
---|---|---|
committer | Tom Needham <needham.thomas@gmail.com> | 2014-02-18 17:35:49 +0100 |
commit | a573fe7d769f5eea26f52b818eee11779090bb50 (patch) | |
tree | 271658d1e79553f5d172a72d0fc9fa67bb4ef946 /tests | |
parent | 3b1083f46eb7dd67faddc8214799ee6396ffdea9 (diff) | |
parent | 0beaeed713977bcca0eb9da996af712526ee69d2 (diff) | |
download | nextcloud-server-a573fe7d769f5eea26f52b818eee11779090bb50.tar.gz nextcloud-server-a573fe7d769f5eea26f52b818eee11779090bb50.zip |
Merge pull request #6650 from owncloud/migration_unit_tests
User migration fix, and basic unit test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/migrate.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/lib/migrate.php b/tests/lib/migrate.php new file mode 100644 index 00000000000..39a9bfc8d5a --- /dev/null +++ b/tests/lib/migrate.php @@ -0,0 +1,89 @@ +<?php +/** + * Copyright (c) 2014 Tom Needham <tom@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_Migrate extends PHPUnit_Framework_TestCase { + + public $users; + public $tmpfiles = array(); + + /** + * @brief Generates a test user and sets up their file system + * @return string the test users id + */ + public function generateUser() { + $username = uniqid(); + \OC_User::createUser($username, 'password'); + \OC_Util::tearDownFS(); + \OC_User::setUserId(''); + \OC\Files\Filesystem::tearDown(); + \OC_Util::setupFS($username); + $this->users[] = $username; + return $username; + } + + /** + * @brief validates an export for a user + * @brief checks for existence of export_info.json and file folder + * @param string $exportedUser the user that was exported + * @param string $path the path to the .zip export + */ + public function validateUserExport($exportedBy, $exportedUser, $path) { + $this->assertTrue(file_exists($path)); + // Extract + $extract = get_temp_dir() . '/oc_import_' . uniqid(); + //mkdir($extract); + $this->tmpfiles[] = $extract; + $zip = new ZipArchive; + $zip->open($path); + $zip->extractTo($extract); + $zip->close(); + $this->assertTrue(file_exists($extract.'/export_info.json')); + $exportInfo = file_get_contents($extract.'/export_info.json'); + $exportInfo = json_decode($exportInfo); + $this->assertNotNull($exportInfo); + $this->assertEquals($exportedUser, $exportInfo->exporteduser); + $this->assertEquals($exportedBy, $exportInfo->exportedby); + $this->assertTrue(file_exists($extract.'/'.$exportedUser.'/files')); + } + + public function testUserSelfExport() { + // Create a user + $user = $this->generateUser(); + \OC_User::setUserId($user); + $export = \OC_Migrate::export($user); + // Check it succeeded and exists + $this->assertTrue(json_decode($export)->success); + // Validate the export + $this->validateUserExport($user, $user, json_decode($export)->data); + } + + public function testUserOtherExport() { + $user = $this->generateUser(); + $user2 = $this->generateUser(); + \OC_User::setUserId($user2); + $export = \OC_Migrate::export($user); + // Check it succeeded and exists + $this->assertTrue(json_decode($export)->success); + // Validate the export + $this->validateUserExport($user2, $user, json_decode($export)->data); + } + + public function tearDown() { + $u = new OC_User(); + foreach($this->users as $user) { + $u->deleteUser($user); + } + foreach($this->tmpfiles as $file) { + \OC_Helper::rmdirr($file); + } + } + + + + +} |