Started unit tests for condition and argument classes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8577 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-07-07 14:34:56 +00:00
parent 7112d518c8
commit 76019a4b2b
15 changed files with 537 additions and 108 deletions

View file

@ -0,0 +1,232 @@
<?php
/**
* Test class for Argument.
* Generated by PHPUnit on 2011-07-07 at 16:51:29.
*/
class ArgumentTest extends CubridTest {
/**
* @todo Implement testGetType().
*/
public function testGetType() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testSetColumnType().
*/
public function testSetColumnType() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGetName().
*/
public function testGetName() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGetValue().
*/
public function testGetValue() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGetUnescapedValue().
*/
public function testGetUnescapedValue() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testToString().
*/
public function testToString() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testEscapeValue().
*/
public function testEscapeValue() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testIsValid().
*/
public function testIsValid() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGetErrorMessage().
*/
public function testGetErrorMessage() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testEnsureDefaultValue().
*/
public function testEnsureDefaultValue() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testCheckFilter().
*/
public function testCheckFilter() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testCheckMaxLength().
*/
public function testCheckMaxLength() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testCheckMinLength().
*/
public function testCheckMinLength() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* Checks that argument is valid after a notnull check when value is not null
*/
public function testCheckNotNullWhenNotNull() {
$member_srl_argument = new ConditionArgument('member_srl', 20, 'equal');
$member_srl_argument->checkNotNull();
$this->assertEquals(true, $member_srl_argument->isValid());
}
/**
* Checks that argument becomes invalid after a notnull check when value is null
*/
public function testCheckNotNullWhenNull() {
$member_srl_argument = new ConditionArgument('member_srl', null, 'equal');
$member_srl_argument->checkNotNull();
$this->assertEquals(false, $member_srl_argument->isValid());
}
/**
* Checks that argument value stays the same when both user value and default value are given
*/
public function testCheckDefaultValueWhenNotNull() {
$member_srl_argument = new ConditionArgument('member_srl', 20, 'equal');
$member_srl_argument->ensureDefaultValue(25);
$this->assertEquals(20, $member_srl_argument->getValue());
}
/**
* Checks that argument value gets set when user value is null and default value is specified
*/
public function testCheckDefaultValueWhenNull() {
$member_srl_argument = new ConditionArgument('member_srl', null, 'equal');
$member_srl_argument->ensureDefaultValue(25);
$this->assertEquals(25, $member_srl_argument->getValue());
}
/**
* Checks like prefix operation
*/
public function testCreateConditionValue_LikePrefix() {
$member_srl_argument = new ConditionArgument('"mid"', 'forum', 'like_prefix');
$member_srl_argument->createConditionValue();
$this->assertEquals('forum%', $member_srl_argument->getValue());
}
/**
* Checks like tail operation
*/
public function testCreateConditionValue_LikeTail() {
$member_srl_argument = new ConditionArgument('"mid"', 'forum', 'like_tail');
$member_srl_argument->createConditionValue();
$this->assertEquals('%forum', $member_srl_argument->getValue());
}
/**
* Checks like operation
*/
public function testCreateConditionValue_Like() {
$member_srl_argument = new ConditionArgument('"mid"', 'forum', 'like');
$member_srl_argument->createConditionValue();
$this->assertEquals('%forum%', $member_srl_argument->getValue());
}
/**
* Checks in operation
*/
public function testCreateConditionValue_In_StringValues() {
$member_srl_argument = new ConditionArgument('"mid"', array('forum', 'board'), 'in');
$member_srl_argument->createConditionValue();
$this->assertEquals('(\'forum\',\'board\')', $member_srl_argument->getValue());
}
/**
* Checks in operation
*/
public function testCreateConditionValue_In_NumericValues() {
$member_srl_argument = new ConditionArgument('"module_srl"', array(3, 21), 'in');
$member_srl_argument->setColumnType('number');
$member_srl_argument->createConditionValue();
$this->assertEquals('(3,21)', $member_srl_argument->getValue());
}
}
?>

View file

