Ejemplo n.º 1
0
 /**
  * Create an API provider for entity "Widget" with action "frobnicate".
  *
  * @return Provider\ProviderInterface
  */
 public function createWidgetFrobnicateProvider()
 {
     $provider = new \Civi\API\Provider\AdhocProvider(self::MOCK_VERSION, 'Widget');
     $provider->addAction('frobnicate', 'access CiviCRM', function ($apiRequest) {
         return civicrm_api3_create_success(array(98 => 'frob'));
     });
     return $provider;
 }
Ejemplo n.º 2
0
 public function testBasicArrayGetReturn()
 {
     $records = array(array('snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'), array('snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'), array('snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'));
     $kernel = new \Civi\API\Kernel(new \Symfony\Component\EventDispatcher\EventDispatcher());
     $provider = new \Civi\API\Provider\AdhocProvider(3, 'Widget');
     $provider->addAction('get', 'access CiviCRM', function ($apiRequest) use($records) {
         return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', array('snack_id', 'fruit', 'cheese'));
     });
     $kernel->registerApiProvider($provider);
     $r1 = $kernel->run('Widget', 'get', array('version' => 3, 'snack_id' => 'b', 'return' => 'fruit'));
     $this->assertAPISuccess($r1);
     $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape')), $r1['values']);
     $r2 = $kernel->run('Widget', 'get', array('version' => 3, 'snack_id' => 'b', 'return' => array('fruit', 'cheese')));
     $this->assertAPISuccess($r2);
     $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar')), $r2['values']);
     $r3 = $kernel->run('Widget', 'get', array('version' => 3, 'cheese' => 'cheddar', 'return' => array('fruit')));
     $this->assertAPISuccess($r3);
     $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape'), 'c' => array('id' => 'c', 'fruit' => 'apple')), $r3['values']);
 }