Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: refs #862. Add testing for new controller actions
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmullen committed Nov 1, 2012
1 parent 959e8f8 commit 92588a2
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 5 deletions.
14 changes: 12 additions & 2 deletions core/controllers/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,24 @@ public function appletAction()
{
if($itemId)
{
$items[] = $this->Item->load($itemId);
$item = $this->Item->load($itemId);
if(!$this->Item->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_READ))
{
throw new Zend_Exception('Invalid policy on item '.$itemId, 403);
}
$items[] = $item;
}
}
foreach($folderIdArray as $folderId)
{
if($folderId)
{
$folders[] = $this->Folder->load($folderId);
$folder = $this->Folder->load($folderId);
if(!$this->Folder->policyCheck($folder, $this->userSession->Dao, MIDAS_POLICY_READ))
{
throw new Zend_Exception('Invalid policy on folder '.$folderId, 403);
}
$folders[] = $folder;
}
}
$totalSize = 0;
Expand Down
6 changes: 3 additions & 3 deletions core/controllers/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function getnameAction()
{
throw new Zend_Exception('Read permission required', 403);
}
print $folder->getName();
echo $folder->getName();
}

/**
Expand Down Expand Up @@ -88,11 +88,11 @@ function javachildrenAction()

foreach($childFolders as $childFolder)
{
print 'f '.$childFolder->getKey().' '.$childFolder->getName()."\n";
echo 'f '.$childFolder->getKey().' '.$childFolder->getName()."\n";
}
foreach($childItems as $childItem)
{
print 'i '.$childItem->getKey().' '.$childItem->getName()."\n";
echo 'i '.$childItem->getKey().' '.$childItem->getName()."\n";
}
}

Expand Down
44 changes: 44 additions & 0 deletions core/tests/controllers/FolderControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,48 @@ public function testRemoveItemAction()
$items = $folder->getItems();
$this->assertTrue(count($items) === $count - 1);
}

/** Test the getname action used by the large downloader applet */
public function testGetnameAction()
{
$usersFile = $this->loadData('User', 'default');
$userWithPermission = $this->User->load(1);
$folderPub = $this->Folder->load(1001);
$folderPriv = $this->Folder->load(1002);

// anon user shouldn't be able to get the folder name on a private folder
$this->dispatchUri('/folder/getname?id='.$folderPriv->getKey(), null, true);

// anon user should be able to get the folder name of a public folder
$this->resetAll();
$this->dispatchUri('/folder/getname?id='.$folderPub->getKey(), null);
$this->assertEquals(trim($this->getBody()), trim($folderPub->getName()));

// user with read access should be able to get name of private folder
$this->resetAll();
$this->dispatchUri('/folder/getname?id='.$folderPriv->getKey(), $userWithPermission);
$this->assertEquals(trim($this->getBody()), trim($folderPriv->getName()));
}

/** Test action used by the large download applet to list children info */
public function testJavachildrenAction()
{
$usersFile = $this->loadData('User', 'default');
$userWithPermission = $this->User->load(1);
$folderPub = $this->Folder->load(1001);
$folderPriv = $this->Folder->load(1002);

// anon user shouldn't be able to access on a private folder
$this->dispatchUri('/folder/javachildren?id='.$folderPriv->getKey(), null, true);

// anon user should be able to access on a public folder
$this->resetAll();
$this->dispatchUri('/folder/javachildren?id='.$folderPub->getKey(), null);
$this->assertEquals(trim($this->getBody()), 'i 1000 name 1');

// user with read access should be able access on a private folder
$this->resetAll();
$this->dispatchUri('/folder/javachildren?id='.$folderPriv->getKey(), $userWithPermission);
$this->assertEquals(trim($this->getBody()), '');
}
}
58 changes: 58 additions & 0 deletions core/tests/controllers/UploadDownloadControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,62 @@ function testActiveDownloadLocking()
$this->assertTrue($lock instanceof ActivedownloadDao);
$this->assertNotEquals($lock->getKey(), $oldLock->getKey());
}

/** Test the checksize method */
function testChecksizeAction()
{
$adminUser = $this->User->load(3);
// anon user should throw an exception if no permission on the folder
$this->dispatchUri('/download/checksize?folderIds=1002', null, true);

$this->resetAll();
$this->dispatchUri('/download/checksize?folderIds=1001', $adminUser);
$json = json_decode($this->getBody(), true);
$this->assertTrue(isset($json['action']));
$this->assertEquals($json['action'], 'download'); //below the threshold

$this->resetAll();
$this->dispatchUri('/download/checksize?folderIds=1002', $adminUser);
$json = json_decode($this->getBody(), true);
$this->assertTrue(isset($json['action']));
$this->assertEquals($json['action'], 'download'); //below the threshold

$this->resetAll();
$this->dispatchUri('/download/checksize?itemIds=1000', null);
$json = json_decode($this->getBody(), true);
$this->assertTrue(isset($json['action']));
$this->assertEquals($json['action'], 'download'); //below the threshold

$this->resetAll();
$item = $this->Item->load(1000);
$item->setSizebytes(1342177280); //1.25 GB
$this->Item->save($item);
$this->dispatchUri('/download/checksize?itemIds=1000', null);
$json = json_decode($this->getBody(), true);
$this->assertTrue(isset($json['action']));
$this->assertEquals($json['action'], 'promptApplet'); //now above the threshold
$this->assertEquals($json['sizeStr'], '1.3 GB'); //should round to 1 decimal place
}

/** Test rendering of the large downloader view */
function testAppletAction()
{
$adminUser = $this->User->load(3);
$this->dispatchUri('/download/applet?folderIds=1002', null, true);

$this->resetAll();
$this->dispatchUri('/download/applet?folderIds=1002', $adminUser);
$this->assertQuery('param[name="itemIds"]');
$this->assertQuery('param[name="folderIds"][value="1002"]');
$this->assertQuery('param[name="totalSize"][value="0"]');

$this->resetAll();
$item = $this->Item->load(1000);
$item->setSizebytes(1342177280); //1.25 GB
$this->Item->save($item);
$this->dispatchUri('/download/applet?itemIds=1000', $adminUser);
$this->assertQuery('param[name="itemIds"][value="1000"]');
$this->assertQuery('param[name="folderIds"]');
$this->assertQuery('param[name="totalSize"][value="1342177280"]');
}
}

0 comments on commit 92588a2

Please sign in to comment.