mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 12:03:14 +00:00
265 lines
7.9 KiB
PHP
265 lines
7.9 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
|
|
require_once __DIR__ . '/../Bridge_datas.inc';
|
|
|
|
/**
|
|
* Test class for Bridge_Api_Abstract.
|
|
* Generated by PHPUnit on 2011-10-12 at 17:59:33.
|
|
*/
|
|
class Bridge_Api_AbstractTest extends PhraseanetWebTestCaseAuthenticatedAbstract
|
|
{
|
|
|
|
public static $account = null;
|
|
public static $api = null;
|
|
|
|
/**
|
|
* @var Bridge_Api_Abstract
|
|
*/
|
|
protected $auth;
|
|
|
|
/**
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
* This method is called before a test is executed.
|
|
*/
|
|
public function setUp()
|
|
{
|
|
$this->auth = $this->getMock("Bridge_Api_Auth_Interface");
|
|
}
|
|
|
|
/**
|
|
* Tears down the fixture, for example, closes a network connection.
|
|
* This method is called after a test is executed.
|
|
*/
|
|
public function tearDown()
|
|
{
|
|
|
|
}
|
|
|
|
public static function setUpBeforeClass()
|
|
{
|
|
parent::setUpBeforeClass();
|
|
try
|
|
{
|
|
self::$api = Bridge_Api::get_by_api_name(appbox::get_instance(\bootstrap::getCore()), 'apitest');
|
|
}
|
|
catch (Bridge_Exception_ApiNotFound $e)
|
|
{
|
|
self::$api = Bridge_Api::create(appbox::get_instance(\bootstrap::getCore()), 'apitest');
|
|
}
|
|
|
|
try
|
|
{
|
|
self::$account = Bridge_Account::load_account_from_distant_id(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo');
|
|
}
|
|
catch (Bridge_Exception_AccountNotFound $e)
|
|
{
|
|
self::$account = Bridge_Account::create(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo', 'coucou');
|
|
}
|
|
}
|
|
|
|
public static function tearDownAfterClass()
|
|
{
|
|
parent::tearDownAfterClass();
|
|
self::$api->delete();
|
|
if (self::$account instanceof Bridge_Account)
|
|
self::$account->delete();
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testSet_auth_settings().
|
|
*/
|
|
public function testSet_auth_settings()
|
|
{
|
|
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$settings = self::$account->get_settings();
|
|
|
|
$stub->expects($this->once())
|
|
->method('set_transport_authentication_params');
|
|
|
|
$return = $stub->set_auth_settings($settings);
|
|
|
|
$this->assertEquals($stub, $return);
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testConnect().
|
|
*/
|
|
public function testConnectGood()
|
|
{
|
|
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$stub->expects($this->once())
|
|
->method('is_configured')
|
|
->will($this->returnValue(TRUE));
|
|
|
|
$this->auth->expects($this->once())
|
|
->method('parse_request_token')
|
|
->will($this->returnValue("token"));
|
|
$this->auth->expects($this->once())
|
|
->method('connect')
|
|
->will($this->returnValue(array("coucou")));
|
|
|
|
$return = $stub->connect();
|
|
|
|
$this->assertEquals(array("coucou"), $return);
|
|
}
|
|
|
|
public function testConnectBad()
|
|
{
|
|
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$stub->expects($this->once())
|
|
->method('is_configured')
|
|
->will($this->returnValue(FALSE));
|
|
|
|
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
|
|
|
|
$stub->connect();
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testReconnect().
|
|
*/
|
|
public function testReconnect()
|
|
{
|
|
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$stub->expects($this->once())
|
|
->method('is_configured')
|
|
->will($this->returnValue(TRUE));
|
|
|
|
$this->auth->expects($this->once())
|
|
->method('reconnect');
|
|
|
|
$return = $stub->reconnect();
|
|
|
|
$this->assertEquals($stub, $return);
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testReconnect().
|
|
*/
|
|
public function testReconnectBad()
|
|
{
|
|
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$stub->expects($this->once())
|
|
->method('is_configured')
|
|
->will($this->returnValue(FALSE));
|
|
|
|
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
|
|
|
|
$stub->reconnect();
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testDisconnect().
|
|
*/
|
|
public function testDisconnect()
|
|
{
|
|
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$stub->expects($this->once())
|
|
->method('is_configured')
|
|
->will($this->returnValue(TRUE));
|
|
|
|
$this->auth->expects($this->once())
|
|
->method('disconnect');
|
|
|
|
$return = $stub->disconnect();
|
|
|
|
$this->assertEquals($stub, $return);
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testDisconnect().
|
|
*/
|
|
public function testDisconnectBad()
|
|
{
|
|
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$stub->expects($this->once())
|
|
->method('is_configured')
|
|
->will($this->returnValue(FALSE));
|
|
|
|
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
|
|
|
|
$stub->disconnect();
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testIs_connected().
|
|
*/
|
|
public function testIs_connected()
|
|
{
|
|
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$this->auth->expects($this->once())
|
|
->method('is_connected')
|
|
->will($this->returnValue(TRUE));
|
|
|
|
$return = $stub->is_connected();
|
|
|
|
$this->assertEquals(TRUE, $return);
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testGet_auth_url().
|
|
*/
|
|
public function testGet_auth_url()
|
|
{
|
|
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$this->auth->expects($this->once())
|
|
->method('get_auth_url')
|
|
->with($this->isType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY))
|
|
->will($this->returnValue("une url"));
|
|
|
|
$return = $stub->get_auth_url();
|
|
|
|
$this->assertEquals("une url", $return);
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testSet_locale().
|
|
*/
|
|
public function testSet_locale()
|
|
{
|
|
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$stub->set_locale("fr");
|
|
|
|
$this->assertEquals("fr", $stub->get_locale());
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testIs_valid_object_id().
|
|
*/
|
|
public function testIs_valid_object_id()
|
|
{
|
|
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
|
|
$this->assertTrue($stub->is_valid_object_id("abc"));
|
|
$this->assertTrue($stub->is_valid_object_id(123));
|
|
$this->assertTrue($stub->is_valid_object_id(12.25));
|
|
$this->assertFalse($stub->is_valid_object_id(array()));
|
|
$this->assertFalse($stub->is_valid_object_id(true));
|
|
}
|
|
|
|
/**
|
|
* @todo Implement testHandle_exception().
|
|
*/
|
|
public function testHandle_exception()
|
|
{
|
|
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
|
|
$e = new Exception("hihi");
|
|
$void = $stub->handle_exception($e);
|
|
$this->assertNull($void);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|