|
| 1 | +<?php |
| 2 | +/*========================================================================= |
| 3 | +MIDAS Server |
| 4 | +Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved. |
| 5 | +69328 Lyon, FRANCE. |
| 6 | +
|
| 7 | +See Copyright.txt for details. |
| 8 | +This software is distributed WITHOUT ANY WARRANTY; without even |
| 9 | +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 10 | +PURPOSE. See the above copyright notices for more information. |
| 11 | +=========================================================================*/ |
| 12 | +/** ItemmetricModelTest*/ |
| 13 | +class ItemmetricModelTest extends DatabaseTestCase |
| 14 | + { |
| 15 | + |
| 16 | + /** init test*/ |
| 17 | + public function setUp() |
| 18 | + { |
| 19 | + $this->enabledModules = array('batchmake'); |
| 20 | + parent::setUp(); |
| 21 | + $this->setupDatabase(array('default'), 'batchmake'); // module dataset |
| 22 | + } |
| 23 | + |
| 24 | + /** Test that ItemmetricModel::createTask($userDao) works */ |
| 25 | + public function testCreateItemmetric() |
| 26 | + { |
| 27 | + $usersFile = $this->loadData('User', 'default', '', 'batchmake'); |
| 28 | + |
| 29 | + $modelLoad = new MIDAS_ModelLoader(); |
| 30 | + $itemmetricModel = $modelLoad->loadModel('Itemmetric', 'batchmake'); |
| 31 | + $user1Dao = $usersFile[0]; |
| 32 | + |
| 33 | + |
| 34 | + // create an itemmetric |
| 35 | + $metricName = 'metrictest1'; |
| 36 | + $bmsName = 'metrictest1.bms'; |
| 37 | + $itemmetric1Dao = $itemmetricModel->createItemmetric($metricName, $bmsName); |
| 38 | + // check the dao is correct |
| 39 | + $this->assertNotEmpty($itemmetric1Dao); |
| 40 | + $this->assertTrue($itemmetric1Dao instanceof Batchmake_ItemmetricDao); |
| 41 | + // check that what we passed in is what we got out |
| 42 | + $this->assertEquals($metricName, $itemmetric1Dao->getMetricName()); |
| 43 | + $this->assertEquals($bmsName, $itemmetric1Dao->getBmsName()); |
| 44 | + // now try to retrieve it by key |
| 45 | + $key = $itemmetric1Dao->getKey(); |
| 46 | + $dupDao = $itemmetricModel->load($key); |
| 47 | + $this->assertTrue($itemmetricModel->compareDao($itemmetric1Dao, $dupDao)); |
| 48 | + |
| 49 | + // now try creating another one with the same name, see that it fails |
| 50 | + try |
| 51 | + { |
| 52 | + $itemmetricDaoDup = $itemmetricModel->createItemmetric($metricName, $bmsName); |
| 53 | + $this->fail('Expected an exception for '.$metricName.', but did not get one.'); |
| 54 | + } |
| 55 | + catch(Zend_Exception $ze) |
| 56 | + { |
| 57 | + // if we got here, this is the correct behavior |
| 58 | + $this->assertTrue(true); |
| 59 | + } |
| 60 | + |
| 61 | + // be sure we can create one with a different name |
| 62 | + $metricName2 = 'metrictest2'; |
| 63 | + $bmsName2 = 'metrictest2.bms'; |
| 64 | + $itemmetricDao2 = $itemmetricModel->createItemmetric($metricName2, $bmsName2); |
| 65 | + // check the dao is correct |
| 66 | + $this->assertNotEmpty($itemmetricDao2); |
| 67 | + $this->assertTrue($itemmetricDao2 instanceof Batchmake_ItemmetricDao); |
| 68 | + // check that what we passed in is what we got out |
| 69 | + $this->assertEquals($metricName2, $itemmetricDao2->getMetricName()); |
| 70 | + $this->assertEquals($bmsName2, $itemmetricDao2->getBmsName()); |
| 71 | + // now try to retrieve it by key |
| 72 | + $key = $itemmetricDao2->getKey(); |
| 73 | + $dupDao = $itemmetricModel->load($key); |
| 74 | + $this->assertTrue($itemmetricModel->compareDao($itemmetricDao2, $dupDao)); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * tests getAll abstract function |
| 79 | + */ |
| 80 | + public function testGetAll() |
| 81 | + { |
| 82 | + $itemmetricFileDaos = $this->loadData('Itemmetric', 'default', 'batchmake', 'batchmake'); |
| 83 | + |
| 84 | + $modelLoad = new MIDAS_ModelLoader(); |
| 85 | + $itemmetricModel = $modelLoad->loadModel('Itemmetric', 'batchmake'); |
| 86 | + $modelDaos = $itemmetricModel->getAll(); |
| 87 | + |
| 88 | + // now check that each of the itemmetrics in the file are loaded as daos |
| 89 | + foreach($itemmetricFileDaos as $fileDao) |
| 90 | + { |
| 91 | + $found = false; |
| 92 | + foreach($modelDaos as $modelDao) |
| 93 | + { |
| 94 | + if($itemmetricModel->compareDao($modelDao, $fileDao)) |
| 95 | + { |
| 96 | + $found = true; |
| 97 | + break; |
| 98 | + } |
| 99 | + } |
| 100 | + if(!$found) |
| 101 | + { |
| 102 | + $this->fail("Did not find a testdata itemmetric , with getAll"); |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + |
| 108 | + } |
0 commit comments