Merge pull request #420 from adamgsoc2013/UT_transform2

add test case for Text_Plain_$type classes
This commit is contained in:
Michal Čihař 2013-06-13 23:54:23 -07:00
commit c602e34ceb
10 changed files with 1349 additions and 0 deletions

View File

@ -0,0 +1,150 @@
<?php
/**
* Tests for Text_Plain_Dateformat class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Text_Plain_Dateformat.class.php';
/**
* Tests for Text_Plain_Dateformat class
*
* @package PhpMyAdmin-test
*/
class Text_Plain_Dateformat_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Text_Plain_Dateformat(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info = 'Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp'
. ' column as formatted date. The first option is the offset (in'
. ' hours) which will be added to the timestamp (Default: 0). Use'
. ' second option to specify a different date/time format string.'
. ' Third option determines whether you want to see local date or'
. ' UTC one (use "local" or "utc" strings) for that. According to'
. ' that, date format has different value - for "local" see the'
. ' documentation for PHP\'s strftime() function and for "utc" it'
. ' is done using gmdate() function.';
$this->assertEquals(
$info,
Text_Plain_Dateformat::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"Date Format",
Text_Plain_Dateformat::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Text",
Text_Plain_Dateformat::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"Plain",
Text_Plain_Dateformat::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$timestamp = 12345;
$options = array(0);
$meta = new Text_Plain_Dateformat_Meta();
$meta->type = 'int';
$result = '<dfn onclick="alert(\'12345\');" title="12345">'
. 'Jan 01, 1970 at 04:25 AM</dfn>';
$this->assertEquals(
$result,
$this->object->applyTransformation($timestamp, $options, $meta)
);
}
}
class Text_Plain_Dateformat_Meta
{
var $blob = null;
var $max_length = null;
var $type = null;
}

View File

@ -0,0 +1,138 @@
<?php
/**
* Tests for Application_Octetstream_Download class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Application_Octetstream_Download.class.php';
/**
* Tests for Application_Octetstream_Download class
*
* @package PhpMyAdmin-test
*/
class Application_Octetstream_Download_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Application_Octetstream_Download(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info =
'Displays a link to download the binary data of the column. You can'
. ' use the first option to specify the filename, or use the second'
. ' option as the name of a column which contains the filename. If'
. ' you use the second option, you need to set the first option to'
. ' the empty string.';
$this->assertEquals(
$info,
Application_Octetstream_Download::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"Download",
Application_Octetstream_Download::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Application",
Application_Octetstream_Download::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"OctetStream",
Application_Octetstream_Download::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = "PMA_BUFFER";
$options = array("filename", 'wrapper_link'=>'PMA_wrapper_link');
$result = '<a href="transformation_wrapper.phpPMA_wrapper_link'
. '&amp;ct=application/octet-stream&amp;cn=filename" '
. 'title="filename">filename</a>';
$this->assertEquals(
$result,
$this->object->applyTransformation($buffer, $options)
);
}
}

View File

@ -0,0 +1,142 @@
<?php
/**
* Tests for Text_Plain_External class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Text_Plain_External.class.php';
/**
* Tests for Text_Plain_External class
*
* @package PhpMyAdmin-test
*/
class Text_Plain_External_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Text_Plain_External(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info =
'LINUX ONLY: Launches an external application and feeds it the column'
. ' data via standard input. Returns the standard output of the'
. ' application. The default is Tidy, to pretty-print HTML code.'
. ' For security reasons, you have to manually edit the file'
. ' libraries/plugins/transformations/Text_Plain_External'
. '.class.php and list the tools you want to make available.'
. ' The first option is then the number of the program you want to'
. ' use and the second option is the parameters for the program.'
. ' The third option, if set to 1, will convert the output using'
. ' htmlspecialchars() (Default 1). The fourth option, if set to 1,'
. ' will prevent wrapping and ensure that the output appears all on'
. ' one line (Default 1).';
$this->assertEquals(
$info,
Text_Plain_External::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"External",
Text_Plain_External::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Text",
Text_Plain_External::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"Plain",
Text_Plain_External::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = "PMA_BUFFER";
$options = array("/dev/null -i -wrap -q", "/dev/null -i -wrap -q");
$this->assertEquals(
"PMA_BUFFER",
$this->object->applyTransformation($buffer, $options)
);
}
}

View File

@ -0,0 +1,133 @@
<?php
/**
* Tests for Text_Plain_Formatted class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Text_Plain_Formatted.class.php';
/**
* Tests for Text_Plain_Formatted class
*
* @package PhpMyAdmin-test
*/
class Text_Plain_Formatted_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Text_Plain_Formatted(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info =
'Displays the contents of the column as-is, without running it'
. ' through htmlspecialchars(). That is, the column is assumed'
. ' to contain valid HTML.';
$this->assertEquals(
$info,
Text_Plain_Formatted::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"Formatted",
Text_Plain_Formatted::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Text",
Text_Plain_Formatted::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"Plain",
Text_Plain_Formatted::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = "<a ref='http://ci.phpmyadmin.net/'>PMA_BUFFER</a>";
$options = array("option1", "option2");
$this->assertEquals(
$buffer,
$this->object->applyTransformation($buffer, $options)
);
}
}

View File

