Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
Finish __clone
  • Loading branch information
Ian MacLennan authored and elinw committed Nov 17, 2011
1 parent 3202485 commit da3eaa5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
16 changes: 12 additions & 4 deletions libraries/joomla/database/databasequery.php
Expand Up @@ -116,9 +116,13 @@ public function getElements()
*/
public function __clone()
{
if (is_object($v) || is_array($v))
foreach ($this as $k => $v)
{
$this->{$k} = unserialize(serialize($v));

if (is_object($v) || is_array($v))
{
$this->{$k} = unserialize(serialize($v));
}
}
}
}
Expand Down Expand Up @@ -1169,9 +1173,13 @@ public function where($conditions, $glue = 'AND')
*/
public function __clone()
{
if (is_object($v) || is_array($v))
foreach ($this as $k => $v)
{
$this->{$k} = unserialize(serialize($v));

if (is_object($v) || is_array($v))
{
$this->{$k} = unserialize(serialize($v));
}
}
}
}
6 changes: 4 additions & 2 deletions tests/suite/joomla/database/JDatabaseQueryElementTest.php
Expand Up @@ -236,12 +236,14 @@ public function test__clone_array()

$baseElement = new JDatabaseQueryElement($name = null, $elements = null);

$baseElement->testArray = array('a', 'b', 'c');
$baseElement->testArray = array();

$cloneElement = clone($baseElement);

$baseElement->testArray[] = 'a';

$this->assertFalse($baseElement === $cloneElement);
$this->assertFalse($baseElement->testArray === $cloneElement->testArray);
$this->assertEquals(count($cloneElement->testArray), 0);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/suite/joomla/database/JDatabaseQueryTest.php
Expand Up @@ -1282,17 +1282,16 @@ public function testWhere()
*/
public function test__clone_array()
{
$baseElement = new JDatabaseQueryInspector($this->getMockDatabase());



$baseElement = new JDatabaseQueryInspector($this->dbo);

$baseElement->testArray = array('a', 'b', 'c');
$baseElement->testArray = array();

$cloneElement = clone($baseElement);

$baseElement->testArray[] = 'test';

$this->assertFalse($baseElement === $cloneElement);
$this->assertFalse($baseElement->testArray === $cloneElement->testArray);
$this->assertTrue(count($cloneElement->testArray) == 0);
}

/**
Expand All @@ -1304,13 +1303,14 @@ public function test__clone_array()
*/
public function test__clone_object()
{
$baseElement = new JDatabaseQueryInspector($this->getMockDatabase());

$baseElement = new JDatabaseQueryInspector($this->dbo);

$baseElement->testObject = new stdClass;

$cloneElement = clone($baseElement);

$this->assertFalse($baseElement === $cloneElement);

$this->assertFalse($baseElement->testObject === $cloneElement->testObject);
}
}

0 comments on commit da3eaa5

Please sign in to comment.