Skip to content

Commit

Permalink
File Filter unit test coverage for FILES array
Browse files Browse the repository at this point in the history
  • Loading branch information
cgmartin committed Dec 18, 2012
1 parent a107fd0 commit 02702ec
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/ZendTest/Filter/File/DecryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,38 @@ public function testBasic()
trim(file_get_contents(dirname(__DIR__).'/_files/newencryption.txt')));
}

/**
* @return void
*/
public function testBasicWithFileArray()
{
$filter = new FileEncrypt();
$filter->setFilename(dirname(__DIR__).'/_files/newencryption.txt');

$this->assertEquals(
dirname(__DIR__).'/_files/newencryption.txt',
$filter->getFilename());

$filter->setVector('1234567890123456');
$filter->filter(array('tmp_name' => dirname(__DIR__).'/_files/encryption.txt'));

$filter = new FileDecrypt();

$this->assertNotEquals(
'Encryption',
file_get_contents(dirname(__DIR__).'/_files/newencryption.txt'));

$filter->setVector('1234567890123456');
$this->assertEquals(
array('tmp_name' => dirname(__DIR__).'/_files/newencryption.txt'),
$filter->filter(array('tmp_name' => dirname(__DIR__).'/_files/newencryption.txt'))
);

$this->assertEquals(
'Encryption',
trim(file_get_contents(dirname(__DIR__).'/_files/newencryption.txt')));
}

public function testEncryptionWithDecryption()
{
$filter = new FileEncrypt();
Expand Down
27 changes: 27 additions & 0 deletions tests/ZendTest/Filter/File/EncryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ public function testBasic()
file_get_contents(dirname(__DIR__).'/_files/newencryption.txt'));
}

/**
* @return void
*/
public function testBasicWithFileArray()
{
$filter = new FileEncrypt();
$filter->setFilename(dirname(__DIR__).'/_files/newencryption.txt');

$this->assertEquals(
dirname(__DIR__).'/_files/newencryption.txt',
$filter->getFilename());

$filter->setVector('1234567890123456');
$this->assertEquals(
array('tmp_name' => dirname(__DIR__).'/_files/newencryption.txt'),
$filter->filter(array('tmp_name' => dirname(__DIR__).'/_files/encryption.txt'))
);

$this->assertEquals(
'Encryption',
file_get_contents(dirname(__DIR__).'/_files/encryption.txt'));

$this->assertNotEquals(
'Encryption',
file_get_contents(dirname(__DIR__).'/_files/newencryption.txt'));
}

public function testEncryptionWithDecryption()
{
$filter = new FileEncrypt();
Expand Down
11 changes: 11 additions & 0 deletions tests/ZendTest/Filter/File/LowerCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public function testInstanceCreationAndNormalWorkflow()
$this->assertContains('this is a file', file_get_contents($this->_newFile));
}

/**
* @return void
*/
public function testNormalWorkflowWithFilesArray()
{
$this->assertContains('This is a File', file_get_contents($this->_newFile));
$filter = new FileLowerCase();
$filter(array('tmp_name' => $this->_newFile));
$this->assertContains('this is a file', file_get_contents($this->_newFile));
}

/**
* @return void
*/
Expand Down
25 changes: 25 additions & 0 deletions tests/ZendTest/Filter/File/RenameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,31 @@ public function testConstructSingleValue()
$this->assertEquals('falsefile', $filter('falsefile'));
}

/**
* Test single parameter filter
*
* @return void
*/
public function testConstructSingleValueWithFilesArray()
{
$filter = new FileRename($this->_newFile);

$this->assertEquals(
array(0 => array(
'source' => '*',
'target' => $this->_newFile,
'overwrite' => false,
'randomize' => false,
)),
$filter->getFile()
);
$this->assertEquals(
array('tmp_name' => $this->_newFile),
$filter(array('tmp_name' => $this->_oldFile))
);
$this->assertEquals('falsefile', $filter('falsefile'));
}

/**
* Test single array parameter filter
*
Expand Down
25 changes: 25 additions & 0 deletions tests/ZendTest/Filter/File/RenameUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,31 @@ public function testConstructSingleValue()
$this->assertEquals('falsefile', $filter('falsefile'));
}

/**
* @return void
*/
public function testConstructSingleValueWithFilesArray()
{
$this->setUpMockMoveUploadedFile();

$filter = new FileRenameUpload($this->_newFile);

$this->assertEquals(
array(0 => array(
'source' => '*',
'target' => $this->_newFile,
'overwrite' => false,
'randomize' => false,
)),
$filter->getFile()
);
$this->assertEquals(
array('tmp_name' => $this->_newFile),
$filter(array('tmp_name' => $this->_oldFile))
);
$this->assertEquals('falsefile', $filter('falsefile'));
}

/**
* Test single array parameter filter
*
Expand Down
11 changes: 11 additions & 0 deletions tests/ZendTest/Filter/File/UpperCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public function testInstanceCreationAndNormalWorkflow()
$this->assertContains('THIS IS A FILE', file_get_contents($this->_newFile));
}

/**
* @return void
*/
public function testNormalWorkflowWithFilesArray()
{
$this->assertContains('This is a File', file_get_contents($this->_newFile));
$filter = new FileUpperCase();
$filter(array('tmp_name' => $this->_newFile));
$this->assertContains('THIS IS A FILE', file_get_contents($this->_newFile));
}

/**
* @return void
*/
Expand Down

0 comments on commit 02702ec

Please sign in to comment.