Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ extension FileProviderExtension {

_ = self.fpUtility.moveFile(self.utilityFileSystem.getDirectoryProviderStorageIconOcId(itemIdentifier.rawValue, etag: metadata.etag), toPath: self.utilityFileSystem.getDirectoryProviderStorageIconOcId(itemIdentifier.rawValue, etag: metadata.etag))

NCManageDatabase.shared.setLocalFile(ocId: ocId, fileName: itemName, etag: nil)
NCManageDatabase.shared.setLocalFile(ocId: ocId, fileName: itemName)
}

guard let parentItemIdentifier = self.fpUtility.getParentItemIdentifier(metadata: metadata) else {
Expand Down
108 changes: 108 additions & 0 deletions Tests/NextcloudUnitTests/RenameFileTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// RenameFileTests.swift
// NextcloudTests
//
// Created by A200073704 on 14/06/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

@testable import Nextcloud
import XCTest
import NextcloudKit

class RenameFileTests: XCTestCase {


override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}


func testStoryboardPresence() {

let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
XCTAssertNotNil(storyboard, "Storyboard 'NCRenameFile' should be present")

}

func testRenameButtonPresence() {
let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let renameButton = viewController.renameButton
XCTAssertNotNil(renameButton, "Rename button should be present")
}

func testRenameButtonBackgroundColor() {

let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let color = NCBrandColor.shared.brand.cgColor
let renameButton = viewController.renameButton.layer.backgroundColor

XCTAssertEqual(renameButton,color, "Rename Button Bcakground Color should be brand")
}

func testCancelButtonPresence() {
let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let cancelButton = viewController.cancelButton
XCTAssertNotNil(cancelButton, "Cancel button should be present")
}

func testImageViewPresence() {

let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let imageView = viewController.previewFile
XCTAssertNotNil(imageView, "UIImageView should be present on the storyboard")
}

func testTextFiledPresence() {

let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let textField = viewController.fileNameNoExtension
let textFieldExt = viewController.ext

XCTAssertNotNil(textField, "FileNameNoExtention TextFiled should be present on the storyboard")
XCTAssertNotNil(textFieldExt, "Extension TextFiled should be present on the storyboard")

}



}
7 changes: 2 additions & 5 deletions iOSClient/Data/NCManageDatabase+LocalFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,15 @@ extension NCManageDatabase {
}
}

func setLocalFile(ocId: String, fileName: String?, etag: String?) {
func setLocalFile(ocId: String, fileName: String?) {

do {
let realm = try Realm()
try realm.write {
let result = realm.objects(tableLocalFile.self).filter("ocId == %@", ocId).first
if let fileName = fileName {
if let fileName {
result?.fileName = fileName
}
if let etag = etag {
result?.etag = etag
}
}
} catch let error {
NextcloudKit.shared.nkCommonInstance.writeLog("Could not write to database: \(error)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCopyFile), object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCreateFolder), object: nil)

NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
Expand Down
23 changes: 9 additions & 14 deletions iOSClient/Networking/NCNetworking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1633,27 +1633,22 @@ class NCNetworking: NSObject, NKCommonDelegate {

NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNamePath, serverUrlFileNameDestination: fileNameToPath, overwrite: false) { _, error in
if error == .success {
NCManageDatabase.shared.renameMetadata(fileNameTo: fileNameNew, ocId: metadata.ocId)
if metadata.directory {
let serverUrl = self.utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)
let serverUrlTo = self.utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: fileNameNew)
if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) {
NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, serverUrlTo: serverUrlTo, etag: "", ocId: nil, fileId: nil, encrypted: directory.e2eEncrypted, richWorkspace: nil, account: metadata.account)
}
} else {
do {
try FileManager.default.removeItem(atPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId))
} catch { }
NCManageDatabase.shared.deleteVideo(metadata: metadata)
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
// LIVE PHOTO SERVER
if let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata), metadataLive.isFlaggedAsLivePhotoByServer {
do {
try FileManager.default.removeItem(atPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(metadataLive.ocId))
} catch { }
NCManageDatabase.shared.deleteVideo(metadata: metadataLive)
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadataLive.ocId))
NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadataLive.ocId))
if (metadata.fileName as NSString).pathExtension != (fileNameNew as NSString).pathExtension {
let path = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)
self.utilityFileSystem.removeFile(atPath: path)
} else {
NCManageDatabase.shared.setLocalFile(ocId: metadata.ocId, fileName: fileNameNew)
let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + metadata.fileName
let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + fileNameNew
self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath)
}
}
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRenameFile, userInfo: ["ocId": metadata.ocId, "account": metadata.account, "indexPath": indexPath])
Expand Down
Loading