mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-25 00:24:35 +00:00
EZ-Components
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
CREDITS
|
||||
=======
|
||||
|
||||
eZ Components team
|
||||
------------------
|
||||
|
||||
- Sergey Alexeev
|
||||
- Sebastian Bergmann
|
||||
- Jan Borsodi
|
||||
- Raymond Bosman
|
||||
- Frederik Holljen
|
||||
- Kore Nordmann
|
||||
- Derick Rethans
|
||||
- Vadym Savchuk
|
||||
- Tobias Schlitt
|
||||
- Alexandru Stanoi
|
||||
@@ -0,0 +1,17 @@
|
||||
1.0 - Monday 02 July 2007
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- No changes.
|
||||
|
||||
|
||||
1.0rc1 - Monday 25 June 2007
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Documentation updates and fixes.
|
||||
|
||||
|
||||
1.0beta1 - Monday 07 May 2007
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Implemented feature #9405: Allow creation of datasets directly from PDO
|
||||
statements.
|
||||
@@ -0,0 +1 @@
|
||||
Graph: 1.1
|
||||
@@ -0,0 +1,2 @@
|
||||
The GraphDatabaseTiein provides functionality to directly use PDO statements
|
||||
as basis for ezcGraph Datasets.
|
||||
@@ -0,0 +1,3 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
@@ -0,0 +1,29 @@
|
||||
eZ publish Enterprise Component: GraphDatabaseTiein, Design
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
:Author: Kore Nordmann
|
||||
:Revision: $id$
|
||||
:Date: $Date: 2007-05-03 08:50:00 +0200 (Thu, 03 May 2007) $
|
||||
|
||||
Design Description
|
||||
==================
|
||||
|
||||
The GraphDatabaseTiein provides functionality to directly use PDO statements
|
||||
as basis for Datasets. You can either use result sets with one or two columns
|
||||
directly or specify in the data set constructor which columns to use as data
|
||||
set keys and values.
|
||||
|
||||
Main Classes
|
||||
============
|
||||
|
||||
- ezcGraphPdoDataSet extends ezcGraphDataSet
|
||||
|
||||
This class receives a PDO statement and can be used as a data set for all
|
||||
chart types.
|
||||
|
||||
|
||||
..
|
||||
Local Variables:
|
||||
mode: rst
|
||||
fill-column: 79
|
||||
End:
|
||||
vim: et syn=rst tw=79
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,132 @@
|
||||
==================================
|
||||
eZ Components - GraphDatabaseTieIn
|
||||
==================================
|
||||
|
||||
.. contents:: Table of Contents
|
||||
:depth: 2
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
The GraphDatabaseTieIn allows you to directly display results from a database
|
||||
query in a graph using ezcGraph. All data represented in PDOStatements, for
|
||||
example returned by the database component, can be displayed.
|
||||
|
||||
Class overview
|
||||
==============
|
||||
|
||||
This section gives you an overview of the most important classes.
|
||||
|
||||
ezcGraphDatabaseDataSet
|
||||
Extends the ezcGraphDataset to read data from a PDOStatement and prepare it
|
||||
for the usage as a dataset in the graph component.
|
||||
|
||||
Setup
|
||||
=====
|
||||
|
||||
For the examples we expect a simple database setup, so that we are able to
|
||||
test our examples. For this we create a table with some statistical data to be
|
||||
used in the graphs.
|
||||
|
||||
.. include:: tutorial/tutorial_insert_data.php
|
||||
:literal:
|
||||
|
||||
We first include the common autoload file to set up the autoload for
|
||||
ezcComponents. Then, in line 5, we connect to a SQLite memory database, we
|
||||
later fill up with some data representing a random browser statistic. The
|
||||
usage idescription of PDO__ and the `database component`__ can be found at
|
||||
the dedicated documentation pages.
|
||||
|
||||
__ http://php.net/PDO
|
||||
__ introduction_Database.html
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Default behaviour
|
||||
-----------------
|
||||
|
||||
To create a simple pie chart we just select the data and add a new dataset,
|
||||
created from the resulting statement, to a new chart.
|
||||
|
||||
.. include:: tutorial/tutorial_simple.php
|
||||
:literal:
|
||||
|
||||
The query builder we use to create the select query in line 8 to 10 is
|
||||
described in detail in the `database components documentation`__. In this
|
||||
example all values from the columns hits and browser are selected from the
|
||||
table browser_hits. The result of the query is available in $statement after
|
||||
the query was executed. The $statement object is an instance of the
|
||||
PDOStatement class.
|
||||
|
||||
__ introduction_Database.html
|
||||
|
||||
The creation of charts is described in detail in the `graph components
|
||||
documentation`__. In this example we create a simple pie chart, set a title
|
||||
for the chart and add a new dataset. To directly use a PDOStatement as a data
|
||||
source an instance of ezcGraphDatabaseDataSet is created with the $statement
|
||||
as the first parameter. By default the first column is used as index and the
|
||||
second column as values for the indices. The result is the pie chart we
|
||||
expected.
|
||||
|
||||
__ introduction_Graph.html
|
||||
|
||||
.. image:: img/tutorial_simple.svg.png
|
||||
:alt: Simple pie chart example
|
||||
|
||||
Single column
|
||||
-------------
|
||||
|
||||
.. include:: tutorial/tutorial_simple.php
|
||||
:literal:
|
||||
|
||||
When only a single column is returned by the select query the values are
|
||||
considered as a zero indexed array. This might be useful to display them in
|
||||
line or bar charts.
|
||||
|
||||
The created data set may be used in the same way like all other data sets,
|
||||
which can be seen in line 20 in the example above, where a average polynomial
|
||||
data set is created from the database data set. More documentation on average
|
||||
datasets can be found in the `graph tutorial`__.
|
||||
|
||||
__ introduction_Graph.html#average-polynomial-dataset
|
||||
|
||||
.. image:: img/tutorial_single.svg.png
|
||||
:alt: Line chart example
|
||||
|
||||
Multiple columns
|
||||
----------------
|
||||
|
||||
You also may specify which column should be used as a key and which column
|
||||
should be used as a value in the created dataset. This is particulary useful
|
||||
when dealing with more then two columns.
|
||||
|
||||
.. include:: tutorial/tutorial_multiple.php
|
||||
:literal:
|
||||
|
||||
In this example all columns from the table are selected using the \*,but the
|
||||
array starting in line 21 defines which columns are used for keys and values.
|
||||
There are two array keys, which are constants defined in ezcGraph, referencing
|
||||
the name of the column to use.
|
||||
|
||||
Starting at line 28 we change the renderer and enhance the output a bit. This
|
||||
is described in more detail in the `3D renderer section`__ in the graph
|
||||
tutorial.
|
||||
|
||||
__ introduction_Graph.html#id2
|
||||
|
||||
.. image:: img/tutorial_multiple.svg.png
|
||||
:alt: Pie chart from multiple columns
|
||||
|
||||
More information
|
||||
================
|
||||
|
||||
For more information, see the ezcGraphDatabaseTieIn API documentation.
|
||||
|
||||
|
||||
..
|
||||
Local Variables:
|
||||
mode: rst
|
||||
fill-column: 79
|
||||
End:
|
||||
vim: et syn=rst tw=79
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
$dir = dirname( dirname( __FILE__ ) );
|
||||
$dirParts = explode( '/', $dir );
|
||||
switch ( $dirParts[count( $dirParts ) - 3] )
|
||||
{
|
||||
case 'doc': require_once 'ezc/Base/base.php'; break; // pear
|
||||
case 'trunk': require_once "$dir/../../Base/src/base.php"; break; // svn
|
||||
default: require_once "$dir/../../Base/src/base.php"; break; // bundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoload ezc classes
|
||||
*
|
||||
* @param string $className
|
||||
*/
|
||||
function __autoload( $className )
|
||||
{
|
||||
ezcBase::autoload( $className );
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once 'tutorial_autoload.php';
|
||||
|
||||
$db = ezcDbFactory::create( 'sqlite://:memory:' );
|
||||
ezcDbInstance::set( $db );
|
||||
|
||||
// Create test table
|
||||
$db->exec( 'CREATE TABLE browser_hits ( id INT, browser VARCHAR(255), hits INT )' );
|
||||
|
||||
// Insert some data
|
||||
$db->exec( "INSERT INTO browser_hits VALUES ( NULL, 'Firefox', 2567 )" );
|
||||
$db->exec( "INSERT INTO browser_hits VALUES ( NULL, 'Opera', 543 )" );
|
||||
$db->exec( "INSERT INTO browser_hits VALUES ( NULL, 'Safari', 23 )" );
|
||||
$db->exec( "INSERT INTO browser_hits VALUES ( NULL, 'Konquror', 812 )" );
|
||||
$db->exec( "INSERT INTO browser_hits VALUES ( NULL, 'Lynx', 431 )" );
|
||||
$db->exec( "INSERT INTO browser_hits VALUES ( NULL, 'wget', 912 )" );
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
require_once 'tutorial_insert_data.php';
|
||||
|
||||
// Receive data from database
|
||||
$db = ezcDbInstance::get();
|
||||
$query = $db->createSelectQuery();
|
||||
$query
|
||||
->select( '*' )
|
||||
->from( 'browser_hits' );
|
||||
$statement = $query->prepare();
|
||||
$statement->execute();
|
||||
|
||||
// Create chart from data
|
||||
$chart = new ezcGraphPieChart();
|
||||
$chart->title = 'Browser statistics';
|
||||
$chart->legend = false;
|
||||
|
||||
$chart->data['browsers'] = new ezcGraphDatabaseDataSet(
|
||||
$statement,
|
||||
array(
|
||||
ezcGraph::KEY => 'browser',
|
||||
ezcGraph::VALUE => 'hits',
|
||||
)
|
||||
);
|
||||
|
||||
// Some graph output formatting
|
||||
$chart->renderer = new ezcGraphRenderer3d();
|
||||
|
||||
$chart->renderer->options->pieChartGleam = .3;
|
||||
$chart->renderer->options->pieChartGleamColor = '#FFFFFF';
|
||||
$chart->renderer->options->dataBorder = false;
|
||||
|
||||
$chart->renderer->options->pieChartShadowSize = 5;
|
||||
$chart->renderer->options->pieChartShadowColor = '#000000';
|
||||
|
||||
$chart->renderer->options->pieChartSymbolColor = '#55575388';
|
||||
|
||||
$chart->renderer->options->pieChartHeight = 5;
|
||||
$chart->renderer->options->pieChartRotation = .8;
|
||||
|
||||
// Render
|
||||
$chart->render( 400, 150, 'tutorial_multiple.svg' );
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
require_once 'tutorial_insert_data.php';
|
||||
|
||||
// Receive data from database
|
||||
$db = ezcDbInstance::get();
|
||||
$query = $db->createSelectQuery();
|
||||
$query
|
||||
->select( 'browser', 'hits' )
|
||||
->from( 'browser_hits' );
|
||||
$statement = $query->prepare();
|
||||
$statement->execute();
|
||||
|
||||
// Create chart from data
|
||||
$chart = new ezcGraphPieChart();
|
||||
$chart->title = 'Browser statistics';
|
||||
|
||||
$chart->data['browsers'] = new ezcGraphDatabaseDataSet( $statement );
|
||||
|
||||
$chart->render( 400, 200, 'tutorial_simple.svg' );
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
require_once 'tutorial_insert_data.php';
|
||||
|
||||
// Receive data from database
|
||||
$db = ezcDbInstance::get();
|
||||
$query = $db->createSelectQuery();
|
||||
$query
|
||||
->select( 'hits' )
|
||||
->from( 'browser_hits' );
|
||||
$statement = $query->prepare();
|
||||
$statement->execute();
|
||||
|
||||
// Create chart from data
|
||||
$chart = new ezcGraphLineChart();
|
||||
$chart->title = 'Browser statistics';
|
||||
$chart->options->fillLines = 220;
|
||||
|
||||
$chart->data['browsers'] = new ezcGraphDatabaseDataSet( $statement );
|
||||
$chart->data['average'] = new ezcGraphDataSetAveragePolynom(
|
||||
$chart->data['browsers']
|
||||
);
|
||||
|
||||
$chart->render( 400, 150, 'tutorial_single.svg' );
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphDatabaseDataSet class
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Class to transform PDO results into ezcGraphDataSets
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
* @mainclass
|
||||
*/
|
||||
class ezcGraphDatabaseDataSet extends ezcGraphDataSet
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Creates a ezcGraphDatabase from a PDOStatement and uses the columns
|
||||
* defined in the definition array as keys and values for the data set.
|
||||
*
|
||||
* If the definition array is empty a single column will be used as values,
|
||||
* with two columns the first column will be used for the keys and the
|
||||
* second for the data set values.
|
||||
*
|
||||
* You may define the name of the rows used for keys and values by using
|
||||
* an array like:
|
||||
* array (
|
||||
* ezcGraph::KEY => 'row name',
|
||||
* ezcGraph::VALUE => 'row name',
|
||||
* );
|
||||
*
|
||||
* @param PDOStatement $statement
|
||||
* @param array $definition
|
||||
* @return ezcGraphDatabase
|
||||
*/
|
||||
public function __construct( PDOStatement $statement, array $definition = null )
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->data = array();
|
||||
$this->createFromPdo( $statement, $definition );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create dataset from PDO statement
|
||||
*
|
||||
* This methods uses the values from a PDOStatement to fill up the data
|
||||
* sets data.
|
||||
*
|
||||
* If the definition array is empty a single column will be used as values,
|
||||
* with two columns the first column will be used for the keys and the
|
||||
* second for the data set values.
|
||||
*
|
||||
* You may define the name of the rows used for keys and values by using
|
||||
* an array like:
|
||||
* array (
|
||||
* ezcGraph::KEY => 'row name',
|
||||
* ezcGraph::VALUE => 'row name',
|
||||
* );
|
||||
*
|
||||
* @param PDOStatement $statement
|
||||
* @param array $definition
|
||||
* @return void
|
||||
*/
|
||||
protected function createFromPdo( PDOStatement $statement, array $definition = null )
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
if ( $definition === null )
|
||||
{
|
||||
while ( $row = $statement->fetch( PDO::FETCH_NUM ) )
|
||||
{
|
||||
++$count;
|
||||
|
||||
switch ( count( $row ) )
|
||||
{
|
||||
case 1:
|
||||
$this->data[] = $row[0];
|
||||
break;
|
||||
case 2:
|
||||
$this->data[$row[0]] = $row[1];
|
||||
break;
|
||||
default:
|
||||
throw new ezcGraphDatabaseTooManyColumnsException( $row );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $statement->fetch( PDO::FETCH_NAMED ) )
|
||||
{
|
||||
++$count;
|
||||
|
||||
if ( !array_key_exists( $definition[ezcGraph::VALUE], $row ) )
|
||||
{
|
||||
throw new ezcGraphDatabaseMissingColumnException( $definition[ezcGraph::VALUE] );
|
||||
}
|
||||
|
||||
$value = $row[$definition[ezcGraph::VALUE]];
|
||||
|
||||
if ( array_key_exists( ezcGraph::KEY, $definition ) )
|
||||
{
|
||||
if ( !array_key_exists( $definition[ezcGraph::KEY], $row ) )
|
||||
{
|
||||
throw new ezcGraphDatabaseMissingColumnException( $definition[ezcGraph::KEY] );
|
||||
}
|
||||
|
||||
$this->data[$row[$definition[ezcGraph::KEY]]] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->data[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Empty result set
|
||||
if ( $count <= 0 )
|
||||
{
|
||||
throw new ezcGraphDatabaseStatementNotExecutedException( $statement );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this dataset
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count( $this->data );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Base exception for the GraphDatabaseTiein package.
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* General exception container for the GraphDatabaseTiein component.
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
*/
|
||||
abstract class ezcGraphDatabaseException extends ezcBaseException
|
||||
{
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphDatabaseMissingColumnException class
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Exception thrown if a requetsted column could not be found in result set
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
*/
|
||||
class ezcGraphDatabaseMissingColumnException extends ezcGraphDatabaseException
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $column
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( $column )
|
||||
{
|
||||
parent::__construct( "Missing column '{$column}' in result set." );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphDatabaseStatementNotExecutedException class
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Exception thrown if a given statement has not been executed.
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
*/
|
||||
class ezcGraphDatabaseStatementNotExecutedException extends ezcGraphDatabaseException
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param PDOStatement $statement
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( $statement )
|
||||
{
|
||||
parent::__construct( "Empty result set. Execute the statement before using with ezcGraphDatabaseTiein." );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphDatabaseTooManyColumnsException class
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Exception thrown if a data set has too many columns for a key value
|
||||
* association.
|
||||
*
|
||||
* @package GraphDatabaseTiein
|
||||
* @version 1.0
|
||||
*/
|
||||
class ezcGraphDatabaseTooManyColumnsException extends ezcGraphDatabaseException
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $row
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( $row )
|
||||
{
|
||||
$columnCount = count( $row );
|
||||
parent::__construct( "'{$columnCount}' columns are too many in a result." );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,374 @@
|
||||
<?php
|
||||
/**
|
||||
* ezcGraphDatabaseTest
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.0
|
||||
* @subpackage Tests
|
||||
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests for ezcGraph class.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcGraphDatabaseTest extends ezcTestCase
|
||||
{
|
||||
protected $basePath;
|
||||
|
||||
protected $tempDir;
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite( "ezcGraphDatabaseTest" );
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
static $i = 0;
|
||||
$this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/';
|
||||
$this->basePath = dirname( __FILE__ ) . '/data/';
|
||||
|
||||
// Try to build up database connection
|
||||
try
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
}
|
||||
catch ( Exception $e )
|
||||
{
|
||||
$this->markTestSkipped( 'Database connection required for PDO statement tests.' );
|
||||
}
|
||||
|
||||
$this->q = new ezcQueryInsert( $db );
|
||||
try
|
||||
{
|
||||
$db->exec( 'DROP TABLE graph_pdo_test' );
|
||||
}
|
||||
catch ( Exception $e ) {} // eat
|
||||
|
||||
// Create test table
|
||||
$db->exec( 'CREATE TABLE graph_pdo_test ( id INT, browser VARCHAR(255), hits INT )' );
|
||||
|
||||
// Insert some data
|
||||
$db->exec( "INSERT INTO graph_pdo_test VALUES ( '', 'Firefox', 2567 )" );
|
||||
$db->exec( "INSERT INTO graph_pdo_test VALUES ( '', 'Opera', 543 )" );
|
||||
$db->exec( "INSERT INTO graph_pdo_test VALUES ( '', 'Safari', 23 )" );
|
||||
$db->exec( "INSERT INTO graph_pdo_test VALUES ( '', 'Konquror', 812 )" );
|
||||
$db->exec( "INSERT INTO graph_pdo_test VALUES ( '', 'Lynx', 431 )" );
|
||||
$db->exec( "INSERT INTO graph_pdo_test VALUES ( '', 'wget', 912 )" );
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if ( !$this->hasFailed() )
|
||||
{
|
||||
$this->removeTempDir();
|
||||
}
|
||||
|
||||
$db = ezcDbInstance::get();
|
||||
$db->exec( 'DROP TABLE graph_pdo_test' );
|
||||
}
|
||||
|
||||
public function testAutomaticDataSetUsage()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT browser, hits FROM graph_pdo_test' );
|
||||
$statement->execute();
|
||||
|
||||
$dataset = new ezcGraphDatabaseDataSet( $statement );
|
||||
|
||||
$dataSetArray = array(
|
||||
'Firefox' => 2567,
|
||||
'Opera' => 543,
|
||||
'Safari' => 23,
|
||||
'Konquror' => 812,
|
||||
'Lynx' => 431,
|
||||
'wget' => 912,
|
||||
);
|
||||
|
||||
$count = 0;
|
||||
foreach ( $dataset as $key => $value )
|
||||
{
|
||||
list( $compareKey, $compareValue ) = each( $dataSetArray );
|
||||
|
||||
$this->assertEquals(
|
||||
$compareKey,
|
||||
$key,
|
||||
'Unexpected key for dataset value.'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$compareValue,
|
||||
$value,
|
||||
'Unexpected value for dataset.'
|
||||
);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$count,
|
||||
count( $dataSetArray ),
|
||||
'Too few datasets found.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testAutomaticDataSetUsageSingleColumn()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT hits FROM graph_pdo_test' );
|
||||
$statement->execute();
|
||||
|
||||
$dataset = new ezcGraphDatabaseDataSet( $statement );
|
||||
|
||||
$dataSetArray = array(
|
||||
'Firefox' => 2567,
|
||||
'Opera' => 543,
|
||||
'Safari' => 23,
|
||||
'Konquror' => 812,
|
||||
'Lynx' => 431,
|
||||
'wget' => 912,
|
||||
);
|
||||
|
||||
$count = 0;
|
||||
foreach ( $dataset as $key => $value )
|
||||
{
|
||||
list( $compareKey, $compareValue ) = each( $dataSetArray );
|
||||
|
||||
$this->assertEquals(
|
||||
$count,
|
||||
$key,
|
||||
'Unexpected key for dataset value.'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$compareValue,
|
||||
$value,
|
||||
'Unexpected value for dataset.'
|
||||
);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$count,
|
||||
count( $dataSetArray ),
|
||||
'Too few datasets found.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testAutomaticDataSetUsageTooManyRows()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT * FROM graph_pdo_test' );
|
||||
$statement->execute();
|
||||
|
||||
try
|
||||
{
|
||||
$dataset = new ezcGraphDatabaseDataSet( $statement );
|
||||
}
|
||||
catch ( ezcGraphDatabaseTooManyColumnsException $e )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->fail( 'Expected ezcGraphDatabaseTooManyColumnsException.' );
|
||||
}
|
||||
|
||||
public function testSpecifiedDataSetUsage()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT * FROM graph_pdo_test' );
|
||||
$statement->execute();
|
||||
|
||||
$dataset = new ezcGraphDatabaseDataSet(
|
||||
$statement,
|
||||
array(
|
||||
ezcGraph::KEY => 'browser',
|
||||
ezcGraph::VALUE => 'hits',
|
||||
)
|
||||
);
|
||||
|
||||
$dataSetArray = array(
|
||||
'Firefox' => 2567,
|
||||
'Opera' => 543,
|
||||
'Safari' => 23,
|
||||
'Konquror' => 812,
|
||||
'Lynx' => 431,
|
||||
'wget' => 912,
|
||||
);
|
||||
|
||||
$count = 0;
|
||||
foreach ( $dataset as $key => $value )
|
||||
{
|
||||
list( $compareKey, $compareValue ) = each( $dataSetArray );
|
||||
|
||||
$this->assertEquals(
|
||||
$compareKey,
|
||||
$key,
|
||||
'Unexpected key for dataset value.'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$compareValue,
|
||||
$value,
|
||||
'Unexpected value for dataset.'
|
||||
);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$count,
|
||||
count( $dataSetArray ),
|
||||
'Too few datasets found.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSpecifiedDataSetUsageSingleColumn()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT * FROM graph_pdo_test' );
|
||||
$statement->execute();
|
||||
|
||||
$dataset = new ezcGraphDatabaseDataSet(
|
||||
$statement,
|
||||
array(
|
||||
ezcGraph::VALUE => 'hits',
|
||||
)
|
||||
);
|
||||
|
||||
$dataSetArray = array(
|
||||
'Firefox' => 2567,
|
||||
'Opera' => 543,
|
||||
'Safari' => 23,
|
||||
'Konquror' => 812,
|
||||
'Lynx' => 431,
|
||||
'wget' => 912,
|
||||
);
|
||||
|
||||
$count = 0;
|
||||
foreach ( $dataset as $key => $value )
|
||||
{
|
||||
list( $compareKey, $compareValue ) = each( $dataSetArray );
|
||||
|
||||
$this->assertEquals(
|
||||
$count,
|
||||
$key,
|
||||
'Unexpected key for dataset value.'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$compareValue,
|
||||
$value,
|
||||
'Unexpected value for dataset.'
|
||||
);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$count,
|
||||
count( $dataSetArray ),
|
||||
'Too few datasets found.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSpecifiedDataSetUsageBrokenKey()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT * FROM graph_pdo_test' );
|
||||
$statement->execute();
|
||||
|
||||
try
|
||||
{
|
||||
$dataset = new ezcGraphDatabaseDataSet(
|
||||
$statement,
|
||||
array(
|
||||
ezcGraph::KEY => 'nonexistant',
|
||||
ezcGraph::VALUE => 'hits',
|
||||
)
|
||||
);
|
||||
}
|
||||
catch ( ezcGraphDatabaseMissingColumnException $e )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->fail( 'Expected ezcGraphDatabaseMissingColumnException.' );
|
||||
}
|
||||
|
||||
public function testSpecifiedDataSetUsageBrokenValue()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT * FROM graph_pdo_test' );
|
||||
$statement->execute();
|
||||
|
||||
try
|
||||
{
|
||||
$dataset = new ezcGraphDatabaseDataSet(
|
||||
$statement,
|
||||
array(
|
||||
ezcGraph::VALUE => 'nonexistant',
|
||||
)
|
||||
);
|
||||
}
|
||||
catch ( ezcGraphDatabaseMissingColumnException $e )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->fail( 'Expected ezcGraphDatabaseMissingColumnException.' );
|
||||
}
|
||||
|
||||
public function testNonExceutedQuery()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT browser, hits FROM graph_pdo_test' );
|
||||
|
||||
try
|
||||
{
|
||||
$dataset = new ezcGraphDatabaseDataSet( $statement );
|
||||
}
|
||||
catch ( ezcGraphDatabaseStatementNotExecutedException $e )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->fail( 'Expected ezcGraphDatabaseStatementNotExecutedException.' );
|
||||
}
|
||||
|
||||
public function testDataSetCount()
|
||||
{
|
||||
$db = ezcDbInstance::get();
|
||||
|
||||
$statement = $db->prepare( 'SELECT * FROM graph_pdo_test' );
|
||||
$statement->execute();
|
||||
|
||||
$dataset = new ezcGraphDatabaseDataSet(
|
||||
$statement,
|
||||
array(
|
||||
ezcGraph::VALUE => 'hits',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
count( $dataset ),
|
||||
6,
|
||||
'Wrong data set item count returned'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @package GraphDatabaseTiein
|
||||
* @subpackage Tests
|
||||
* @version 1.0
|
||||
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
require_once 'dataset_pdo_test.php';
|
||||
|
||||
/**
|
||||
* @package GraphDatabaseTiein
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcGraphDatabaseTieinSuite extends PHPUnit_Framework_TestSuite
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setName( 'GraphDatabaseTiein' );
|
||||
|
||||
$this->addTest( ezcGraphDatabaseTest::suite() );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new ezcGraphDatabaseTieinSuite;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user