diff options
author | tomneedham <tom@owncloud.com> | 2014-02-17 10:58:27 +0000 |
---|---|---|
committer | tomneedham <tom@owncloud.com> | 2014-02-17 10:58:27 +0000 |
commit | 049e03c2b92e10ef94d1f7bc900e74f078a56a9b (patch) | |
tree | e60884d07dde2989d0d04b78de8bb259bc37261b /tests/lib | |
parent | 082abdc62080730f70ac0fac67628e4d3bb0cc7b (diff) | |
download | nextcloud-server-049e03c2b92e10ef94d1f7bc900e74f078a56a9b.tar.gz nextcloud-server-049e03c2b92e10ef94d1f7bc900e74f078a56a9b.zip |
Finish basic testing of user export
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/migrate.php | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/tests/lib/migrate.php b/tests/lib/migrate.php index 5c6c9ebe7be..4b20173ba5f 100644 --- a/tests/lib/migrate.php +++ b/tests/lib/migrate.php @@ -9,14 +9,68 @@ class Test_Migrate extends PHPUnit_Framework_TestCase { public $users; + public $tmpfiles = array(); - public function testUserSelfExport(){ + /** + * @breif 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; + } + + /** + * @breif validates an export for a user + * @breif 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 = uniqid(); - $u = new OC_User(); - $u->createUser($user, 'password'); - $this->users[] = $user; - $exportLocation = \OC_Migrate::export($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() { @@ -24,6 +78,9 @@ class Test_Migrate extends PHPUnit_Framework_TestCase { foreach($this->users as $user) { $u->deleteUser($user); } + foreach($this->tmpfiles as $file) { + \OC_Helper::rmdirr($file); + } } |