This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test tracker scalar API endpoints for cloven params
- Loading branch information
mgrauer
committed
Oct 1, 2015
1 parent
36d04fa
commit 19c5ce2
Showing
3 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
modules/tracker/tests/controllers/ApiScalarComponentTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/*========================================================================= | ||
Midas Server | ||
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France. | ||
All rights reserved. | ||
For more information visit http://www.kitware.com/. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
=========================================================================*/ | ||
|
||
require_once BASE_PATH.'/core/tests/controllers/api/RestCallMethodsTestCase.php'; | ||
|
||
/** API test for tracker module ApiscalarComponent. */ | ||
class Tracker_ApiScalarComponentTest extends RestCallMethodsTestCase | ||
{ | ||
public $moduleName = 'tracker'; | ||
|
||
/** Setup. */ | ||
public function setUp() | ||
{ | ||
$this->enabledModules = array('api', 'scheduler', $this->moduleName); | ||
$this->_models = array('Assetstore', 'Community', 'Setting', 'User'); | ||
|
||
$this->setupDatabase(array('default')); | ||
$this->setupDatabase(array('default'), 'tracker'); | ||
|
||
ControllerTestCase::setUp(); | ||
} | ||
|
||
/** | ||
* Test updating an existing scalar with a set of params, via PUT. | ||
* | ||
* @throws Zend_Exception | ||
*/ | ||
public function testPUT() | ||
{ | ||
$usersFile = $this->loadData('User', 'default'); | ||
$userDao = $this->User->load($usersFile[0]->getKey()); | ||
|
||
// Create a scalar attached to a trend. | ||
|
||
$trendModel = MidasLoader::loadModel('Trend', 'tracker'); | ||
$trend = $trendModel->load(1); | ||
|
||
$scalarModel = MidasLoader::loadModel('Scalar', 'tracker'); | ||
$scalarArgs = array( | ||
'trend_id' => $trend->getTrendId(), | ||
'value' => 42, | ||
'build_results_url' => 'http://localhost', | ||
); | ||
$scalar = $scalarModel->initDao('Scalar', $scalarArgs, $this->moduleName); | ||
$scalarModel->save($scalar); | ||
|
||
$token = $this->_loginAsAdministrator(); | ||
|
||
$params = array( | ||
'num_param' => 90, | ||
'text_param' => 'master', | ||
'null_param' => '', | ||
); | ||
$restParams = array( | ||
'trend_id' => $trend->getTrendId(), | ||
'params' => json_encode($params), | ||
'token' => $token, | ||
); | ||
|
||
$this->resetAll(); | ||
$this->params = $restParams; | ||
$resp = $this->_callRestApi('PUT', '/tracker/scalar/'.$scalar->getScalarId()); | ||
|
||
// Ensure params are properly set on scalar. | ||
|
||
$paramChecks = array( | ||
'num_param' => array('found' => false, 'type' => 'numeric', 'val' => 90), | ||
'text_param' => array('found' => false, 'type' => 'text', 'val' => 'master'), | ||
'null_param' => array('found' => false, 'type' => 'text', 'val' => ''), | ||
); | ||
|
||
foreach ($scalar->getParams() as $param) { | ||
$checks = $paramChecks[$param->getParamName()]; | ||
$this->assertEquals($checks['type'], $param->getParamType()); | ||
if ($checks['type'] === 'numeric') { | ||
$this->assertEquals($checks['val'], $param->getNumericValue()); | ||
} else { | ||
$this->assertEquals($checks['val'], $param->getTextValue()); | ||
} | ||
$paramChecks[$param->getParamName()]['found'] = true; | ||
} | ||
|
||
foreach ($paramChecks as $checks) { | ||
$this->assertTrue($checks['found']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters