<?php
/*
+--------------------------------------------------------------------+
-| CiviCRM version 4.5 |
+| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
require_once 'CiviTest/CiviUnitTestCase.php';
class api_v3_OptionValueTest extends CiviUnitTestCase {
protected $_apiversion = 3;
- function setUp() {
+ public function setUp() {
parent::setUp();
+ $this->useTransaction(TRUE);
}
- function tearDown() {}
-
-
public function testGetCount() {
$result = $this->callAPISuccess('option_value', 'getcount', array());
$this->assertGreaterThan(100, $result);
/**
* Test limit param
*/
- function testGetOptionValueLimit() {
+ public function testGetOptionValueLimit() {
$params = array();
$result = $this->callAPISuccess('option_value', 'get', $params);
$this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__);
/**
* Test offset param
*/
- function testGetOptionValueOffSet() {
+ public function testGetOptionValueOffSet() {
$result = $this->callAPISuccess('option_value', 'get', array(
'option_group_id' => 1,
- 'value' => '1', ));
+ 'value' => '1',
+ ));
$result2 = $this->callAPISuccess('option_value', 'get', array(
'option_group_id' => 1,
- 'value' => '1',
- 'options' => array('offset' => 1),
- ));
+ 'value' => '1',
+ 'options' => array('offset' => 1),
+ ));
$this->assertGreaterThan($result2['count'], $result['count']);
}
/**
* Test offset param
*/
- function testGetSingleValueOptionValueSort() {
+ public function testGetSingleValueOptionValueSort() {
$description = "demonstrates use of Sort param (available in many api functions). Also, getsingle";
- $subfile = 'SortOption';
- $result = $this->callAPISuccess('option_value', 'getsingle', array(
- 'option_group_id' => 1, 'options' => array(
- 'sort' => 'label ASC',
- 'limit' => 1,
- ),
- ));
+ $subfile = 'SortOption';
+ $result = $this->callAPISuccess('option_value', 'getsingle', array(
+ 'option_group_id' => 1,
+ 'options' => array(
+ 'sort' => 'label ASC',
+ 'limit' => 1,
+ ),
+ ));
$params = array(
- 'option_group_id' => 1, 'options' => array(
+ 'option_group_id' => 1,
+ 'options' => array(
'sort' => 'label DESC',
'limit' => 1,
),
/**
* Try to emulate a pagination: fetch the first page of 10 options, then fetch the second page with an offset of 9 (instead of 10) and check the start of the second page is the end of the 1st one.
*/
- function testGetValueOptionPagination() {
+ public function testGetValueOptionPagination() {
$pageSize = 10;
- $page1 = $this->callAPISuccess('option_value', 'get', array('options' => array('limit' => $pageSize), ));
+ $page1 = $this->callAPISuccess('option_value', 'get', array('options' => array('limit' => $pageSize)));
$page2 = $this->callAPISuccess('option_value', 'get', array(
- 'options' => array('limit' => $pageSize,
- // if you use it for pagination, option.offset=pageSize*pageNumber
- 'offset' => $pageSize - 1,
- ), ));
+ 'options' => array(
+ 'limit' => $pageSize,
+ // if you use it for pagination, option.offset=pageSize*pageNumber
+ 'offset' => $pageSize - 1,
+ ),
+ ));
$this->assertEquals($pageSize, $page1['count'], "Check only 10 retrieved in the 1st page " . __LINE__);
$this->assertEquals($pageSize, $page2['count'], "Check only 10 retrieved in the 2nd page " . __LINE__);
'name' => 'from_email_address',
'sequential' => 1,
'api.option_value.create' => array('domain_id' => 2, 'name' => 'my@y.com'),
- ));
+ ));
$optionValueId = $result['values'][0]['api.option_value.create']['id'];
$domain_id = $this->callAPISuccess('option_value', 'getvalue', array(
public function testCreateOptionSpecifyComponentID() {
$result = $this->callAPISuccess('option_group', 'get', array(
'name' => 'from_email_address',
- 'sequential' => 1, 'api.option_value.create' => array('component_id' => 2, 'name' => 'my@y.com'),
+ 'sequential' => 1,
+ 'api.option_value.create' => array('component_id' => 2, 'name' => 'my@y.com'),
));
$this->assertAPISuccess($result);
$optionValueId = $result['values'][0]['api.option_value.create']['id'];
$component_id = $this->callAPISuccess('option_value', 'getvalue', array(
- 'id' => $optionValueId, 'return' => 'component_id',
+ 'id' => $optionValueId,
+ 'return' => 'component_id',
));
$this->assertEquals(2, $component_id);
}
public function testCreateOptionSpecifyComponent() {
$result = $this->callAPISuccess('option_group', 'get', array(
'name' => 'from_email_address',
- 'sequential' => 1, 'api.option_value.create' => array(
+ 'sequential' => 1,
+ 'api.option_value.create' => array(
'component_id' => 'CiviContribute',
- 'name' => 'my@y.com'
- ),
+ 'name' => 'my@y.com',
+ ),
));
$this->assertAPISuccess($result);
$optionValueId = $result['values'][0]['api.option_value.create']['id'];
$component_id = $this->callAPISuccess('option_value', 'getvalue', array(
- 'id' => $optionValueId, 'return' => 'component_id',
+ 'id' => $optionValueId,
+ 'return' => 'component_id',
));
$this->assertEquals(2, $component_id);
}
public function testCreateOptionSpecifyComponentString() {
$result = $this->callAPISuccess('option_group', 'get', array(
'name' => 'from_email_address',
- 'sequential' => 1, 'api.option_value.create' => array(
+ 'sequential' => 1,
+ 'api.option_value.create' => array(
'component_id' => 'CiviContribute',
- 'name' => 'my@y.com'),
+ 'name' => 'my@y.com',
+ ),
));
$this->assertAPISuccess($result);
$optionValueId = $result['values'][0]['api.option_value.create']['id'];
$component_id = $this->callAPISuccess('option_value', 'getvalue', array(
- 'id' => $optionValueId, 'return' => 'component_id',
+ 'id' => $optionValueId,
+ 'return' => 'component_id',
));
$this->assertEquals(2, $component_id);
}
public function testCRM12133CreateOptionWeightNoValue() {
$optionGroup = $this->callAPISuccess(
'option_group', 'get', array(
- 'name' => 'gender',
- 'sequential' => 1, ));
+ 'name' => 'gender',
+ 'sequential' => 1,
+ )
+ );
$this->assertAPISuccess($optionGroup);
$params = array(
'option_group_id' => $optionGroup['id'],
- 'label' => 'my@y.com', 'weight' => 3,
+ 'label' => 'my@y.com',
+ 'weight' => 3,
);
- $optionValue = $this->callAPISuccess('option_value', 'create', $params);
+ $optionValue = $this->callAPISuccess('option_value', 'create', $params);
$this->assertAPISuccess($optionValue);
$params['weight'] = 4;
- $optionValue2 = $this->callAPISuccess('option_value', 'create', $params );
+ $optionValue2 = $this->callAPISuccess('option_value', 'create', $params);
$this->assertAPISuccess($optionValue2);
$options = $this->callAPISuccess('option_value', 'get', array('option_group_id' => $optionGroup['id']));
$this->assertNotEquals($options['values'][$optionValue['id']]['value'], $options['values'][$optionValue2['id']]['value']);
- //cleanup
+ //cleanup
$this->callAPISuccess('option_value', 'delete', array('id' => $optionValue['id']));
$this->callAPISuccess('option_value', 'delete', array('id' => $optionValue2['id']));
}
public function testCreateOptionNoName() {
$optionGroup = $this->callAPISuccess('option_group', 'get', array(
'name' => 'gender',
- 'sequential' => 1, ));
+ 'sequential' => 1,
+ ));
$params = array('option_group_id' => $optionGroup['id'], 'label' => 'my@y.com');
- $optionValue = $this->callAPISuccess('option_value', 'create', $params);
+ $optionValue = $this->callAPISuccess('option_value', 'create', $params);
$this->assertAPISuccess($optionValue);
$this->getAndCheck($params, $optionValue['id'], 'option_value');
}
* and deleted
*/
public function testCRM11876CreateOptionPseudoConstantUpdated() {
- $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array( 'name' => 'payment_instrument',
+ $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array(
+ 'name' => 'payment_instrument',
'return' => 'id',
));
$newOption = (string) time();
array('option_group_id' => $og['id'], 'label' => 'test option value')
);
// update option value without 'option_group_id'
- $res = $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0));
+ $res = $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0));
$val = $this->callAPISuccess('option_value', 'getvalue', array(
- 'id' => $ov['id'], 'return' => 'is_active',
+ 'id' => $ov['id'],
+ 'return' => 'is_active',
));
$this->assertEquals($val, 0, "update with no group id is not proper" . __LINE__);
}
*/
public function testUpdateOptionValueWithGroupId() {
// create a option group
- $og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group for with group id', 'is_active' => 1));
+ $og = $this->callAPISuccess('option_group', 'create', array(
+ 'name' => 'our test Option Group for with group id',
+ 'is_active' => 1,
+ ));
// create a option value
$ov = $this->callAPISuccess('option_value', 'create',
array('option_group_id' => $og['id'], 'label' => 'test option value')
);
// update option value without 'option_group_id'
- $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'option_group_id' => $og['id'], 'is_active' => 0));
+ $this->callAPISuccess('option_value', 'create', array(
+ 'id' => $ov['id'],
+ 'option_group_id' => $og['id'],
+ 'is_active' => 0,
+ ));
$val = $this->callAPISuccess('option_value', 'getvalue', array(
- 'id' => $ov['id'], 'return' => 'is_active',
+ 'id' => $ov['id'],
+ 'return' => 'is_active',
));
$this->assertEquals($val, 0, "update with group id is not proper " . __LINE__);
}
+
}