@ -0,0 +1,40 @@
<?php
/**
* Test class for ConditionArgument.
*/
class ConditionArgumentTest extends CubridTest {
/**
* @todo Implement testCreateConditionValue().
*/
public function testCreateConditionValue() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGetType().
*/
public function testGetType() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testSetColumnType().
*/
public function testSetColumnType() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}
?>

View file

@ -0,0 +1,35 @@
<?php
/**
* Test class for QueryArgument.
*/
class QueryArgumentTest extends CubridTest {
var $xmlPath = "data/";
function QueryArgumentClass(){
$this->xmlPath = str_replace('QueryArgumentTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
}
function testNotNullConditionArgument(){
$xml_file = $this->xmlPath . "condition1.xml";
$xml_obj = Helper::getXmlObject($xml_file);
$tag = new QueryArgument($xml_obj->condition);
$this->assertEquals("member_srl", $tag->getArgumentName());
$this->assertEquals("member_srl", $tag->getColumnName());
$this->assertEquals(true, $tag->isConditionArgument());
$actual = $tag->toString();
$expected = ' $member_srl_argument = new ConditionArgument(\'member_srl\', $args->member_srl, \'equal\');
$member_srl_argument->checkNotNull();
$member_srl_argument->createConditionValue();
if(!$member_srl_argument->isValid()) return $member_srl_argument->getErrorMessage();';
$this->assertEquals($expected, $actual);
}
}
?>

View file

@ -0,0 +1 @@
<condition operation="equal" column="member_srl" var="member_srl" notnull="notnull" />

View file

@ -0,0 +1 @@
<index var="sort_index" default="list_order" order="order_type" />

View file

@ -0,0 +1,68 @@
<?php
/**
* Test class for ConditionTag.
*/
class ConditionTagTest extends CubridTest {
var $xmlPath = "data/";
function ConditionTagTest(){
$this->xmlPath = str_replace('ConditionTagTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
}
/**
* Tests a simple <condition> tag:
* <condition operation="equal" column="user_id" var="user_id" />
*/
function testConditionStringWithArgument(){
$xml_file = $this->xmlPath . "condition1.xml";
$xml_obj = Helper::getXmlObject($xml_file);
$tag = new ConditionTag($xml_obj->condition);
$expected = "new Condition('\"user_id\"',\$user_id_argument,\"equal\")";
$actual = $tag->getConditionString();
$this->assertEquals($expected, $actual);
$arguments = $tag->getArguments();
$this->assertEquals(1, count($arguments));
}
/**
* Tests a condition tag for joins - that uses no argument
* <condition operation="equal" column="comments.user_id" default="member.user_id" filter="userid" />
*/
function testConditionStringWithoutArgument(){
$xml_file = $this->xmlPath . "condition3.xml";
$xml_obj = Helper::getXmlObject($xml_file);
$tag = new ConditionTag($xml_obj->condition);
$expected = "new Condition('\"comments\".\"user_id\"','\"member\".\"user_id\"',\"equal\")";
$actual = $tag->getConditionString();
$this->assertEquals($expected, $actual);
$arguments = $tag->getArguments();
$this->assertEquals(0, count($arguments));
}
/**
* Tests a <condition> tag with pipe:
* <condition operation="equal" column="type" var="type" notnull="notnull" pipe="and" />
*/
function testConditionStringWithPipe(){
$xml_file = $this->xmlPath . "condition2.xml";
$xml_obj = Helper::getXmlObject($xml_file);
$tag = new ConditionTag($xml_obj->condition);
$expected = "new Condition('\"type\"',\$type_argument,\"equal\", 'and')";
$actual = $tag->getConditionString();
$this->assertEquals($expected, $actual);
$arguments = $tag->getArguments();
$this->assertEquals(1, count($arguments));
}
}
?>

View file

@ -0,0 +1 @@
<condition operation="equal" column="user_id" var="user_id" />

View file

@ -0,0 +1 @@
<condition operation="equal" column="type" var="type" notnull="notnull" pipe="and" />

View file

@ -0,0 +1 @@
<condition operation="equal" column="comments.user_id" default="member.user_id" filter="userid" />