@ -0,0 +1,140 @@
<?php
/**
* Tests for Application_Octetstream_Hex class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Application_Octetstream_Hex.class.php';
/**
* Tests for Application_Octetstream_Hex class
*
* @package PhpMyAdmin-test
*/
class Application_Octetstream_Hex_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Application_Octetstream_Hex(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info =
'Displays hexadecimal representation of data. Optional first'
. ' parameter specifies how often space will be added (defaults'
. ' to 2 nibbles).';
$this->assertEquals(
$info,
Application_Octetstream_Hex::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"Hex",
Application_Octetstream_Hex::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Application",
Application_Octetstream_Hex::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"OctetStream",
Application_Octetstream_Hex::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = "11111001";
$options = array(3);
$this->assertEquals(
"313 131 313 130 303 1 ",
$this->object->applyTransformation($buffer, $options)
);
$buffer = "11111001";
$options = array(0);
$this->assertEquals(
"3131313131303031",
$this->object->applyTransformation($buffer, $options)
);
}
}

View File

@ -0,0 +1,136 @@
<?php
/**
* Tests for Text_Plain_Imagelink class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Text_Plain_Imagelink.class.php';
/**
* Tests for Text_Plain_Imagelink class
*
* @package PhpMyAdmin-test
*/
class Text_Plain_Imagelink_test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Text_Plain_Imagelink(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info = 'Displays an image and a link; '
. 'the column contains the filename. The first option'
. ' is a URL prefix like "http://www.example.com/". The second and third options'
. ' are the width and the height in pixels.';
$this->assertEquals(
$info,
Text_Plain_Imagelink::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"Image Link",
Text_Plain_Imagelink::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Text",
Text_Plain_Imagelink::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"Plain",
Text_Plain_Imagelink::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = "PMA_IMAGE";
$options = array("./image/", "200");
$result = '<a href="./image/PMA_IMAGE" target="_blank">'
. '<img src="./image/PMA_IMAGE" border="0" width="200" '
. 'height="50" />PMA_IMAGE</a>';
$this->assertEquals(
$result,
$this->object->applyTransformation($buffer, $options)
);
}
}

View File

@ -0,0 +1,135 @@
<?php
/**
* Tests for Text_Plain_Link class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Text_Plain_Link.class.php';
/**
* Tests for Text_Plain_Link class
*
* @package PhpMyAdmin-test
*/
class Text_Plain_Link_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Text_Plain_Link(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info =
'Displays a link; the column contains the filename. The first option'
. ' is a URL prefix like "http://www.example.com/". The second option'
. ' is a title for the link.';
$this->assertEquals(
$info,
Text_Plain_Link::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"TextLink",
Text_Plain_Link::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Text",
Text_Plain_Link::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"Plain",
Text_Plain_Link::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = "PMA_TXT_LINK";
$options = array("./php/", "text_name");
$result = '<a href="./php/PMA_TXT_LINK"'
. ' title="text_name" target="_new">text_name</a>';
$this->assertEquals(
$result,
$this->object->applyTransformation($buffer, $options)
);
}
}

View File

@ -0,0 +1,131 @@
<?php
/**
* Tests for Text_Plain_Longtoipv4 class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Text_Plain_Longtoipv4.class.php';
/**
* Tests for Text_Plain_Longtoipv4 class
*
* @package PhpMyAdmin-test
*/
class Text_Plain_Longtoipv4_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Text_Plain_Longtoipv4(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info = 'Converts an (IPv4) Internet network address into a string in'
. ' Internet standard dotted format.';
$this->assertEquals(
$info,
Text_Plain_Longtoipv4::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"Long To IPv4",
Text_Plain_Longtoipv4::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Text",
Text_Plain_Longtoipv4::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"Plain",
Text_Plain_Longtoipv4::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = 42949672;
$options = array("option1", "option2");
$this->assertEquals(
"2.143.92.40",
$this->object->applyTransformation($buffer, $options)
);
}
}

View File

@ -0,0 +1,131 @@
<?php
/**
* Tests for Text_Plain_Sql class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Text_Plain_Sql.class.php';
/**
* Tests for Text_Plain_Sql class
*
* @package PhpMyAdmin-test
*/
class Text_Plain_Sql_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Text_Plain_Sql(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getInfo
*
* @return void
*
* @group medium
*/
public function testGetInfo()
{
$info = 'Formats text as SQL query with syntax highlighting.';
$this->assertEquals(
$info,
Text_Plain_Sql::getInfo()
);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"SQL",
Text_Plain_Sql::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Text",
Text_Plain_Sql::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"Plain",
Text_Plain_Sql::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = "select *";
$options = array("option1", "option2");
$result = '<code class="sql"><pre>select *</pre></code>';
$this->assertEquals(
$result,
$this->object->applyTransformation($buffer, $options)
);
}
}

View File

@ -0,0 +1,113 @@
<?php
/**
* Tests for Text_Plain_Substring class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
/* Each PluginObserver instance contains a PluginManager instance */
require_once 'libraries/plugins/PluginManager.class.php';
require_once 'libraries/plugins/transformations/Text_Plain_Substring.class.php';
/**
* Tests for Text_Plain_Substring class
*
* @package PhpMyAdmin-test
*/
class Text_Plain_Substring_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Text_Plain_Substring(new PluginManager());
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for getName
*
* @return void
*
* @group medium
*/
public function testGetName()
{
$this->assertEquals(
"Substring",
Text_Plain_Substring::getName()
);
}
/**
* Test for getMIMEType
*
* @return void
*
* @group medium
*/
public function testGetMIMEType()
{
$this->assertEquals(
"Text",
Text_Plain_Substring::getMIMEType()
);
}
/**
* Test for getMIMESubtype
*
* @return void
*
* @group medium
*/
public function testGetMIMESubtype()
{
$this->assertEquals(
"Plain",
Text_Plain_Substring::getMIMESubtype()
);
}
/**
* Test for applyTransformation
*
* @return void
*
* @group medium
*/
public function testApplyTransformation()
{
$buffer = "PMA_BUFFER";
$options = array(1, 3, 'suffix');
$this->assertEquals(
"suffixMA_suffix",
$this->object->applyTransformation($buffer, $options)
);
}
}