Inheritance: extends Zend_Db_Adapter_Pdo_Abstract
Esempio n. 1
0
 protected function setUp()
 {
     $db = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => dirname(__FILE__) . '/Paginator/_files/test.sqlite'));
     $this->_query = $db->select()->from('test');
     $this->_testCollection = range(1, 101);
     $this->_paginator = Zend_Paginator::factory($this->_testCollection);
     $this->_config = new Zend_Config_Xml(dirname(__FILE__) . '/Paginator/_files/config.xml');
     $this->_restorePaginatorDefaults();
 }
 /**
  * Set up test configuration
  *
  * @return void
  */
 public function setUp()
 {
     $this->_db = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE));
     $sqlCreate = 'CREATE TABLE [users] ( ' . '[id] INTEGER  NOT NULL PRIMARY KEY, ' . '[username] VARCHAR(50) UNIQUE NOT NULL, ' . '[password] VARCHAR(32) NULL, ' . '[real_name] VARCHAR(150) NULL)';
     $this->_db->query($sqlCreate);
     $sqlInsert = 'INSERT INTO users (username, password, real_name) ' . 'VALUES ("my_username", "my_password", "My Real Name")';
     $this->_db->query($sqlInsert);
     $this->_adapter = new Zend_Auth_Adapter_DbTable($this->_db, 'users', 'username', 'password');
 }
Esempio n. 3
0
 public function testUnitTestLoadFixtures()
 {
     Zend_Db_Table_Abstract::setDefaultAdapter($db = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => ":memory:")));
     $db->getConnection()->exec('DROP TABLE IF EXISTS `foo`; CREATE TABLE `foo` (`a` VARCHAR, `b` VARCHAR);');
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->addTestSuite('NotEmptyZendDbTest');
     $suite->run($result = new PHPUnit_Framework_TestResult());
     $this->assertEquals(1, $result->count());
     $this->assertTestsAreSuccessful($result);
 }
Esempio n. 4
0
 protected function setUp()
 {
     $db = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => dirname(__FILE__) . '/Paginator/_files/test.sqlite'));
     $this->_query = $db->select()->from('test');
     $this->_testCollection = range(1, 101);
     $this->_paginator = Zend_Paginator::factory($this->_testCollection);
     $this->_config = new Zend_Config_Xml(dirname(__FILE__) . '/Paginator/_files/config.xml');
     // get a fresh new copy of ViewRenderer in each tests
     Zend_Controller_Action_HelperBroker::resetHelpers();
     $this->_restorePaginatorDefaults();
 }
