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

Commit 8c71e48

Browse files
author
Michael Grauer
committed
BUG: Refs #0283. Fixed AssetstoreModelTest failures by adding type juggling.
Pgsql and Mysql have different behaviors related to the type of data, so in order to use compareDao in these tests across the two db systems I added an option to MIDASModel to compare dao objects with typejuggling, leaving the default behavior to not type juggle. These tests call compareDao with typejuggling.
1 parent 0348efa commit 8c71e48

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

core/models/MIDASModel.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function getCountAll()
376376
* @param $dao2
377377
* @return True ifthey are the same one
378378
*/
379-
public function compareDao($dao1, $dao2)
379+
public function compareDao($dao1, $dao2, $juggleTypes = false)
380380
{
381381
if(!is_object($dao1) || !is_object($dao2))
382382
{
@@ -386,10 +386,20 @@ public function compareDao($dao1, $dao2)
386386
{
387387
if($data['type'] == MIDAS_DATA)
388388
{
389-
if($dao1->get($name) !== $dao2->get($name))
389+
if($juggleTypes)
390390
{
391-
return false;
391+
if($dao1->get($name) != $dao2->get($name))
392+
{
393+
return false;
394+
}
392395
}
396+
else
397+
{
398+
if($dao1->get($name) !== $dao2->get($name))
399+
{
400+
return false;
401+
}
402+
}
393403
}
394404
}
395405
return true;

core/tests/models/base/AssetstoreModelTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,15 @@ public function testSave()
9494

9595
// create new ones with a different path from existing ones
9696

97-
$assetstoreDao1 = $this->validSaveTestcase('test_assetstore_1', '/testassetstore1/path', 0);
98-
$assetstoreDao2 = $this->validSaveTestcase('test_assetstore_2', '/testassetstore2/path', 1);
99-
$assetstoreDao3 = $this->validSaveTestcase('test_assetstore_3', '/testassetstore3/path', 2);
97+
$assetstoreDao1 = $this->validSaveTestcase('test_assetstore_1', '/testassetstore1/path', '0');
98+
$assetstoreDao2 = $this->validSaveTestcase('test_assetstore_2', '/testassetstore2/path', '1');
99+
$assetstoreDao3 = $this->validSaveTestcase('test_assetstore_3', '/testassetstore3/path', '2');
100100

101101
// make sure one got saved
102102
$found = $this->Assetstore->findBy('name', 'test_assetstore_3');
103103
$this->assertNotEmpty($found);
104104
$savedDao = $found[0];
105-
// explicit cast to get around differences in mysql vs pgsql type handling
106-
$savedDao->type = (int)$savedDao->type;
107-
$this->assertTrue($this->Assetstore->compareDao($assetstoreDao3, $savedDao));
105+
$this->assertTrue($this->Assetstore->compareDao($assetstoreDao3, $savedDao, true));
108106

109107
// Incorrect Create Tests
110108

@@ -153,9 +151,7 @@ public function testSave()
153151
$found = $this->Assetstore->findBy('name', $newName);
154152
$this->assertNotEmpty($found);
155153
$foundDao = $found[0];
156-
// explicit cast to get around differences in mysql vs pgsql type handling
157-
$foundDao->type = (int)$foundDao->type;
158-
$this->assertTrue($this->Assetstore->compareDao($foundDao, $assetstoreDao1));
154+
$this->assertTrue($this->Assetstore->compareDao($foundDao, $assetstoreDao1, true));
159155
$this->assertEquals($foundDao->getName(), $newName);
160156
$assetstoreDao1->setName($savedName);
161157

@@ -169,9 +165,7 @@ public function testSave()
169165
$found = $this->Assetstore->findBy('path', $newPath);
170166
$this->assertNotEmpty($found);
171167
$foundDao = $found[0];
172-
// explicit cast to get around differences in mysql vs pgsql type handling
173-
$foundDao->type = (int)$foundDao->type;
174-
$this->assertTrue($this->Assetstore->compareDao($foundDao, $assetstoreDao1));
168+
$this->assertTrue($this->Assetstore->compareDao($foundDao, $assetstoreDao1, true));
175169
$this->assertEquals($foundDao->getPath(), $newPath);
176170
$assetstoreDao1->setPath($savedPath);
177171

0 commit comments

Comments
 (0)