예제 #1
0
 function tearDown()
 {
     ConnectionManager::drop('testapi');
     ConnectionManager::drop('testapiToken');
     Configure::delete('Copula.testapi.Auth');
     unset($this->controller, $this->Oauth);
     parent::tearDown();
 }
예제 #2
0
 function tearDown()
 {
     parent::tearDown();
     Cache::clear(false, 'default');
     ConnectionManager::drop('cacher');
     unset($this->CacheData);
     unset($this->dataSource);
 }
 public function tearDown()
 {
     $manager = ConnectionManager::getDataSource('testMongoFixture')->getSchemaManager();
     $manager->dropDocumentCollection('User');
     $manager->dropDocumentCollection('Account');
     App::build();
     ClassRegistry::flush();
     ConnectionManager::drop('testMongoFixture');
 }
예제 #4
0
 public function testGetTokenRefresh()
 {
     $config = array('datasource' => 'Copula.RemoteTokenSource', 'login' => 'login', 'password' => 'password', 'authMethod' => 'OAuthV2', 'access' => 'token', 'scheme' => 'https', 'host' => 'accounts.example.com');
     ConnectionManager::create('testapiToken', $config);
     $testapi = ConnectionManager::getDataSource('testapiToken');
     $testapi->Http = $this->getMock('HttpSocketOauth');
     $refresh = new HttpSocketResponse();
     $refresh->code = 200;
     $body = array('access_token' => 'token', 'refresh_token' => 'refresh', 'expires_in' => '1234');
     $refresh->body = json_encode($body);
     $refresh->headers['Content-Type'] = 'application/json';
     $request = array('method' => 'POST', 'uri' => array('host' => 'accounts.example.com', 'path' => 'token', 'scheme' => 'https'), 'body' => array('client_id' => 'login', 'client_secret' => 'password', 'grant_type' => 'refresh_token', 'refresh_token' => 'canHasRefresh'));
     $testapi->Http->expects($this->once())->method('request')->will($this->returnValueMap(array(array($request, $refresh))));
     $token = $this->tokenV2;
     $token['modified'] = '1970-01-01 00:00:00';
     CakeSession::write('Copula.testapi.42', $token);
     $result = $this->Token->getToken('42', 'testapi');
     $expected = array_merge($token, $body);
     $this->assertEquals($expected, $result);
     ConnectionManager::drop('testapiToken');
 }
 /**
  * Tests that tablePrefix is taken from the datasource if none is defined in the model
  *
  * @return void
  * @see http://cakephp.lighthouseapp.com/projects/42648/tickets/2277-caketestmodels-in-test-cases-do-not-set-model-tableprefix
  */
 public function testModelPrefixFromDatasource()
 {
     ConnectionManager::create('mock', array('datasource' => 'DboMock', 'prefix' => 'custom_prefix_'));
     $Article = new Article(false, null, 'mock');
     $this->assertEquals('custom_prefix_', $Article->tablePrefix);
     ConnectionManager::drop('mock');
 }
예제 #6
0
 /**
  * Test getMockForModel on secondary datasources.
  *
  * @return void
  */
 public function testGetMockForModelSecondaryDatasource()
 {
     App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS), 'Model/Datasource/Database' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS . 'Datasource' . DS . 'Database' . DS)), App::RESET);
     CakePlugin::load('TestPlugin');
     ConnectionManager::create('test_secondary', array('datasource' => 'Database/TestLocalDriver'));
     $post = $this->getMockForModel('SecondaryPost', array('save'));
     $this->assertEquals('test_secondary', $post->useDbConfig);
     ConnectionManager::drop('test_secondary');
 }
예제 #7
0
 public function tearDown()
 {
     ConnectionManager::drop('testapi');
     unset($this->components, $this->auth, $this->request);
     parent::tearDown();
 }
 /**
  * Tests that a connection configuration can be deleted in runtime
  *
  * @return void
  */
 public function testDrop()
 {
     App::build(array('Model/Datasource' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS . 'Datasource' . DS)));
     ConnectionManager::create('droppable', array('datasource' => 'Test2Source'));
     $connections = ConnectionManager::enumConnectionObjects();
     $this->assertEquals(array('datasource' => 'Test2Source'), $connections['droppable']);
     $this->assertTrue(ConnectionManager::drop('droppable'));
     $connections = ConnectionManager::enumConnectionObjects();
     $this->assertFalse(isset($connections['droppable']));
 }
예제 #9
0
 public static function tearDownAfterClass()
 {
     ConnectionManager::drop('test_twitter_app');
     ConnectionManager::drop('test_twitter2');
     parent::tearDownAfterClass();
 }
예제 #10
0
 static function tearDownAfterClass()
 {
     ConnectionManager::drop('test_twitter_component');
     ConnectionManager::drop('fake_twitter');
 }
예제 #11
0
 public function tearDown()
 {
     ConnectionManager::drop('testapi');
     unset($this->Source, $this->Model);
     parent::tearDown();
 }