Esempio n. 5
0
function deleteUser($user)
{
    // Crée une connexion de base de données SQLite en mémoire
    require_once 'Zend/Db/Adapter/Pdo/Sqlite.php';
    $dbAdapter = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => 'logins'));
    // Construit la requête pour insérer une ligne pour laquelle
    // l'authentification pourra réussir
    $sqlInsert = 'DELETE FROM logins WHERE login="******"';
    // Insertion des données
    $dbAdapter->query($sqlInsert);
    echo "done";
}
Esempio n. 6
0
function addUser($user, $pwd)
{
    // Crée une connexion de base de données SQLite en mémoire
    require_once 'Zend/Db/Adapter/Pdo/Sqlite.php';
    $dbAdapter = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => 'logins'));
    // Construit la requête pour insérer une ligne pour laquelle
    // l'authentification pourra réussir
    $sqlInsert = 'INSERT INTO logins (login, password) values ("' . $user . '", "' . substr(crypt($pwd, '$6$$'), 4) . '")';
    // Insertion des données
    $dbAdapter->query($sqlInsert);
    echo "done";
}
Esempio n. 7
0
 /**
  * Set up the test case
  */
 public function setUp()
 {
     parent::setUp();
     $dir = Enlight_TestHelper::Instance()->TestPath('TempFiles');
     $this->db = Enlight_Components_Db::factory('PDO_SQLITE', array('dbname' => $dir . 'config.db'));
     $this->db->exec('
       CREATE TABLE IF NOT EXISTS `config_test` (
           `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
           `section` varchar(255) DEFAULT NULL,
           `name` varchar(255) NOT NULL,
           `value` text NOT NULL,
           `created` datetime NOT NULL,
           `updated` datetime NOT NULL
         );
     ');
 }
Esempio n. 8
0
 /**
  * Log response information
  *
  * @param Spizer_Response $response
  */
 public function logResponse(Spizer_Response $response)
 {
     $this->_db->insert('responses', array('microtime' => microtime(true), 'request_id' => $this->_currentReqId, 'statuscode' => $response->getStatus(), 'message' => $response->getMessage()));
     $stmt = $this->_db->prepare("INSERT INTO response_headers (request_id, header, value) VALUES ({$this->_currentReqId}, ?, ?)");
     foreach ($response->getAllHeaders() as $k => $v) {
         $stmt->execute(array($k, $v));
     }
 }
Esempio n. 9
0
 /**
  * Inserts a table row with specified data.
  *
  * @param mixed $table The table to insert data into.
  * @param array $bind Column-value pairs.
  * @return int The number of affected rows.
  */
 public function insert($table = null, array $bind = null)
 {
     if (is_null($table) && is_null($bind)) {
         return new Harmoni_Db_Insert($this);
     } else {
         return parent::insert($table, $bind);
     }
 }
Esempio n. 10
0
 /**
  * @group ZF-7127
  */
 public function testMultipleGroupSelect()
 {
     $select = $this->_db->select()->from('test')->group('testgroup')->group('number')->where('number > 250');
     $adapter = new Adapter\DbSelect($select);
     $expected = 'SELECT COUNT(1) AS "zend_paginator_row_count" FROM (SELECT "test".* FROM "test" WHERE (number > 250) GROUP BY "testgroup"' . ",\n\t" . '"number") AS "t"';
     $this->assertEquals($expected, $adapter->getCountSelect()->__toString());
     $this->assertEquals(250, $adapter->count());
 }
Esempio n. 11
0
 protected function _setupDbAdapter($optionalParams = array())
 {
     $params = array('dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE);
     if (!empty($optionalParams)) {
         $params['options'] = $optionalParams;
     }
     $this->_db = new Zend_Db_Adapter_Pdo_Sqlite($params);
     $sqlCreate = 'CREATE TABLE [users] ( ' . '[id] INTEGER  NOT NULL PRIMARY KEY, ' . '[username] VARCHAR(50) NOT NULL, ' . '[password] VARCHAR(32) NULL, ' . '[real_name] VARCHAR(150) NULL)';
     $this->_db->query($sqlCreate);
     $sqlInsert = 'INSERT INTO users (username, password, real_name) ' . 'VALUES ("my_username", "my_password", "My Real Name")';
     $this->_db->query($sqlInsert);
 }
Esempio n. 12
0
 /**
  * @group ZF-10884
  */
 public function testSetRowCountWithAlias()
 {
     $select = $this->_db->select();
     $select->from('test', array(Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => new Zend_Db_Expr('COUNT(DISTINCT number)')));
     $this->_db->setProfiler(true);
     $adapter = new Zend_Paginator_Adapter_DbSelect($this->_db->select());
     $adapter->setRowCount($select);
     $adapter->count();
     $expected = 'SELECT COUNT(DISTINCT number) AS "zend_paginator_row_count" FROM "test"';
     $lastQuery = $this->_db->getProfiler()->getLastQueryProfile()->getQuery();
     $this->assertEquals($expected, $lastQuery);
 }
Esempio n. 13
0
 /**
  * Ensures expected behavior for for authentication failure
  * reason: Identity not found.
  *
  */
 public function testAuthenticateFailureIdentityAmbigious()
 {
     $sql_insert = 'INSERT INTO users (username, password, real_name) VALUES ("my_username", "my_password", "My Real Name")';
     $this->_db->query($sql_insert);
     $this->_adapter->setIdentity('my_username');
     $this->_adapter->setCredential('my_password');
     try {
         $result = $this->_adapter->authenticate();
         $this->assertEquals($result->getCode(), Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS);
     } catch (Zend_Auth_Exception $e) {
         $this->fail('Exception should have been thrown');
     }
 }
Esempio n. 14
0
 /**
  * Set up the test case
  */
 public function setUp()
 {
     parent::setUp();
     $dir = Enlight_TestHelper::Instance()->TestPath('TempFiles');
     $this->db = Enlight_Components_Db::factory('PDO_SQLITE', array('dbname' => $dir . 'menu.db'));
     $this->db->exec('
         DROP TABLE IF EXISTS `menu_test`;
         CREATE TABLE IF NOT EXISTS `menu_test` (
           `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
           `parent` INTEGER NOT NULL,
           `active` INTEGER(1) NOT NULL,
           `label` varchar(255) NOT NULL
         );
         DROP TABLE IF EXISTS `menu_test2`;
         CREATE TABLE IF NOT EXISTS `menu_test2` (
           `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
           `parent` INTEGER NOT NULL,
           `active` INTEGER(1) NOT NULL,
           `name` varchar(255) NOT NULL
         );
     ');
     $this->adapter = new Enlight_Components_Menu_Adapter_DbTable(array('db' => $this->db, 'name' => 'menu_test'));
 }
 /**
  * @group ZF-10704
  */
 public function testObjectSelectWithBind()
 {
     $select = $this->_db->select();
     $select->from('test', array('number'))->where('number = ?')->distinct(true)->bind(array(250));
     $adapter = new Zend_Paginator_Adapter_DbSelect($select);
     $this->assertEquals(1, $adapter->count());
     $select->reset(Zend_Db_Select::DISTINCT);
     $select2 = clone $select;
     $select2->reset(Zend_Db_Select::WHERE)->where('number = 500');
     $selectUnion = $this->_db->select()->bind(array(250));
     $selectUnion->union(array($select, $select2));
     $adapter = new Zend_Paginator_Adapter_DbSelect($selectUnion);
     $this->assertEquals(2, $adapter->count());
 }
Esempio n. 16
0
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
// Crée une connexion de base de données SQLite en mémoire
require_once 'Zend/Db/Adapter/Pdo/Sqlite.php';
$dbAdapter = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => 'logins'));
// Construit une requête de création de table
$sqlCreate = 'CREATE TABLE [logins] ( ' . '[login] VARCHAR(10) NOT NULL PRIMARY KEY, ' . '[password] CHAR(128) NULL)';
// Crée la table de crédits d'authentification
$dbAdapter->query($sqlCreate);
// Construit la requête pour insérer une ligne pour laquelle
// l'authentification pourra réussir
$sqlInsert = 'INSERT INTO logins (login, password) ' . 'VALUES ("mosioj", "MdB3G8Ym1rKNhS8mD8fTXhRu2tWlHH5A406Lg5jaI5i.eQbgpk8Z3B5boV3I1QjEUjCpxmyxsMsvkQrr3WOyQ/")';
// Insertion des données
$dbAdapter->query($sqlInsert);
$sqlInsert = 'INSERT INTO logins (login, password) ' . 'VALUES ("lauramosio", "W0.k8vp2N4eMX74PhkNpeEn/uSoTiPSENEY3FvcSS0BJNGh2KWpmREb33MmexrBblSVpoOzLAdUM6BUgSE.l80")';
// Insertion des données
$dbAdapter->query($sqlInsert);
Esempio n. 17
0
 /**
  * @group ZF-4177
  */
 public function testSelectDistinctAllUsesRegularCountAll()
 {
     $query = $this->_db->select()->from('test')->distinct();
     $adapter = new Zend_Paginator_Adapter_DbSelect($query);
     $this->assertEquals(500, $adapter->count());
 }
Esempio n. 18
0
 private function createDefaultUser($lockeduntilColumn)
 {
     $userAdd = "\n\t\t\t\tINSERT INTO `test_auth`\n\t\t\t\t\t(\t`id`,\n\t\t\t\t\t\t`username`,\n\t\t\t\t\t\t`password`,\n\t\t\t\t\t\t`sessionID`,\n\t\t\t\t\t\t`lastlogin`,\n\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t`email`,\n\t\t\t\t\t\t`active`,\n\t\t\t\t\t\t`rights`,\n\t\t\t\t\t\t`failedlogins`,\n\t\t\t\t\t\t`" . $lockeduntilColumn . "`)\n\t\t\t\t\tVALUES\n\t\t\t\t\t(\t1,\n\t\t\t\t\t\t'demo',\n\t\t\t\t\t\t'fe01ce2a7fbac8fafaed7c982a04e229',\n\t\t\t\t\t\t's4inr04o6apmclk7u88qau4r57',\n\t\t\t\t\t\t'2011-25-11 14:41:24',\n\t\t\t\t\t\t'Administrator',\n\t\t\t\t\t\t'*****@*****.**',\n\t\t\t\t\t\t 1,\n\t\t\t\t\t\t '',\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t '0000-00-00 00:00:00'\n\t\t\t\t\t);\n\t\t";
     $this->db->exec($userAdd);
 }
Esempio n. 19
0
 private function connectDB()
 {
     try {
         $dbconfig = array('host' => $this->config->database->host, 'username' => $this->config->database->username, 'password' => $this->config->database->password, 'dbname' => $this->config->database->db);
         $dbconfig = $this->doQoolHook('front_pre_connectdb', $dbconfig);
         //here we check for database type
         switch ($this->config->database->type) {
             case "mysql":
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
                 break;
             case "sqlite":
                 $db = new Zend_Db_Adapter_Pdo_Sqlite($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 break;
             default:
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
         }
     } catch (Zend_Db_Adapter_Exception $e) {
         $this->triggerError($this->language['db_connect_error']);
     } catch (Zend_Exception $e) {
         $this->triggerError($this->language['db_factory_error']);
     }
     $db = $this->doQoolHook('front_after_connectdb', $db);
     $this->db = $db;
 }