mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 22:13:13 +00:00
Delete api_* class tests
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
class api_oauthv2_AccountTest extends \PhraseanetTestCase
|
||||
{
|
||||
/**
|
||||
* @var ApiApplication
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->object = self::$DI['app']['repo.api-accounts']->findByUserAndApplication(self::$DI['user'], self::$DI['oauth2-app-user']);
|
||||
}
|
||||
|
||||
public function testGettersAndSetters()
|
||||
{
|
||||
$this->assertTrue(is_int($this->object->getId()));
|
||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $this->object->getUser());
|
||||
$this->assertEquals(self::$DI['user']->getId(), $this->object->getUser()->getId());
|
||||
|
||||
$this->assertEquals('1.0', $this->object->getApiVersion());
|
||||
|
||||
$this->assertTrue(is_bool($this->object->isRevoked()));
|
||||
|
||||
$this->object->set_revoked(true);
|
||||
$this->assertTrue($this->object->isRevoked());
|
||||
$this->object->set_revoked(false);
|
||||
$this->assertFalse($this->object->isRevoked());
|
||||
|
||||
$this->assertInstanceOf('DateTime', $this->object->getCreated());
|
||||
$this->assertInstanceOf('ApiApplication', $this->object->getApplication());
|
||||
$this->assertEquals(self::$DI['oauth2-app-user'], $this->object->getApplication());
|
||||
}
|
||||
|
||||
public function testLoad_with_user()
|
||||
{
|
||||
$loaded = self::$DI['app']['repo.api-accounts']->findByUserAndApplication(self::$DI['user'], self::$DI['oauth2-app-user']);
|
||||
$this->assertInstanceOf('ApiAccount', $loaded);
|
||||
$this->assertEquals($this->object, $loaded);
|
||||
}
|
||||
}
|
@@ -1,108 +0,0 @@
|
||||
<?php
|
||||
use Alchemy\Phrasea\Model\Entities\ApiApplication;
|
||||
|
||||
class api_oauthv2_ApplicationTest extends \PhraseanetTestCase
|
||||
{
|
||||
public function testLoad_from_client_id()
|
||||
{
|
||||
$loaded = self::$DI['app']['repo.api-applications']->findByClientId(self::$DI['oauth2-app-user']->getClientId());
|
||||
$this->assertInstanceOf('ApiApplication', $loaded);
|
||||
$this->assertEquals(self::$DI['oauth2-app-user'], $loaded);
|
||||
}
|
||||
|
||||
public function testLoad_dev_app_by_user()
|
||||
{
|
||||
$apps = self::$DI['app']['repo.api-applications']->findByCreator(self::$DI['user']);
|
||||
$this->assertTrue(is_array($apps));
|
||||
$this->assertTrue(count($apps) > 0);
|
||||
$found = false;
|
||||
foreach ($apps as $app) {
|
||||
if ($app->get_id() === self::$DI['oauth2-app-user']->getId()) {
|
||||
$found = true;
|
||||
}
|
||||
$this->assertInstanceOf('ApiApplication', $app);
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$this->fail();
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoad_app_by_user()
|
||||
{
|
||||
$apps = self::$DI['app']['repo.api-applications']->findByUser(self::$DI['user']);
|
||||
$this->assertTrue(is_array($apps));
|
||||
$this->assertTrue(count($apps) > 0);
|
||||
$found = false;
|
||||
|
||||
foreach ($apps as $app) {
|
||||
if ($app->get_id() === self::$DI['oauth2-app-user']->getId()) {
|
||||
$found = true;
|
||||
}
|
||||
$this->assertInstanceOf('ApiApplication', $app);
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$this->fail();
|
||||
}
|
||||
}
|
||||
|
||||
public function testGettersAndSetters()
|
||||
{
|
||||
$this->assertTrue(is_int(self::$DI['oauth2-app-user']->getId()));
|
||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', self::$DI['oauth2-app-user']->getCreator());
|
||||
$this->assertEquals(self::$DI['user']->getId(), self::$DI['oauth2-app-user']->getCreator()->getId());
|
||||
$this->assertTrue(in_array(self::$DI['oauth2-app-user']->getType(), [ApiApplication::DESKTOP_TYPE, ApiApplication::WEB_TYPE]));
|
||||
$this->assertTrue(is_string(self::$DI['oauth2-app-user']->getNonce()));
|
||||
$this->assertEquals(64, strlen(self::$DI['oauth2-app-user']->getNonce()));
|
||||
self::$DI['oauth2-app-user']->setType(ApiApplication::WEB_TYPE);
|
||||
$this->assertEquals(ApiApplication::WEB_TYPE, self::$DI['oauth2-app-user']->getType());
|
||||
self::$DI['oauth2-app-user']->setType(ApiApplication::DESKTOP_TYPE);
|
||||
$this->assertEquals(ApiApplication::DESKTOP_TYPE, self::$DI['oauth2-app-user']->getType());
|
||||
$this->assertEquals(ApiApplication::NATIVE_APP_REDIRECT_URI, self::$DI['oauth2-app-user']->getRedirectUri());
|
||||
self::$DI['oauth2-app-user']->setType(ApiApplication::WEB_TYPE);
|
||||
|
||||
self::$DI['oauth2-app-user']->setName('prout');
|
||||
$this->assertEquals('prout', self::$DI['oauth2-app-user']->getName());
|
||||
self::$DI['oauth2-app-user']->setName('test application for user');
|
||||
$this->assertEquals('test application for user', self::$DI['oauth2-app-user']->getName());
|
||||
|
||||
$desc = 'prouti prouto prout prout';
|
||||
self::$DI['oauth2-app-user']->setDescription($desc);
|
||||
$this->assertEquals($desc, self::$DI['oauth2-app-user']->getDescription());
|
||||
self::$DI['oauth2-app-user']->setDescription('');
|
||||
$this->assertEquals('', self::$DI['oauth2-app-user']->getDescription());
|
||||
|
||||
$site = 'http://www.example.com/';
|
||||
self::$DI['oauth2-app-user']->setWebsite($site);
|
||||
$this->assertEquals($site, self::$DI['oauth2-app-user']->getWebsite());
|
||||
self::$DI['oauth2-app-user']->setWebsite('');
|
||||
$this->assertEquals('', self::$DI['oauth2-app-user']->getWebsite());
|
||||
|
||||
$this->assertInstanceOf('DateTime', self::$DI['oauth2-app-user']->getCreated());
|
||||
$this->assertInstanceOf('DateTime', self::$DI['oauth2-app-user']->getUpdated());
|
||||
|
||||
$this->assertMd5(self::$DI['oauth2-app-user']->getClientId());
|
||||
|
||||
$client_id = md5('prouto');
|
||||
self::$DI['oauth2-app-user']->seClientId($client_id);
|
||||
$this->assertEquals($client_id, self::$DI['oauth2-app-user']->getClientId());
|
||||
$this->assertMd5(self::$DI['oauth2-app-user']->getClientId());
|
||||
|
||||
$this->assertMd5(self::$DI['oauth2-app-user']->getClientSecret());
|
||||
|
||||
$client_secret = md5('prouto');
|
||||
self::$DI['oauth2-app-user']->setClientSecret($client_secret);
|
||||
$this->assertEquals($client_secret, self::$DI['oauth2-app-user']->getClientSecret());
|
||||
$this->assertMd5(self::$DI['oauth2-app-user']->getClientSecret());
|
||||
|
||||
$uri = 'http://www.example.com/callback/';
|
||||
self::$DI['oauth2-app-user']->setRedirectUri($uri);
|
||||
$this->assertEquals($uri, self::$DI['oauth2-app-user']->getRedirectUri());
|
||||
}
|
||||
|
||||
private function assertmd5($md5)
|
||||
{
|
||||
$this->assertTrue((count(preg_match('/[a-z0-9]{32}/', $md5)) === 1));
|
||||
}
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
|
||||
<?php
|
||||
|
||||
class api_oauthv2_AuthCodeTest extends \PhraseanetTestCase
|
||||
{
|
||||
/**
|
||||
* @var API_OAuth2_AuthCode
|
||||
*/
|
||||
protected $object;
|
||||
protected $code;
|
||||
|
||||
protected $account;
|
||||
protected $application;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->account = self::$DI['app']['repo.api-accounts']->findByUserAndApplication(self::$DI['user'], self::$DI['oauth2-app-user']);
|
||||
$expires = time() + 100;
|
||||
$this->code = self::$DI['app']['random.low']->generateString(8);
|
||||
$this->object = API_OAuth2_AuthCode::create(self::$DI['app'], $this->account, $this->code, $expires);
|
||||
}
|
||||
|
||||
public function testGet_code()
|
||||
{
|
||||
$this->assertEquals($this->code, $this->object->get_code());
|
||||
}
|
||||
|
||||
public function testGet_account()
|
||||
{
|
||||
$this->assertInstanceOf('ApiApplication', $this->object->get_account());
|
||||
}
|
||||
|
||||
public function testGet_redirect_uri()
|
||||
{
|
||||
$this->assertEquals('', $this->object->get_redirect_uri());
|
||||
}
|
||||
|
||||
public function testSet_redirect_uri()
|
||||
{
|
||||
$redirect_uri = 'https://www.google.com';
|
||||
$this->assertEquals('', $this->object->get_redirect_uri());
|
||||
$this->object->set_redirect_uri($redirect_uri);
|
||||
$this->assertEquals($redirect_uri, $this->object->get_redirect_uri());
|
||||
}
|
||||
|
||||
public function testGet_expires()
|
||||
{
|
||||
$this->assertInternalType('string', $this->object->get_expires());
|
||||
}
|
||||
|
||||
public function testGet_scope()
|
||||
{
|
||||
$this->assertEquals('', $this->object->get_scope());
|
||||
}
|
||||
|
||||
public function testSet_scope()
|
||||
{
|
||||
$scope = 'prout';
|
||||
$this->assertEquals('', $this->object->get_scope());
|
||||
$this->object->set_scope($scope);
|
||||
$this->assertEquals($scope, $this->object->get_scope());
|
||||
}
|
||||
|
||||
public function testLoad_codes_by_account()
|
||||
{
|
||||
$this->assertTrue(is_array(API_OAuth2_AuthCode::load_codes_by_account(self::$DI['app'], $this->account)));
|
||||
$this->assertTrue(count(API_OAuth2_AuthCode::load_codes_by_account(self::$DI['app'], $this->account)) > 0);
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
class api_oauthv2_RefreshTokenTest extends \PhraseanetTestCase
|
||||
{
|
||||
/**
|
||||
* @var API_OAuth2_RefreshToken
|
||||
*/
|
||||
protected $object;
|
||||
protected $token;
|
||||
protected $scope;
|
||||
|
||||
protected $account;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->account = self::$DI['app']['repo.api-accounts']->findByUserAndApplication(self::$DI['user'], self::$DI['oauth2-app-user']);
|
||||
$expires = time() + 100;
|
||||
$this->token = self::$DI['app']['random.low']->generateString(8);
|
||||
$this->scope = 'scopidou';
|
||||
|
||||
$this->object = API_OAuth2_RefreshToken::create(self::$DI['app'], $this->account, $expires, $this->token, $this->scope);
|
||||
}
|
||||
|
||||
public function testGet_value()
|
||||
{
|
||||
$this->assertEquals($this->token, $this->object->get_value());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_account().
|
||||
*/
|
||||
public function testGet_account()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_expires().
|
||||
*/
|
||||
public function testGet_expires()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testGet_scope().
|
||||
*/
|
||||
public function testGet_scope()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testLoad_by_account().
|
||||
*/
|
||||
public function testLoad_by_account()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement testCreate().
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
class api_oauthv2_TokenTest extends \PhraseanetTestCase
|
||||
{
|
||||
/**
|
||||
* @var API_OAuth2_Token
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$account = self::$DI['app']['repo.api-accounts']->findByUserAndApplication(self::$DI['user'], self::$DI['oauth2-app-user']);
|
||||
|
||||
try {
|
||||
new API_OAuth2_Token(self::$DI['app']['phraseanet.appbox'], $account, self::$DI['app']['random.medium']);
|
||||
$this->fail();
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
$this->object = API_OAuth2_Token::create(self::$DI['app']['phraseanet.appbox'], $account, self::$DI['app']['random.medium']);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->object->delete();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
private function assertmd5($md5)
|
||||
{
|
||||
$this->assertTrue((count(preg_match('/[a-z0-9]{32}/', $md5)) === 1));
|
||||
}
|
||||
|
||||
public function testGettersAndSetters()
|
||||
{
|
||||
$this->assertmd5($this->object->get_value());
|
||||
|
||||
$value = md5('prout');
|
||||
$this->object->set_value($value);
|
||||
$this->assertEquals($value, $this->object->get_value());
|
||||
|
||||
$this->object->set_session_id(null);
|
||||
$this->assertNull($this->object->get_session_id());
|
||||
|
||||
$this->object->set_session_id(458);
|
||||
$this->assertEquals(458, $this->object->get_session_id());
|
||||
|
||||
$expire = time() + 3600;
|
||||
$this->object->set_expires($expire);
|
||||
$diff = (int) $this->object->get_expires() - time();
|
||||
$this->assertSame($expire, $this->object->get_expires(), "expiration timestamp is string : " . $this->object->get_expires());
|
||||
$this->assertTrue($diff > 3500, "expire value $diff should be more than 3500 seconds ");
|
||||
$this->assertTrue($diff < 3700, "expire value $diff should be less than 3700 seconds ");
|
||||
|
||||
$date = time() + 7200;
|
||||
$this->object->set_expires($date);
|
||||
$this->assertEquals($date, $this->object->get_expires());
|
||||
|
||||
$this->assertNull($this->object->get_scope());
|
||||
|
||||
$this->assertNull($this->object->get_scope());
|
||||
$scope = "prout";
|
||||
$this->object->set_scope($scope);
|
||||
$this->assertEquals($scope, $this->object->get_scope());
|
||||
|
||||
$this->assertInstanceOf('ApiApplication', $this->object->get_account());
|
||||
}
|
||||
|
||||
public function testRenew()
|
||||
{
|
||||
$first = $this->object->get_value();
|
||||
$this->assertMd5($first);
|
||||
$this->object->renew();
|
||||
$second = $this->object->get_value();
|
||||
$this->assertMd5($second);
|
||||
$this->assertNotEquals($second, $first);
|
||||
}
|
||||
|
||||
public function testLoad_by_oauth_token()
|
||||
{
|
||||
$token = $this->object->get_value();
|
||||
$loaded = API_OAuth2_Token::load_by_oauth_token(self::$DI['app'], $token);
|
||||
$this->assertInstanceOf('API_OAuth2_Token', $loaded);
|
||||
$this->assertEquals($this->object, $loaded);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user