예제 #12
0
    /**
     * Test the two db connections 'default', and 'test' using the passed db config params
     *
     * @access private
     * @param array $dbConfig
     * @param array $connectionName name of the database we are trying to connect to
     * @return array
     */
    private function __testDbConnection($dbConfig, $connectionName)
    {
        $connected = false;

        try {
            $this->out("Trying '{$connectionName}' database connection");
            ConnectionManager::create($connectionName, $dbConfig);

            $this->out("++ Successfully connected to database using entered connection parameters");
            $connected = true;
        } catch(MissingConnectionException $ex) {
            ConnectionManager::drop($connectionName);
            $this->out("** ERROR ** '" . ucfirst($connectionName) . "' database connection parameters failed");
        }

        return $connected;
    }
 public function tearDown()
 {
     parent::tearDown();
     ConnectionManager::drop($this->testDatasourceName);
     ConnectionManager::drop($this->mockDatasourceName);
 }
예제 #14
0
 public function tearDown()
 {
     ConnectionManager::drop('testapi');
     unset($this->model, $this->Apis);
     ClassRegistry::flush();
     parent::tearDown();
 }
예제 #15
0
 /**
  * testSchemaReadWithAppModel method
  *
  * @return void
  */
 public function testSchemaReadWithAppModel()
 {
     $connections = ConnectionManager::enumConnectionObjects();
     ConnectionManager::drop('default');
     ConnectionManager::create('default', $connections['test']);
     try {
         $this->Schema->read(array('connection' => 'default', 'name' => 'TestApp', 'models' => array('AppModel')));
     } catch (MissingTableException $mte) {
         ConnectionManager::drop('default');
         $this->fail($mte->getMessage());
     }
     ConnectionManager::drop('default');
 }
예제 #16
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     unset($this->Model, $this->Source);
     ConnectionManager::drop($this->sourceName);
 }
예제 #17
0
 function testFindingOnMultipleDbConfigs()
 {
     $testSuite = ConnectionManager::getDataSource('test');
     ConnectionManager::create('cacher_test1', $testSuite->config);
     ConnectionManager::create('cacher_test2', $testSuite->config);
     $CacheData1 = ClassRegistry::init('CacheData');
     $CacheData1->alias = 'CacheData1';
     $CacheData1->useDbConfig = 'cacher_test1';
     $CacheData1->Behaviors->attach('Cacher.Cache', array('auto' => true, 'clearOnDelete' => false));
     $CacheData2 = ClassRegistry::init('CacheData2');
     $CacheData2->alias = 'CacheData2';
     $CacheData2->useDbConfig = 'cacher_test2';
     $CacheData2->Behaviors->attach('Cacher.Cache', array('auto' => true, 'clearOnDelete' => false));
     $count1 = $CacheData1->find('count');
     $count2 = $CacheData2->find('count');
     $CacheData1->delete(1);
     $CacheData2->delete(1);
     $this->assertEquals($count1, $CacheData1->find('count'));
     $this->assertEquals($count2, $CacheData2->find('count'));
     $this->assertEquals($CacheData1->useDbConfig, 'cacher_test1');
     $this->assertEquals($CacheData2->useDbConfig, 'cacher_test2');
     ConnectionManager::drop('cacher_test1');
     ConnectionManager::drop('cacher_test2');
 }
예제 #18
0
 /**
  * testEscapeField to prove it escapes the field well even when it has part of the alias on it
  *
  * @return void
  */
 public function testEscapeField()
 {
     $TestModel = new Test();
     $db = $TestModel->getDataSource();
     $result = $TestModel->escapeField('test_field');
     $expected = $db->name('Test.test_field');
     $this->assertEquals($expected, $result);
     $result = $TestModel->escapeField('TestField');
     $expected = $db->name('Test.TestField');
     $this->assertEquals($expected, $result);
     $result = $TestModel->escapeField('DomainHandle', 'Domain');
     $expected = $db->name('Domain.DomainHandle');
     $this->assertEquals($expected, $result);
     ConnectionManager::create('mock', array('datasource' => 'DboMock'));
     $TestModel->setDataSource('mock');
     $db = $TestModel->getDataSource();
     $result = $TestModel->escapeField('DomainHandle', 'Domain');
     $expected = $db->name('Domain.DomainHandle');
     $this->assertEquals($expected, $result);
     ConnectionManager::drop('mock');
 }
예제 #19
0
 /**
  * Change path metadata database.
  *
  * @access public
  * @return void
  */
 public function _applyMetadata()
 {
     $dbConfig = ConnectionManager::getDataSource('default')->config;
     $userMetadata = Configure::read('General.metadata');
     if (!empty($userMetadata) && $dbConfig['database'] !== $userMetadata) {
         $dbConfig['database'] = $userMetadata;
         ConnectionManager::drop('default');
         ConnectionManager::create('default', $dbConfig);
     }
 }