X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fapi%2Fv3%2FEventTest.php;h=1a47f574b0c8f659cc4f10aee4750464ee474648;hb=22e263ad985b62de5cf7bdaf09555bfb3f0cd322;hp=1769fc7f637ff86695690a5a8799b507e93f1779;hpb=8a09f67755f309dcd2c990720c4f792054b77ce9;p=civicrm-core.git diff --git a/tests/phpunit/api/v3/EventTest.php b/tests/phpunit/api/v3/EventTest.php index 1769fc7f63..1a47f574b0 100644 --- a/tests/phpunit/api/v3/EventTest.php +++ b/tests/phpunit/api/v3/EventTest.php @@ -2,7 +2,7 @@ /* +--------------------------------------------------------------------+ - | CiviCRM version 4.5 | + | CiviCRM version 4.6 | +--------------------------------------------------------------------+ | Copyright CiviCRM LLC (c) 2004-2014 | +--------------------------------------------------------------------+ @@ -37,18 +37,7 @@ class api_v3_EventTest extends CiviUnitTestCase { protected $_apiversion; protected $_entity; - /** - * @return array - */ - function get_info() { - return array( - 'name' => 'Event Create', - 'description' => 'Test all Event Create API methods.', - 'group' => 'CiviCRM API Tests', - ); - } - - function setUp() { + public function setUp() { parent::setUp(); $this->_apiversion = 3; $this->_entity = 'event'; @@ -93,11 +82,11 @@ class api_v3_EventTest extends CiviUnitTestCase { array( 'title' => 'Annual CiviCRM meet', 'event_type_id' => 1, - 'start_date' => 20081021, ), + 'start_date' => 20081021, ), array( 'title' => 'Annual CiviCRM meet 2', 'event_type_id' => 1, - 'start_date' => 20101021, ), + 'start_date' => 20101021, ), ); $this->events = array(); @@ -109,7 +98,7 @@ class api_v3_EventTest extends CiviUnitTestCase { } } - function tearDown() { + public function tearDown() { foreach ($this->eventIds as $eventId) { $this->eventDelete($eventId); } @@ -122,14 +111,14 @@ class api_v3_EventTest extends CiviUnitTestCase { ///////////////// civicrm_event_get methods - function testGetEventById() { + public function testGetEventById() { $params = array( 'id' => $this->_events[1]['id'],); $result = $this->callAPISuccess('event', 'get', $params); $this->assertEquals($result['values'][$this->_eventIds[1]]['event_title'], 'Annual CiviCRM meet 2'); } - function testGetEventByEventTitle() { + public function testGetEventByEventTitle() { $params = array( 'event_title' => 'Annual CiviCRM meet', @@ -141,23 +130,23 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->assertEquals($result['values'][0]['id'], $this->_eventIds[0]); } - function testGetEventByWrongTitle() { + public function testGetEventByWrongTitle() { $params = array( 'title' => 'No event with that title',); $result = $this->callAPISuccess('Event', 'Get', $params); $this->assertEquals(0, $result['count']); } - function testGetEventByIdSort() { + public function testGetEventByIdSort() { $params = array( 'return.sort' => 'id ASC', - 'return.max_results' => 1, ); + 'return.max_results' => 1, ); $result = $this->callAPISuccess('Event', 'Get', $params); $this->assertEquals(1, $result['id'], ' in line ' . __LINE__); $params = array( 'options' => array( 'sort' => 'id DESC', 'limit' => 1, - ), ); + ), ); $result = $this->callAPISuccess('Event', 'Get', $params); $this->assertAPISuccess($result, ' in line ' . __LINE__); @@ -166,11 +155,10 @@ class api_v3_EventTest extends CiviUnitTestCase { 'options' => array( 'sort' => 'id ASC', 'limit' => 1, - ), ); + ), ); $result = $this->callAPISuccess('Event', 'Get', $params); $this->assertEquals(1, $result['id'], ' in line ' . __LINE__); - } /* * Getting the id back of an event. @@ -178,7 +166,7 @@ class api_v3_EventTest extends CiviUnitTestCase { */ /* - function testGetIdOfEventByEventTitle() { + public function testGetIdOfEventByEventTitle() { $params = array( 'title' => 'Annual CiviCRM meet', 'return' => 'id' ); @@ -188,14 +176,15 @@ class api_v3_EventTest extends CiviUnitTestCase { */ - /* - * Test 'is.Current' option. Existing event is 'old' so only current should be returned - */ - function testGetIsCurrent() { + /** + * Test 'is.Current' option. Existing event is 'old' so only current should be returned + */ + public function testGetIsCurrent() { $params = array( 'isCurrent' => 1, ); - $currentEventParams = array('start_date' => date('Y-m-d', strtotime('+ 1 day')), + $currentEventParams = array( + 'start_date' => date('Y-m-d', strtotime('+ 1 day')), 'end_date' => date('Y-m-d', strtotime('+ 1 week')), ); $currentEventParams = array_merge($this->_params[1], $currentEventParams); @@ -209,39 +198,42 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__); $this->assertEquals($currentEvent['id'], $result['id'], ''); } -/* - * There has been a schema change & the api needs to buffer developers from it - */ - function testGetPaymentProcessorId() { + + /** + * There has been a schema change & the api needs to buffer developers from it + */ + public function testGetPaymentProcessorId() { $params = $this->_params[0]; $params['payment_processor_id'] = 1; - $params['sequential'] =1; + $params['sequential'] = 1; $result = $this->callAPISuccess('event', 'create', $params); - $this->assertEquals( 1,$result['values'][0]['payment_processor'][0], "handing of payment processor compatibility"); + $this->assertEquals( 1, $result['values'][0]['payment_processor'][0], "handing of payment processor compatibility"); $result = $this->callAPISuccess('event', 'get', $params); - $this->assertEquals($result['values'][0]['payment_processor_id'], 1,"handing get payment processor compatibility"); + $this->assertEquals($result['values'][0]['payment_processor_id'], 1, "handing get payment processor compatibility"); } - function testInvalidData() { + public function testInvalidData() { $params = $this->_params[0]; - $params['sequential'] =1; - $params['loc_block_id'] =100; + $params['sequential'] = 1; + $params['loc_block_id'] = 100; $result = $this->callAPIFailure('event', 'create', $params); } - /* - * Test 'is.Current' option. Existing event is 'old' so only current should be returned - */ - function testGetSingleReturnIsFull() { + /** + * Test 'is.Current' option. Existing event is 'old' so only current should be returned + */ + public function testGetSingleReturnIsFull() { $contactID = $this->individualCreate(); $params = array( - 'id' => $this->_eventIds[0], 'max_participants' => 1, + 'id' => $this->_eventIds[0], + 'max_participants' => 1, ); $result = $this->callAPISuccess('Event', 'Create', $params); $getEventParams = array( - 'id' => $this->_eventIds[0], 'return.is_full' => 1, + 'id' => $this->_eventIds[0], + 'return.is_full' => 1, ); $currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams); @@ -260,9 +252,9 @@ class api_v3_EventTest extends CiviUnitTestCase { * Legacy support for Contribution Type ID. We need to ensure this is supported * as an alias for financial_type_id */ - function testCreateGetEventLegacyContributionTypeID() { + public function testCreateGetEventLegacyContributionTypeID() { $contributionTypeArray = array('contribution_type_id' => 3); - if(isset($this->_params[0]['financial_type_id'])){ + if (isset($this->_params[0]['financial_type_id'])){ //in case someone edits $this->_params & invalidates this test :-) unset($this->_params[0]['financial_type_id']); } @@ -275,12 +267,12 @@ class api_v3_EventTest extends CiviUnitTestCase { ///////////////// civicrm_event_create methods /** - * check with complete array + custom field + * Check with complete array + custom field * Note that the test is written on purpose without any * variables specific to participant so it can be replicated into other entities * and / or moved to the automated test suite */ - function testCreateWithCustom() { + public function testCreateWithCustom() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $params = $this->_params[0]; @@ -299,7 +291,7 @@ class api_v3_EventTest extends CiviUnitTestCase { /** * Test that an event with a price set can be created */ - function testCreatePaidEvent() { + public function testCreatePaidEvent() { //@todo alter API so that an integer is converted to an array $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1); $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params[0], $priceSetParams)); @@ -307,33 +299,33 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->assertArrayKeyExists('price_set_id', $event); } - function testCreateEventParamsNotArray() { + public function testCreateEventParamsNotArray() { $params = NULL; $result = $this->callAPIFailure('event', 'create', $params); } - function testCreateEventEmptyParams() { + public function testCreateEventEmptyParams() { $params = array(); $result = $this->callAPIFailure('event', 'create', $params); } - function testCreateEventParamsWithoutTitle() { + public function testCreateEventParamsWithoutTitle() { unset($this->_params['title']); $result = $this->callAPIFailure('event', 'create', $this->_params); $this->assertAPIFailure($result); } - function testCreateEventParamsWithoutEventTypeId() { + public function testCreateEventParamsWithoutEventTypeId() { unset($this->_params['event_type_id']); $result = $this->callAPIFailure('event', 'create', $this->_params); } - function testCreateEventParamsWithoutStartDate() { + public function testCreateEventParamsWithoutStartDate() { unset($this->_params['start_date']); $result = $this->callAPIFailure('event', 'create', $this->_params); } - function testCreateEventSuccess() { + public function testCreateEventSuccess() { $result = $this->callAPIAndDocument('Event', 'Create', $this->_params[0], __FUNCTION__, __FILE__); $this->assertArrayHasKey('id', $result['values'][$result['id']], 'In line ' . __LINE__); $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id'])); @@ -343,10 +335,11 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__); $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__); } - /* - * Test that passing in Unique field names works - */ - function testCreateEventSuccessUniqueFieldNames() { + + /** + * Test that passing in Unique field names works + */ + public function testCreateEventSuccessUniqueFieldNames() { $this->_params[0]['event_start_date'] = $this->_params[0]['start_date']; unset($this->_params[1]['start_date']); $this->_params[0]['event_title'] = $this->_params[0]['title']; @@ -364,11 +357,12 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->assertEquals($this->_params[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__); } - function testUpdateEvent() { + public function testUpdateEvent() { $result = $this->callAPISuccess('event', 'create', $this->_params[1]); $params = array( - 'id' => $result['id'], 'max_participants' => 150, + 'id' => $result['id'], + 'max_participants' => 150, ); $this->callAPISuccess('Event', 'Create', $params); $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__, __FILE__); @@ -378,11 +372,11 @@ class api_v3_EventTest extends CiviUnitTestCase { } - function testDeleteEmptyParams() { + public function testDeleteEmptyParams() { $result = $this->callAPIFailure('Event', 'Delete', array()); } - function testDelete() { + public function testDelete() { $params = array( 'id' => $this->_eventIds[0], ); @@ -390,18 +384,19 @@ class api_v3_EventTest extends CiviUnitTestCase { } /** - * check event_id still supported for delete + * Check event_id still supported for delete */ - function testDeleteWithEventId() { + public function testDeleteWithEventId() { $params = array( - 'event_id' => $this->_eventIds[0], ); + 'event_id' => $this->_eventIds[0], ); $result = $this->callAPISuccess('Event', 'Delete', $params); $this->assertAPISuccess($result, 'in line ' . __LINE__); } - /* - * Trying to delete an event with participants should return error - */ - function testDeleteWithExistingParticipant() { + + /** + * Trying to delete an event with participants should return error + */ + public function testDeleteWithExistingParticipant() { $contactID = $this->individualCreate(); $participantID = $this->participantCreate( array( @@ -412,7 +407,7 @@ class api_v3_EventTest extends CiviUnitTestCase { $result = $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds[0])); } - function testDeleteWithWrongEventId() { + public function testDeleteWithWrongEventId() { $params = array('event_id' => $this->_eventIds[0]); $result = $this->callAPISuccess('Event', 'Delete', $params); // try to delete again - there's no such event anymore @@ -425,7 +420,7 @@ class api_v3_EventTest extends CiviUnitTestCase { /** * Test civicrm_event_search with wrong params type */ - function testSearchWrongParamsType() { + public function testSearchWrongParamsType() { $params = 'a string'; $result = $this->callAPIFailure('event', 'get', $params); } @@ -433,7 +428,7 @@ class api_v3_EventTest extends CiviUnitTestCase { /** * Test civicrm_event_search with empty params */ - function testSearchEmptyParams() { + public function testSearchEmptyParams() { $event = $this->callAPISuccess('event', 'create', $this->_params[1]); $getparams = array( 'sequential' => 1, @@ -448,12 +443,12 @@ class api_v3_EventTest extends CiviUnitTestCase { /** * Test civicrm_event_search. Success expected. */ - function testSearch() { + public function testSearch() { $params = array( 'event_type_id' => 1, 'return.title' => 1, 'return.id' => 1, - 'return.start_date' => 1, ); + 'return.start_date' => 1, ); $result = $this->callAPISuccess('event', 'get', $params); $this->assertEquals($result['values'][$this->_eventIds[0]]['id'], $this->_eventIds[0], 'In line ' . __LINE__); @@ -464,11 +459,12 @@ class api_v3_EventTest extends CiviUnitTestCase { * Test civicrm_event_search. Success expected. * return.offset and return.max_results test (CRM-5266) */ - function testSearchWithOffsetAndMaxResults() { + public function testSearchWithOffsetAndMaxResults() { $maxEvents = 5; $events = array(); while ($maxEvents > 0) { - $params = array( 'title' => 'Test Event' . $maxEvents, + $params = array( + 'title' => 'Test Event' . $maxEvents, 'event_type_id' => 2, 'start_date' => 20081021, ); @@ -476,7 +472,8 @@ class api_v3_EventTest extends CiviUnitTestCase { $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params); $maxEvents--; } - $params = array( 'event_type_id' => 2, + $params = array( + 'event_type_id' => 2, 'return.id' => 1, 'return.title' => 1, 'return.offset' => 2, @@ -487,9 +484,12 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__); } - function testEventCreationPermissions() { + public function testEventCreationPermissions() { $params = array( - 'event_type_id' => 1, 'start_date' => '2010-10-03', 'title' => 'le cake is a tie', 'check_permissions' => TRUE, ); + 'event_type_id' => 1, + 'start_date' => '2010-10-03', + 'title' => 'le cake is a tie', + 'check_permissions' => TRUE, ); $config = &CRM_Core_Config::singleton(); $config->userPermissionClass->permissions = array('access CiviCRM'); $result = $this->callAPIFailure('event', 'create', $params); @@ -499,32 +499,32 @@ class api_v3_EventTest extends CiviUnitTestCase { $result = $this->callAPISuccess('event', 'create', $params); } - function testgetfields() { - $description = "demonstrate use of getfields to interogate api"; + public function testgetfields() { + $description = "demonstrate use of getfields to interrogate api"; $params = array('action' => 'create'); $result = $this->callAPISuccess('event', 'getfields', $params); $this->assertEquals(1, $result['values']['title']['api.required'], 'in line ' . __LINE__); } - /* - * test api_action param also works - */ - function testgetfieldsRest() { - $description = "demonstrate use of getfields to interogate api"; + + /** + * Test api_action param also works + */ + public function testgetfieldsRest() { + $description = "demonstrate use of getfields to interrogate api"; $params = array('api_action' => 'create'); $result = $this->callAPISuccess('event', 'getfields', $params); $this->assertEquals(1, $result['values']['title']['api.required'], 'in line ' . __LINE__); } - function testgetfieldsGet() { - $description = "demonstrate use of getfields to interogate api"; + public function testgetfieldsGet() { + $description = "demonstrate use of getfields to interrogate api"; $params = array('action' => 'get'); $result = $this->callAPISuccess('event', 'getfields', $params); $this->assertEquals('title', $result['values']['event_title']['name'], 'in line ' . __LINE__); } - function testgetfieldsDelete() { - $description = "demonstrate use of getfields to interogate api"; + public function testgetfieldsDelete() { + $description = "demonstrate use of getfields to interrogate api"; $params = array('action' => 'delete'); $result = $this->callAPISuccess('event', 'getfields', $params); $this->assertEquals(1, $result['values']['id']['api.required']); } } -