Skip to content
This repository
Browse code

BUGFIX: fixed asserts and file cleanup

DataObject::get_one returns false if not found, so better check for
object. Also, the directory would not be cleaned, so on the subsequent
run the files could end up having suffixes.

missed this one
  • Loading branch information...
commit a2c9c409a8d76214a189a054e8996179a905ca91 1 parent a1327fa
Mateusz U authored April 18, 2012
10  tests/forms/uploadfield/UploadFieldTest.php
@@ -28,7 +28,7 @@ function testUploadNoRelation() {
28 28
 		$this->assertFalse($response->isError());
29 29
 		$this->assertFileExists(ASSETS_PATH . "/UploadFieldTest/$tmpFileName");
30 30
 		$uploadedFile = DataObject::get_one('File', sprintf('"Name" = \'%s\'', $tmpFileName));
31  
-		$this->assertNotNull($uploadedFile);
  31
+		$this->assertTrue(is_object($uploadedFile), 'The file object is created');
32 32
 	}
33 33
 
34 34
 	function testUploadHasOneRelation() {
@@ -48,7 +48,7 @@ function testUploadHasOneRelation() {
48 48
 		$this->assertFalse($response->isError());
49 49
 		$this->assertFileExists(ASSETS_PATH . "/UploadFieldTest/$tmpFileName");
50 50
 		$uploadedFile = DataObject::get_one('File', sprintf('"Name" = \'%s\'', $tmpFileName));
51  
-		$this->assertNotNull($uploadedFile);
  51
+		$this->assertTrue(is_object($uploadedFile), 'The file object is created');
52 52
 
53 53
 		$record = DataObject::get_by_id($record->class, $record->ID, false);
54 54
 		$this->assertTrue($record->HasOneFile()->exists());
@@ -69,7 +69,7 @@ function testUploadHasManyRelation() {
69 69
 		$this->assertFalse($response->isError());
70 70
 		$this->assertFileExists(ASSETS_PATH . "/UploadFieldTest/$tmpFileName");
71 71
 		$uploadedFile = DataObject::get_one('File', sprintf('"Name" = \'%s\'', $tmpFileName));
72  
-		$this->assertNotNull($uploadedFile);
  72
+		$this->assertTrue(is_object($uploadedFile), 'The file object is created');
73 73
 
74 74
 		$record = DataObject::get_by_id($record->class, $record->ID, false);
75 75
 		$this->assertEquals(3, $record->HasManyFiles()->Count());
@@ -91,7 +91,7 @@ function testUploadManyManyRelation() {
91 91
 		$this->assertFalse($response->isError());
92 92
 		$this->assertFileExists(ASSETS_PATH . "/UploadFieldTest/$tmpFileName");
93 93
 		$uploadedFile = DataObject::get_one('File', sprintf('"Name" = \'%s\'', $tmpFileName));
94  
-		$this->assertNotNull($uploadedFile);
  94
+		$this->assertTrue(is_object($uploadedFile), 'The file object is created');
95 95
 
96 96
 		$record = DataObject::get_by_id($record->class, $record->ID, false);
97 97
 		$this->assertEquals($relationCount+1, $record->ManyManyFiles()->Count());
@@ -605,7 +605,7 @@ function tearDown() {
605 605
 		}
606 606
 
607 607
 		// Remove left over folders and any files that may exist
608  
-		if(file_exists('../assets/UploadFieldTest')) Filesystem::removeFolder('../assets/FileTest');
  608
+		if(file_exists('../assets/UploadFieldTest')) Filesystem::removeFolder('../assets/UploadFieldTest');
609 609
 	}
610 610
 
611 611
 }

0 notes on commit a2c9c40

Please sign in to comment.
Something went wrong with that request. Please try again.