Exemplo n.º 1
0
 /**
  * setUp
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $db = ConnectionManager::getDatasource('test');
     $db->fullDebug = true;
     Configure::write('Cache.disable', false);
     Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
     Router::parse('/');
     $this->Controller = new Controller(null);
     $this->View = new View($this->Controller);
     $this->Toolbar = new ToolbarHelper($this->View, array('output' => 'MockBackendHelper', 'cacheKey' => 'debug_kit_toolbar_test_case', 'cacheConfig' => 'default'));
     $this->Toolbar->MockBackend = $this->getMock('Helper', array('testMethod'), array($this->View));
     $this->_viewPaths = App::path('views');
     App::build(array('View' => array(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'View' . DS, APP . 'Plugin' . DS . 'DebugKit' . DS . 'View' . DS, CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'View' . DS)), true);
 }
Exemplo n.º 2
0
 /**
  * Test truncate with a mock.
  *
  * @return void
  */
 public function testTruncateStatements()
 {
     $this->loadFixtures('Article', 'User');
     $db = ConnectionManager::getDatasource('test');
     $schema = $db->config['schema'];
     $Article = new Article();
     $this->Dbo = $this->getMock('Postgres', array('execute'), array($db->config));
     $this->Dbo->expects($this->at(0))->method('execute')->with("DELETE FROM \"{$schema}\".\"articles\"");
     $this->Dbo->truncate($Article);
     $this->Dbo->expects($this->at(0))->method('execute')->with("DELETE FROM \"{$schema}\".\"articles\"");
     $this->Dbo->truncate('articles');
     // #2355: prevent duplicate prefix
     $this->Dbo->config['prefix'] = 'tbl_';
     $Article->tablePrefix = 'tbl_';
     $this->Dbo->expects($this->at(0))->method('execute')->with("DELETE FROM \"{$schema}\".\"tbl_articles\"");
     $this->Dbo->truncate($Article);
     $this->Dbo->expects($this->at(0))->method('execute')->with("DELETE FROM \"{$schema}\".\"tbl_articles\"");
     $this->Dbo->truncate('articles');
 }
Exemplo n.º 3
0
 /**
  * Test truncate with a mock.
  *
  * @return void
  */
 public function testTruncateStatements()
 {
     $this->loadFixtures('Article', 'User');
     $db = ConnectionManager::getDatasource('test');
     $schema = $db->config['database'];
     $Article = new Article();
     $this->Dbo = $this->getMock('Mysql', array('execute'), array($db->config));
     $this->Dbo->expects($this->at(0))->method('execute')->with("TRUNCATE TABLE `{$schema}`.`articles`");
     $this->Dbo->truncate($Article);
     $this->Dbo->expects($this->at(0))->method('execute')->with("TRUNCATE TABLE `{$schema}`.`articles`");
     $this->Dbo->truncate('articles');
     // #2355: prevent duplicate prefix
     $this->Dbo->config['prefix'] = 'tbl_';
     $Article->tablePrefix = 'tbl_';
     $this->Dbo->expects($this->at(0))->method('execute')->with("TRUNCATE TABLE `{$schema}`.`tbl_articles`");
     $this->Dbo->truncate($Article);
     $this->Dbo->expects($this->at(0))->method('execute')->with("TRUNCATE TABLE `{$schema}`.`tbl_articles`");
     $this->Dbo->truncate('articles');
 }
Exemplo n.º 4
0
 /**
  * Test deletes with a mock.
  *
  * @return void
  */
 public function testDeleteStatements()
 {
     $this->loadFixtures('Article', 'User');
     $test = ConnectionManager::getDatasource('test');
     $this->Dbo = $this->getMock('Mysql', array('execute'), array($test->config));
     $this->Dbo->expects($this->at(0))->method('execute')->with("DELETE  FROM `articles`  WHERE 1 = 1");
     $this->Dbo->expects($this->at(1))->method('execute')->with("DELETE `Article` FROM `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" . "  WHERE 1 = 1");
     $this->Dbo->expects($this->at(2))->method('execute')->with("DELETE `Article` FROM `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" . "  WHERE 2=2");
     $Article = new Article();
     $this->Dbo->delete($Article);
     $this->Dbo->delete($Article, true);
     $this->Dbo->delete($Article, '2=2');
 }
Exemplo n.º 5
0
 /**
  * firstImport method
  *
  * accepts an xml dump (generated from the nodes controller admin_export function)
  * and contents with the file contents.
  *
  * @param mixed $xml
  * @return void
  * @access public
  */
 function first_import($xml, $options = array(), $thisUser = false)
 {
     $deleteFirst = true;
     $addingTranslation = false;
     extract($options);
     uses('Xml');
     $xml = new Xml($xml);
     $xml = Set::reverse($xml);
     $meta = Set::extract($xml, '/Contents/Meta');
     $nodes = Set::extract($xml, '/Contents/Node');
     $nodes = $nodes[0];
     $ids = Set::extract($nodes, '/Node/id');
     set_time_limit(count($ids) * 2);
     unset($this->Revision->validate['content']);
     if (Configure::read('Languages.default') != $meta[0]['Meta']['lang']) {
         $addingTranslation = true;
         if ($this->find('count') > 0) {
             $deleteFirst = false;
         }
     }
     $db =& ConnectionManager::getDataSouce($this->useDbConfig);
     $db->begin($this);
     if ($deleteFirst) {
         $db =& ConnectionManager::getDatasource('default');
         $db->query('truncate nodes');
         $db->query('truncate changes');
         $db->query('truncate revisions');
     }
     foreach ($nodes['Node'] as $i => $row) {
         extract($row);
         if ($addingTranslation && $Revision['lang'] == Configure::read('Languages.default')) {
             continue;
         }
         $parent_id = empty($parent_id) ? null : $parent_id;
         if (!$addingTranslation) {
             $depth = empty($depth) ? 0 : $depth;
             $show_in_toc = empty($show_in_toc) ? 0 : 1;
             $status = 1;
             $sequence = null;
             $toSave = compact('id', 'parent_id', 'depth', 'status', 'show_in_toc');
             if ($i == 0) {
                 $toSave['lft'] = 1;
                 $toSave['rght'] = 2;
             } else {
                 $toSave['lft'] = $parent_id;
                 $rght = $this->field('id', array('parent_id' => $id));
                 $toSave['rght'] = empty($rght) ? 0 : $rght;
             }
             $this->create();
             $this->id = false;
             if (!$this->save(array('Node' => $toSave), false)) {
                 $db->rallback($this);
                 return false;
             }
         }
         $toSave = $Revision;
         $toSave['reason'] = empty($toSave['reason']) || is_array($toSave['reason']) ? "" : $toSave['reason'];
         $toSave['content'] = empty($toSave['content']) || is_array($toSave['content']) ? "" : $toSave['content'];
         $toSave['node_id'] = $id;
         $toSave['under_node_id'] = $parent_id;
         $toSave['status'] = 'current';
         if ($thisUser) {
             $toSave['user_id'] = $thisUser;
         }
         $this->Revision->create();
         if (!$this->Revision->save(array('Revision' => $toSave), false)) {
             $db->rallback($this);
             return false;
         }
     }
     $db->commit($this);
     return true;
 }
Exemplo n.º 6
0
 public function isAuthorized()
 {
     // set OAuth
     ConnectionManager::getDatasource('twitter')->setToken($this->Auth->user('oauth_token'), $this->Auth->user('oauth_token_secret'));
     return true;
 }