예제 #1
0
 public function testDeveloperCRUD()
 {
     $developer = new Developer(self::$orgConfig);
     $mail = 'phpunit-' . $this->randomString() . '@example.com';
     // Begin creation
     $developer->blankValues();
     $developer->setEmail($mail);
     $developer->setFirstName($this->randomString());
     $developer->setLastName($this->randomString());
     $developer->setUserName($this->randomString());
     $developer->setAttribute('foo', 'bar');
     try {
         $developer->save();
     } catch (\Exception $e) {
         $this->fail('Cannot save developer at create time: [' . $e->getCode() . '] ' . $e->getMessage());
     }
     $this->assertNotEmpty($developer->getDeveloperId());
     $this->assertEquals($mail, $developer->getEmail());
     $this->assertEquals('bar', $developer->getAttribute('foo'));
     // End creation
     // Begin load
     $developer->blankValues();
     try {
         $developer->load($mail);
     } catch (\Exception $e) {
         $this->fail();
         return;
     }
     $this->assertNotEmpty($developer->getDeveloperId());
     $this->assertEquals($mail, $developer->getEmail());
     $this->assertEquals('bar', $developer->getAttribute('foo'));
     // End load
     // Begin update
     $developer->setAttribute('foo', 'baz');
     try {
         $developer->save(false);
     } catch (\Exception $e) {
         $this->fail('Cannot save developer at update time');
         return;
     }
     $developer->blankValues();
     try {
         $developer->load($mail);
     } catch (\Exception $e) {
         $this->fail('Cannot reload developer after update');
         return;
     }
     $this->assertEquals('baz', $developer->getAttribute('foo'));
     // End update
     // Begin delete
     try {
         $developer->delete();
     } catch (\Exception $e) {
         $this->fail('Cannot delete developer');
     }
     $developer->blankValues();
     try {
         $developer->load($mail);
         // If we succeed in the load, the developer was not deleted.
         $this->fail('Developer deletion failed.');
     } catch (\Exception $e) {
         $this->assertEquals(404, $e->getCode());
     }
     // End delete
 }
예제 #2
0
 public function testAppCRUD()
 {
     $developer = new Developer(self::$orgConfig);
     $mail = 'phpunit-' . $this->randomString() . '@example.com';
     // Create a developer to test on
     $developer->blankValues();
     $developer->setEmail($mail);
     $developer->setFirstName($this->randomString());
     $developer->setLastName($this->randomString());
     $developer->setUserName($this->randomString());
     try {
         $developer->save();
     } catch (\Exception $e) {
         $this->fail('Cannot save developer at create time: [' . $e->getCode() . '] ' . $e->getMessage());
     }
     $apiproduct = new APIProduct(self::$orgConfig);
     $products = $apiproduct->listProducts();
     shuffle($products);
     $product = array_shift($products);
     $new_product = array_shift($products);
     // Begin create
     $app = new DeveloperApp(self::$orgConfig, $mail);
     $app->setName('phpunit test');
     $app->setAccessType('read');
     $app->setCallbackUrl('http://example.com/');
     $app->setApiProducts(array($product->getName()));
     $app->setAttribute('foo', 'bar');
     try {
         $app->save();
     } catch (\Exception $e) {
         $this->fail('Cannot save app at creation time');
     }
     $this->assertNotEmpty($app->getConsumerKey());
     $this->assertNotEmpty($app->getAppId());
     $this->assertEquals('bar', $app->getAttribute('foo'));
     // End create
     // Begin load
     $app->blankValues();
     try {
         $app->load('phpunit test');
     } catch (\Exception $e) {
         $this->fail('Cannot load app.');
         return;
     }
     $this->assertNotEmpty($app->getConsumerKey());
     $this->assertEquals($app->getDeveloperId(), $developer->getDeveloperId());
     // End load
     // Begin update
     $app->setAttribute('foo', 'baz');
     try {
         $app->save(FALSE);
     } catch (\Exception $e) {
         $this->fail('Cannot save app at update time');
         return;
     }
     $app->blankValues();
     try {
         $app->load('phpunit test');
     } catch (\Exception $e) {
         $this->fail('Cannot reload app after update');
         return;
     }
     $this->assertEquals('baz', $app->getAttribute('foo'));
     // End update
     // Update key
     $key = $app->getConsumerKey();
     $new_product_name = $new_product->getName();
     $app->setApiProducts(array($new_product_name));
     try {
         $app->save();
     } catch (\Exception $e) {
         $this->fail('Cannot save app when updating API Products.');
     }
     $api_products = $app->getApiProducts();
     $cred_api_products = $app->getCredentialApiProducts();
     if (count($api_products) != 1 || $api_products[0] != $new_product_name) {
         $this->fail('Failed to update API Products list');
     }
     if (count($cred_api_products) != 1 || $cred_api_products[0]['apiproduct'] != $new_product_name) {
         $this->fail('Failed to update Credential API Products list');
     }
     $this->assertEquals($key, $app->getConsumerKey(), 'Consumer Key changed when API Product changed.');
     // End update key
     // Create key
     $key = $this->randomString(16);
     $secret = $this->randomString(16);
     try {
         $app->createKey($key, $secret);
     } catch (\Exception $e) {
         $this->fail('Cannot create key: ' . $e->getMessage());
         return;
     }
     $app->blankValues();
     $app->load('phpunit test');
     $this->assertEquals($key, $app->getConsumerKey(), 'Consumer Key changed to our custom value.');
     // End create key
     // Begin delete
     try {
         $app->delete();
     } catch (\Exception $e) {
         $this->fail('Cannot delete app');
     }
     $app->blankValues();
     try {
         $app->load($mail);
         // If we succeed in the load, the developer was not deleted.
         $this->fail('App deletion failed.');
     } catch (\Exception $e) {
         $this->assertEquals(404, $e->getCode());
     }
     // End delete
     // Clean up
     try {
         $developer->delete();
     } catch (\Exception $e) {
     }
 }
예제 #3
0
 /**
  * Updates the email address associated with a developer.
  *
  * By default, we do not support changing the developer's email address on
  * the user-profile form -- we disable the element. However, customer-
  * specific code may do so, hence this function.
  *
  * @param \Drupal\devconnect_user\DeveloperEntity $entity
  *   The entity whose email address is to be changed.
  * @param string $new_email
  *   The new email to be assigned to this entity.
  *
  * @return bool
  *   TRUE on success, FALSE on failure.
  */
 public function updateEmail(DeveloperEntity $entity, $new_email)
 {
     $saved = FALSE;
     if (empty($entity->orgNames)) {
         $entity->orgNames = array('default');
     }
     foreach ($entity->orgNames as $org) {
         if (module_exists('devconnect_multiorg')) {
             $org = devconnect_multiorg_find_requested_org($org);
         }
         $config = devconnect_default_org_config($org);
         try {
             $dev = new Developer($config);
             $dev->load($entity->developerId);
             $dev->setEmail($new_email);
             $dev->save(TRUE, $entity->email);
             $saved = TRUE;
             $this->devCache[$entity->developerId] = $dev;
             $entity->email = $new_email;
         } catch (Exception $e) {
             watchdog('devconnect_user', 'Error updating the developer email: %response_message', array('%response_message' => $e->getMessage()), WATCHDOG_ERROR);
         }
     }
     return $saved;
 }