├── tests ├── simpletest │ ├── VERSION │ ├── test │ │ ├── support │ │ │ ├── collector │ │ │ │ ├── collectable.1 │ │ │ │ └── collectable.2 │ │ │ ├── upload_sample.txt │ │ │ ├── supplementary_upload_sample.txt │ │ │ ├── empty_test_file.php │ │ │ ├── latin1_sample │ │ │ ├── test1.php │ │ │ └── spl_examples.php │ │ ├── url_test.php │ │ ├── parser_test.php │ │ ├── acceptance_test.php │ │ ├── test_with_parse_error.php │ │ ├── parse_error_test.php │ │ ├── bad_test_suite.php │ │ ├── autorun_test.php │ │ ├── all_tests.php │ │ ├── detached_test.php │ │ ├── remote_test.php │ │ ├── socket_test.php │ │ ├── eclipse_test.php │ │ ├── shell_test.php │ │ ├── shell_tester_test.php │ │ ├── command_line_test.php │ │ ├── unit_tester_test.php │ │ ├── simpletest_test.php │ │ ├── live_test.php │ │ ├── collector_test.php │ │ ├── reflection_php4_test.php │ │ ├── adapter_test.php │ │ ├── unit_tests.php │ │ ├── dumper_test.php │ │ └── compatibility_test.php │ ├── docs │ │ ├── fr │ │ │ ├── server_stubs_documentation.html │ │ │ └── docs.css │ │ └── en │ │ │ └── docs.css │ ├── extensions │ │ ├── testdox.php │ │ ├── phpunit_test_case.php │ │ └── testdox │ │ │ └── test.php │ ├── autorun.php │ ├── detached.php │ ├── selector.php │ ├── remote.php │ ├── reflection_php4.php │ ├── invoker.php │ └── collector.php ├── config_tests.php ├── query.php ├── QueryBuilders │ ├── postgres.php │ ├── Groupby.php │ ├── Where.php │ ├── Select.php │ └── Orderby.php ├── show_passes.php ├── Validation │ ├── Alpha.php │ ├── Required.php │ ├── AlphaNumeric.php │ ├── Ip.php │ ├── Email.php │ ├── Integer.php │ ├── Boolean.php │ ├── Url.php │ ├── Regexp.php │ ├── Matches.php │ ├── Numeric.php │ ├── MaxLength.php │ ├── MinLength.php │ ├── Between.php │ ├── Extension.php │ └── Comparsion.php ├── config.php ├── Connection │ └── Configuration.php └── validations.php ├── .gitignore ├── Crystal ├── Exception.php ├── Config │ ├── Exception.php │ └── Reader.php ├── Error │ ├── Exception.php │ └── Validation.php ├── Helper │ ├── Exception.php │ ├── Postgres.php │ └── Mysql.php ├── Parser │ ├── Exception.php │ └── Array.php ├── Query │ ├── Exception.php │ ├── Sql.php │ ├── Delete.php │ ├── Count.php │ ├── Limit.php │ ├── Common.php │ ├── Get.php │ ├── From.php │ ├── Having.php │ ├── Expression.php │ ├── Insert.php │ ├── Join.php │ ├── Update.php │ ├── Groupby.php │ ├── Orderby.php │ ├── Select.php │ └── Where.php ├── Validation │ ├── Exception.php │ ├── Integer.php │ ├── Numeric.php │ ├── Required.php │ ├── Alpha.php │ ├── Boolean.php │ ├── AlphaNumeric.php │ ├── Unique.php │ ├── Matches.php │ ├── Ip.php │ ├── Url.php │ ├── Regexp.php │ ├── MaxLength.php │ ├── Extension.php │ ├── MinLength.php │ ├── Between.php │ └── Comparsion.php ├── Connection │ ├── Exception.php │ ├── Adapter │ │ ├── Exception.php │ │ ├── Sqlite3.php │ │ ├── Mysql.php │ │ └── Postgres.php │ └── Manager.php ├── Fixtures.php ├── Manipulation │ ├── Common.php │ ├── Mysql │ │ ├── Alter.php │ │ ├── Rename.php │ │ ├── Drop.php │ │ ├── Options.php │ │ ├── Create.php │ │ ├── Fields.php │ │ └── Builder.php │ └── Postgres │ │ ├── Alter.php │ │ ├── Rename.php │ │ ├── Drop.php │ │ ├── Options.php │ │ ├── Create.php │ │ └── Fields.php ├── Log.php └── Loader.php ├── CHANGELOG.mk ├── .buildpath ├── COPYRIGHT ├── views └── print_as_table.php ├── LICENSE ├── messages └── validation_errors.php ├── config └── database.php └── Crystal.php /tests/simpletest/VERSION: -------------------------------------------------------------------------------- 1 | 1.0.1 -------------------------------------------------------------------------------- /tests/simpletest/test/support/collector/collectable.1: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/simpletest/test/support/collector/collectable.2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | *~ 3 | index.php 4 | db_config.php -------------------------------------------------------------------------------- /tests/simpletest/docs/fr/server_stubs_documentation.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/simpletest/test/support/upload_sample.txt: -------------------------------------------------------------------------------- 1 | Sample for testing file upload -------------------------------------------------------------------------------- /Crystal/Exception.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/simpletest/test/url_test.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinrusev/Crystal/HEAD/tests/simpletest/test/url_test.php -------------------------------------------------------------------------------- /Crystal/Connection/Adapter/Exception.php: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /tests/simpletest/test/support/test1.php: -------------------------------------------------------------------------------- 1 | assertEqual(3,1+2, "pass1"); 5 | } 6 | } 7 | ?> 8 | -------------------------------------------------------------------------------- /CHANGELOG.mk: -------------------------------------------------------------------------------- 1 | Changelog 2 | Last updated 08.01.2010 3 | 4 | #Version 0.3 5 | - Added query_time() function 6 | - Added print_as_table() function 7 | - Added inline configuration settings 8 | -------------------------------------------------------------------------------- /.buildpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/simpletest/test/test_with_parse_error.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/simpletest/test/parse_error_test.php: -------------------------------------------------------------------------------- 1 | addFile('test_with_parse_error.php'); 8 | $test->run(new HtmlReporter()); 9 | ?> -------------------------------------------------------------------------------- /tests/simpletest/test/bad_test_suite.php: -------------------------------------------------------------------------------- 1 | TestSuite('Two bad test cases'); 7 | $this->addFile(dirname(__FILE__) . '/support/empty_test_file.php'); 8 | } 9 | } 10 | ?> -------------------------------------------------------------------------------- /tests/config_tests.php: -------------------------------------------------------------------------------- 1 | addTestFile(CRYSTAL_CONNECTION_TESTS .'Configuration.php'); 10 | 11 | $test->run(new ShowPasses()); -------------------------------------------------------------------------------- /tests/simpletest/test/autorun_test.php: -------------------------------------------------------------------------------- 1 | addFile(dirname(__FILE__) . '/support/test1.php'); 9 | $this->assertEqual($tests->getSize(), 1); 10 | } 11 | } 12 | 13 | ?> -------------------------------------------------------------------------------- /Crystal/Parser/Array.php: -------------------------------------------------------------------------------- 1 | addTestFile(CRYSTAL_BUILDER .'Select.php'); 9 | $test->addTestFile(CRYSTAL_BUILDER .'Where.php'); 10 | //$test->addTestFile(CRYSTAL_BUILDER .'Orderby.php'); 11 | //$test->addTestFile(CRYSTAL_BUILDER .'Groupby.php'); 12 | 13 | $test->run(new ShowPasses()); -------------------------------------------------------------------------------- /tests/simpletest/test/support/spl_examples.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/simpletest/test/all_tests.php: -------------------------------------------------------------------------------- 1 | TestSuite('All tests for SimpleTest ' . SimpleTest::getVersion()); 7 | $this->addFile(dirname(__FILE__) . '/unit_tests.php'); 8 | $this->addFile(dirname(__FILE__) . '/shell_test.php'); 9 | $this->addFile(dirname(__FILE__) . '/live_test.php'); 10 | $this->addFile(dirname(__FILE__) . '/acceptance_test.php'); 11 | } 12 | } 13 | ?> -------------------------------------------------------------------------------- /tests/simpletest/test/detached_test.php: -------------------------------------------------------------------------------- 1 | addTestCase(new DetachedTestCase($command)); 11 | if (SimpleReporter::inCli()) { 12 | exit ($test->run(new TextReporter()) ? 0 : 1); 13 | } 14 | $test->run(new HtmlReporter()); 15 | ?> -------------------------------------------------------------------------------- /tests/QueryBuilders/postgres.php: -------------------------------------------------------------------------------- 1 | addTestFile(CRYSTAL_POSTGRE_TESTS .'Select.php'); 10 | $test->addTestFile(CRYSTAL_POSTGRE_TESTS .'Where.php'); 11 | $test->addTestFile(CRYSTAL_POSTGRE_TESTS .'Orderby.php'); 12 | $test->addTestFile(CRYSTAL_POSTGRE_TESTS .'Groupby.php'); 13 | 14 | $test->run(new ShowPasses()); -------------------------------------------------------------------------------- /Crystal/Query/Sql.php: -------------------------------------------------------------------------------- 1 | query->sql = $sql[0]; 21 | $this->query->type = 'sql'; 22 | 23 | return $this->query; 24 | } 25 | 26 | 27 | } -------------------------------------------------------------------------------- /Crystal/Query/Delete.php: -------------------------------------------------------------------------------- 1 | query->type = 'delete'; 23 | $this->query->sql = "DELETE FROM ?"; 24 | $this->query->params = $table[0]; 25 | 26 | return $this->query; 27 | 28 | 29 | } 30 | 31 | 32 | 33 | } -------------------------------------------------------------------------------- /tests/show_passes.php: -------------------------------------------------------------------------------- 1 | HtmlReporter(); 8 | } 9 | 10 | 11 | 12 | function paintPass($message) 13 | { 14 | parent::paintPass($message); 15 | print "

"; 16 | print "
"; 17 | print "Pass: "; 18 | $breadcrumb = $this->getTestList(); 19 | array_shift($breadcrumb); 20 | print "" . implode("->", $breadcrumb) . "
"; 21 | print $message . "
\n\n"; 22 | print "

"; 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | } 31 | ?> -------------------------------------------------------------------------------- /Crystal/Query/Count.php: -------------------------------------------------------------------------------- 1 | query->type = 'count'; 24 | $this->query->sql = "SELECT COUNT(*) as total FROM ?"; 25 | $this->query->params = $table[0]; 26 | 27 | 28 | 29 | return $this->query; 30 | } 31 | 32 | 33 | } -------------------------------------------------------------------------------- /tests/Validation/Alpha.php: -------------------------------------------------------------------------------- 1 | assertTrue($alpha->result, 'Alpha validation with string should be true'); 14 | } 15 | 16 | function TestArrayParam() 17 | { 18 | $alpha = new Crystal_Validation_Alpha(array('test')); 19 | $this->assertFalse($alpha->result, 'Alpha validation with array should be false'); 20 | 21 | } 22 | 23 | function TestEmptyParam() 24 | { 25 | $alpha = new Crystal_Validation_Alpha(); 26 | $this->assertFalse($alpha->result, 'Alpha validation with no params should be false'); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /tests/simpletest/test/remote_test.php: -------------------------------------------------------------------------------- 1 | addTestCase(new RemoteTestCase($test_url . '?xml=yes', $test_url . '?xml=yes&dry=yes')); 16 | if (SimpleReporter::inCli()) { 17 | exit ($test->run(new TextReporter()) ? 0 : 1); 18 | } 19 | $test->run(new HtmlReporter()); 20 | ?> -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyrights 2 | ---------- 3 | 4 | Crystal 5 | -------- 6 | 7 | Crystal is a database wrapper built from scratch with PHP5. It contains a few ports of other popular PHP classes/libraries. 8 | 9 | Url: http://www.crystal.martinrusev.net 10 | Copyright: 2008-2009 Martin Rusev 11 | License: MIT - see LICENSE file 12 | 13 | 14 | Zend Framework 15 | -------------- 16 | 17 | Crystal has borrowed concepts and ideas from the Zend Framework project. 18 | 19 | Url: http://framework.zend.com 20 | Copyright: Copyright © 2006-2007 by Zend Technologies, All rights reserved. 21 | 22 | Doctrine 23 | -------------- 24 | 25 | Crystal has borrowed concepts and ideas from the Doctrine ORM project. 26 | 27 | Url: http://www.phpdoctrine.net 28 | Copyright: 2005-2007 Konsta Vesterinen 29 | License: LGPL - http://www.gnu.org/licenses/lgpl.html -------------------------------------------------------------------------------- /Crystal/Validation/Integer.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 26 | } 27 | else 28 | { 29 | $this->result = FALSE; 30 | } 31 | 32 | } 33 | 34 | 35 | function __toString() 36 | { 37 | return $this->result; 38 | } 39 | 40 | } 41 | /* END OF FILE **/ -------------------------------------------------------------------------------- /tests/Validation/Required.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Required validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Required(array('test')); 18 | $this->assertFalse($alpha->result, 'Required validation with array should be false'); 19 | 20 | } 21 | 22 | 23 | function TestValidParam() 24 | { 25 | $alpha = new Crystal_Validation_Required(''); 26 | $this->assertTrue($alpha->result, 'Required validation with empty string should be true'); 27 | 28 | } 29 | 30 | 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Crystal/Validation/Numeric.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 27 | } 28 | else 29 | { 30 | $this->result = FALSE; 31 | } 32 | 33 | } 34 | 35 | function __toString() 36 | { 37 | return $this->result; 38 | } 39 | 40 | } 41 | /* END OF FILE **/ -------------------------------------------------------------------------------- /tests/config.php: -------------------------------------------------------------------------------- 1 | assertTrue($alpha->result, 'Alpha numeric validation with string should be true'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_AlphaNumeric(array('test')); 18 | $this->assertFalse($alpha->result, 'Alpha numeric validation with array should be false'); 19 | 20 | } 21 | 22 | function TestEmptyParam() 23 | { 24 | $alpha = new Crystal_Validation_AlphaNumeric(); 25 | $this->assertFalse($alpha->result, 'Alpha numeric validation with no params should be false'); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Crystal/Validation/Required.php: -------------------------------------------------------------------------------- 1 | result = FALSE; 29 | } 30 | else 31 | { 32 | $this->result = TRUE; 33 | } 34 | 35 | 36 | } 37 | 38 | function __toString() 39 | { 40 | return $this->result; 41 | } 42 | 43 | } 44 | /* END OF FILE **/ -------------------------------------------------------------------------------- /Crystal/Validation/Alpha.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 29 | 30 | } 31 | else 32 | { 33 | 34 | $this->result = FALSE; 35 | 36 | 37 | } 38 | 39 | } 40 | 41 | public function __toString() 42 | { 43 | return (string)$this->result; 44 | } 45 | 46 | 47 | 48 | } 49 | ?> 50 | -------------------------------------------------------------------------------- /tests/simpletest/test/socket_test.php: -------------------------------------------------------------------------------- 1 | assertFalse($error->isError()); 12 | $error->_setError('Ouch'); 13 | $this->assertTrue($error->isError()); 14 | $this->assertEqual($error->getError(), 'Ouch'); 15 | } 16 | 17 | function testClearingError() { 18 | $error = new SimpleStickyError(); 19 | $error->_setError('Ouch'); 20 | $this->assertTrue($error->isError()); 21 | $error->_clearError(); 22 | $this->assertFalse($error->isError()); 23 | } 24 | } 25 | ?> -------------------------------------------------------------------------------- /Crystal/Manipulation/Common.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 29 | } 30 | else 31 | { 32 | $this->result = FALSE; 33 | } 34 | 35 | 36 | 37 | 38 | } 39 | 40 | function __toString() 41 | { 42 | return $this->result; 43 | } 44 | 45 | } 46 | /* END OF FILE */ -------------------------------------------------------------------------------- /Crystal/Connection/Adapter/Sqlite3.php: -------------------------------------------------------------------------------- 1 | db = ($database_config['database'], 0666); 25 | 26 | 27 | 28 | if (!$this->db) 29 | { 30 | throw new Crystal_Connection_Exception("Cannot open database"); 31 | } 32 | 33 | 34 | 35 | return $this->db; 36 | 37 | 38 | } 39 | 40 | 41 | 42 | 43 | 44 | } -------------------------------------------------------------------------------- /Crystal/Validation/AlphaNumeric.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 26 | 27 | } 28 | else 29 | { 30 | 31 | $this->result = FALSE; 32 | 33 | 34 | } 35 | 36 | } 37 | 38 | public function __toString() 39 | { 40 | return (string)$this->result; 41 | } 42 | 43 | 44 | 45 | } 46 | /* END OF FILE */ 47 | -------------------------------------------------------------------------------- /Crystal/Query/Limit.php: -------------------------------------------------------------------------------- 1 | query->sql = "LIMIT ?,? "; 25 | $this->query->type = 'limit'; 26 | $this->query->params = $limit_params; 27 | 28 | return $this->query; 29 | 30 | } 31 | else 32 | { 33 | return FALSE; 34 | } 35 | 36 | 37 | 38 | } 39 | 40 | 41 | } -------------------------------------------------------------------------------- /views/print_as_table.php: -------------------------------------------------------------------------------- 1 | 20 | 21 | 22 | 23 | $field): ?> 24 | 27 | 28 | 29 | $v): ?> 30 | 31 | 32 | 35 | 36 | 37 | 38 |
25 | 26 |
33 | 34 |
39 | 40 |

41 | The specified table is empty 42 |

43 | 44 | -------------------------------------------------------------------------------- /Crystal/Manipulation/Mysql/Alter.php: -------------------------------------------------------------------------------- 1 | alter = "ALTER TABLE" . Crystal_Helper_Mysql::add_apostrophe($params[0]); 28 | break; 29 | 30 | 31 | default: 32 | break; 33 | } 34 | 35 | 36 | } 37 | 38 | 39 | 40 | 41 | public function __toString() 42 | { 43 | return $this->alter; 44 | } 45 | 46 | 47 | } -------------------------------------------------------------------------------- /Crystal/Manipulation/Postgres/Alter.php: -------------------------------------------------------------------------------- 1 | alter = "ALTER TABLE" . Crystal_Helper_Postgres::add_single_quote($params[0]); 28 | break; 29 | 30 | 31 | default: 32 | break; 33 | } 34 | 35 | 36 | } 37 | 38 | 39 | 40 | 41 | public function __toString() 42 | { 43 | return $this->alter; 44 | } 45 | 46 | 47 | } -------------------------------------------------------------------------------- /tests/Validation/Ip.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Ip validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Ip(array('test')); 18 | $this->assertFalse($alpha->result, 'Ip validation with array should be false'); 19 | 20 | } 21 | 22 | function TestEmptyParam() 23 | { 24 | $alpha = new Crystal_Validation_Ip(); 25 | $this->assertFalse($alpha->result, 'Ip validation with no params should be false'); 26 | 27 | } 28 | 29 | function TestValidParam() 30 | { 31 | $alpha = new Crystal_Validation_Ip('1sd92.168.1.2df3'); 32 | 33 | $this->assertTrue($alpha->result, 'Ip validation with valid ip should be true'); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Crystal/Query/Common.php: -------------------------------------------------------------------------------- 1 | query->type = 'get'; 24 | 25 | /** table alias get('producsts p') 26 | */ 27 | if(ereg(" ", $table[0])) 28 | { 29 | $this->query->sql = "SELECT * FROM ? ?"; 30 | $this->query->params = explode(' ', $table[0]); 31 | 32 | } 33 | else 34 | { 35 | $this->query->sql = "SELECT * FROM ?"; 36 | $this->query->params = $table[0]; 37 | 38 | } 39 | 40 | 41 | 42 | return $this->query; 43 | } 44 | 45 | 46 | } -------------------------------------------------------------------------------- /tests/Validation/Email.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Email validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Email(array('test')); 18 | $this->assertFalse($alpha->result, 'Email validation with array should be false'); 19 | 20 | } 21 | 22 | 23 | function TestValidParam() 24 | { 25 | $alpha = new Crystal_Validation_Email('test@mail.com'); 26 | $this->assertTrue($alpha->result, 'Email validation with valid email should be true'); 27 | 28 | } 29 | 30 | function TestEmptyParam() 31 | { 32 | $alpha = new Crystal_Validation_Email(); 33 | $this->assertFalse($alpha->result, 'Email validation with no params should be false'); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/Validation/Integer.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Integer validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Integer(array('test')); 18 | $this->assertFalse($alpha->result, 'Integer validation with array should be false'); 19 | 20 | } 21 | 22 | function TestEmptyParam() 23 | { 24 | $alpha = new Crystal_Validation_Integer(); 25 | $this->assertFalse($alpha->result, 'Integer validation with no params should be false'); 26 | 27 | } 28 | 29 | function TestValidParam() 30 | { 31 | $alpha = new Crystal_Validation_Integer(23); 32 | $this->assertTrue($alpha->result, 'Integer validation with integer should be true'); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Crystal/Manipulation/Mysql/Rename.php: -------------------------------------------------------------------------------- 1 | rename = "RENAME TABLE" . Crystal_Helper_Mysql::add_apostrophe($params[0]); 26 | 27 | $this-> rename .= "TO"; 28 | 29 | $this->rename .= Crystal_Helper_Mysql::add_apostrophe($params[1]); 30 | 31 | 32 | } 33 | 34 | 35 | 36 | 37 | public function __toString() 38 | { 39 | return $this->rename; 40 | } 41 | 42 | 43 | } 44 | 45 | 46 | 47 | 48 | //RENAME TABLE current_db.tbl_name TO other_db.tbl_name; 49 | -------------------------------------------------------------------------------- /tests/Validation/Boolean.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Boolean validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Boolean(array('test233')); 18 | $this->assertFalse($alpha->result, 'Boolean validation with array should be false'); 19 | } 20 | 21 | 22 | function TestValidParam() 23 | { 24 | $alpha = new Crystal_Validation_Boolean('1'); 25 | $this->assertTrue($alpha->result, 'Boolean with valid values should be true'); 26 | 27 | } 28 | 29 | function TestEmptyParam() 30 | { 31 | $alpha = new Crystal_Validation_Boolean(); 32 | $this->assertFalse($alpha->result, 'Boolean validation with no params should be false'); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tests/Validation/Url.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Url validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Url(array('test')); 18 | $this->assertFalse($alpha->result, 'Url validation with array should be false'); 19 | 20 | } 21 | 22 | 23 | function TestEmptyParam() 24 | { 25 | $alpha = new Crystal_Validation_Url(); 26 | $this->assertFalse($alpha->result, 'Url validation with empty string should be false'); 27 | 28 | } 29 | 30 | 31 | function TestValidParam() 32 | { 33 | $alpha = new Crystal_Validation_Url("http://google.com"); 34 | $this->assertTrue($alpha->result, 'Url validation with valid url should be true'); 35 | 36 | } 37 | 38 | 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Crystal/Manipulation/Postgres/Rename.php: -------------------------------------------------------------------------------- 1 | rename = "RENAME TABLE" . Crystal_Helper_Postgres::add_single_quote($params[0]); 26 | 27 | $this-> rename .= "TO"; 28 | 29 | $this->rename .= Crystal_Helper_Postgres::add_single_quote($params[1]); 30 | 31 | 32 | } 33 | 34 | 35 | 36 | 37 | public function __toString() 38 | { 39 | return $this->rename; 40 | } 41 | 42 | 43 | } 44 | 45 | 46 | 47 | 48 | //RENAME TABLE current_db.tbl_name TO other_db.tbl_name; 49 | -------------------------------------------------------------------------------- /Crystal/Query/From.php: -------------------------------------------------------------------------------- 1 | query->type = 'from'; 24 | $this->query->sql = "FROM ?"; 25 | 26 | /** table alias get('producsts p') 27 | */ 28 | if(ereg(" ", $table[0])) 29 | { 30 | $this->query->sql = "FROM ? ?"; 31 | $this->query->params = explode(' ', $table[0]); 32 | 33 | } 34 | else 35 | { 36 | $this->query->sql = "FROM ?"; 37 | $this->query->params = $table[0]; 38 | 39 | } 40 | 41 | return $this->query; 42 | } 43 | 44 | 45 | 46 | 47 | } -------------------------------------------------------------------------------- /tests/Validation/Regexp.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Regexp validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Regexp(array('test')); 18 | $this->assertFalse($alpha->result, 'Regexp validation with array should be false'); 19 | 20 | } 21 | 22 | function TestEmptyParam() 23 | { 24 | $alpha = new Crystal_Validation_Regexp(); 25 | $this->assertFalse($alpha->result, 'Regexp validation with no params should be false'); 26 | 27 | } 28 | 29 | function TestValidParam() 30 | { 31 | $alpha = new Crystal_Validation_Regexp("abcdef", '/def/i'); 32 | $this->assertTrue($alpha->result, 'Regexp validation with valid regular expression should be true'); 33 | 34 | } 35 | 36 | 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Crystal/Query/Having.php: -------------------------------------------------------------------------------- 1 | query->sql .= " HAVING ? = ?"; 28 | $this->query->params = $params; 29 | } 30 | else 31 | { 32 | $this->query->sql .= " HAVING ?"; 33 | $this->query->params = $params; 34 | } 35 | 36 | 37 | 38 | 39 | } 40 | else 41 | { 42 | 43 | $this->having = FALSE; 44 | 45 | } 46 | 47 | 48 | 49 | return $this->query; 50 | 51 | 52 | } 53 | 54 | 55 | 56 | 57 | } -------------------------------------------------------------------------------- /Crystal/Manipulation/Postgres/Drop.php: -------------------------------------------------------------------------------- 1 | drop = "DROP TABLE IF EXISTS " . $params[0]; 34 | break; 35 | 36 | case 'drop_database': 37 | $this->drop = "DROP DATABASE " . $params[0]; 38 | break; 39 | 40 | default: 41 | break; 42 | } 43 | 44 | 45 | } 46 | 47 | public function __toString() 48 | { 49 | return $this->drop; 50 | } 51 | 52 | 53 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2009 Martin Rusev 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Crystal/Log.php: -------------------------------------------------------------------------------- 1 | get($params['table'])->where($params['field'], $data)->fetch_row(); 26 | 27 | if(is_array($check)) 28 | { 29 | $this->result = False; 30 | } 31 | else 32 | { 33 | $this->result = True; 34 | } 35 | 36 | } 37 | else 38 | { 39 | throw new Crystal_Validation_Exception('Cannot find "table" param for the unique rule' ); 40 | } 41 | 42 | } 43 | 44 | 45 | function __toString() 46 | { 47 | 48 | return $this->result; 49 | 50 | } 51 | 52 | } 53 | /* END OF FILE **/ -------------------------------------------------------------------------------- /Crystal/Validation/Matches.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 33 | } 34 | else 35 | { 36 | $this->result = FALSE; 37 | } 38 | 39 | 40 | } 41 | else 42 | { 43 | $this->result = FALSE; 44 | } 45 | 46 | 47 | } 48 | 49 | 50 | function __toString() 51 | { 52 | return $this->result; 53 | } 54 | 55 | } 56 | /* END OF FILE **/ -------------------------------------------------------------------------------- /Crystal/Manipulation/Mysql/Drop.php: -------------------------------------------------------------------------------- 1 | drop = "DROP TABLE IF EXISTS " . Crystal_Helper_Mysql::add_apostrophe($params[0]); 34 | break; 35 | 36 | case 'drop_database': 37 | $this->drop = "DROP DATABASE " . Crystal_Helper_Mysql::add_apostrophe($params[0]); 38 | break; 39 | 40 | default: 41 | break; 42 | } 43 | 44 | 45 | } 46 | 47 | public function __toString() 48 | { 49 | return $this->drop; 50 | } 51 | 52 | 53 | } -------------------------------------------------------------------------------- /Crystal/Validation/Ip.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 33 | } 34 | else 35 | { 36 | $this->result = FALSE; 37 | } 38 | 39 | 40 | } 41 | else 42 | { 43 | 44 | $this->result = FALSE; 45 | 46 | } 47 | 48 | 49 | 50 | } 51 | 52 | 53 | function __toString() 54 | { 55 | return $this->result; 56 | } 57 | 58 | } 59 | /* END OF FILE **/ -------------------------------------------------------------------------------- /Crystal/Validation/Url.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 33 | } 34 | else 35 | { 36 | $this->result = FALSE; 37 | } 38 | 39 | 40 | 41 | } 42 | else 43 | { 44 | $this->result = FALSE; 45 | } 46 | 47 | 48 | 49 | } 50 | 51 | 52 | function __toString() 53 | { 54 | return $this->result; 55 | } 56 | 57 | } 58 | /* END OF FILE **/ -------------------------------------------------------------------------------- /Crystal/Validation/Regexp.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 34 | } 35 | else 36 | { 37 | $this->result = FALSE; 38 | } 39 | 40 | 41 | } 42 | else 43 | { 44 | $this->result = FALSE; 45 | } 46 | 47 | 48 | } 49 | 50 | 51 | function __toString() 52 | { 53 | return $this->result; 54 | } 55 | 56 | } 57 | /* END OF FILE **/ -------------------------------------------------------------------------------- /tests/Validation/Matches.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Matches validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Matches(array('test')); 18 | $this->assertFalse($alpha->result, 'Matches validation with array should be false'); 19 | 20 | } 21 | 22 | function TestEmptyParam() 23 | { 24 | $alpha = new Crystal_Validation_Matches(); 25 | $this->assertFalse($alpha->result, 'Matches validation with no params should be false'); 26 | 27 | } 28 | 29 | function TestValidParam() 30 | { 31 | $alpha = new Crystal_Validation_Matches('cat','cat'); 32 | $this->assertTrue($alpha->result, 'Matches validation with Matches should be true'); 33 | 34 | } 35 | 36 | function TestInValidParam() 37 | { 38 | $alpha = new Crystal_Validation_Matches('cat','test'); 39 | $this->assertFalse($alpha->result, 'Matches validation with Matches should be false'); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Crystal/Validation/MaxLength.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 35 | } 36 | else 37 | { 38 | $this->result = FALSE; 39 | } 40 | 41 | 42 | 43 | } 44 | else 45 | { 46 | $this->result = FALSE; 47 | } 48 | 49 | 50 | } 51 | 52 | 53 | function __toString() 54 | { 55 | return $this->result; 56 | } 57 | 58 | } 59 | /* END OF FILE **/ -------------------------------------------------------------------------------- /tests/Validation/Numeric.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Numeric validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Numeric(array('test')); 18 | $this->assertFalse($alpha->result, 'Numeric validation with array should be false'); 19 | 20 | } 21 | 22 | function TestEmptyParam() 23 | { 24 | $alpha = new Crystal_Validation_Numeric(); 25 | $this->assertFalse($alpha->result, 'Numeric validation with no params should be false'); 26 | 27 | } 28 | 29 | function TestValidParam() 30 | { 31 | $alpha = new Crystal_Validation_Numeric(12); 32 | $this->assertTrue($alpha->result, 'Numeric validation with Numeric should be true'); 33 | 34 | } 35 | 36 | function TestValidFloatParam() 37 | { 38 | $alpha = new Crystal_Validation_Numeric(12.12); 39 | $this->assertTrue($alpha->result, 'Numeric validation with Numeric should be true'); 40 | 41 | } 42 | 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /tests/Validation/MaxLength.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'MaxLength validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_MaxLength(array('test')); 18 | $this->assertFalse($alpha->result, 'MaxLength validation with array should be false'); 19 | 20 | } 21 | 22 | function TestEmptyParam() 23 | { 24 | $alpha = new Crystal_Validation_MaxLength(); 25 | $this->assertFalse($alpha->result, 'MaxLength validation with no params should be false'); 26 | 27 | } 28 | 29 | function TestValidParam() 30 | { 31 | $alpha = new Crystal_Validation_MaxLength('cat',5); 32 | $this->assertTrue($alpha->result, 'MaxLength validation with MaxLength should be true'); 33 | 34 | } 35 | 36 | function TestInValidParam() 37 | { 38 | $alpha = new Crystal_Validation_MaxLength('cat',1); 39 | $this->assertFalse($alpha->result, 'MaxLength validation with MaxLength should be false'); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tests/Validation/MinLength.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'MinLength validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_MinLength(array('test')); 18 | $this->assertFalse($alpha->result, 'MinLength validation with array should be false'); 19 | 20 | } 21 | 22 | function TestEmptyParam() 23 | { 24 | $alpha = new Crystal_Validation_MinLength(); 25 | $this->assertFalse($alpha->result, 'MinLength validation with no params should be false'); 26 | 27 | } 28 | 29 | function TestValidParam() 30 | { 31 | $alpha = new Crystal_Validation_MinLength('category',5); 32 | $this->assertTrue($alpha->result, 'MinLength validation with MinLength should be true'); 33 | 34 | } 35 | 36 | function TestInValidParam() 37 | { 38 | $alpha = new Crystal_Validation_MinLength('cat',5); 39 | $this->assertFalse($alpha->result, 'MinLength validation with MinLength should be false'); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Crystal/Validation/Extension.php: -------------------------------------------------------------------------------- 1 | result = TRUE; 35 | } 36 | else 37 | { 38 | $this->result = FALSE; 39 | } 40 | 41 | 42 | 43 | } 44 | else 45 | { 46 | $this->result = FALSE; 47 | } 48 | 49 | 50 | } 51 | 52 | function __toString() 53 | { 54 | return $this->result; 55 | } 56 | 57 | } 58 | /* END OF FILE **/ -------------------------------------------------------------------------------- /tests/Validation/Between.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Between validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Between(array('test233')); 18 | $this->assertFalse($alpha->result, 'Between validation with string should be false'); 19 | } 20 | 21 | 22 | function TestValidIntegerParam() 23 | { 24 | $alpha = new Crystal_Validation_Between('7', array('6', '8')); 25 | $this->assertTrue($alpha->result, 'Between with valid integer param should be true'); 26 | 27 | } 28 | 29 | function TestValidStringParam() 30 | { 31 | $alpha = new Crystal_Validation_Between('test', array('3', '5')); 32 | $this->assertTrue($alpha->result, 'Between with valid string param should be true'); 33 | 34 | } 35 | 36 | function TestEmptyParam() 37 | { 38 | $alpha = new Crystal_Validation_Between(); 39 | $this->assertFalse($alpha->result, 'Between validation with no params should be false'); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tests/simpletest/extensions/testdox.php: -------------------------------------------------------------------------------- 1 | _test_case_pattern = empty($test_case_pattern) ? '/^(.*)$/' : $test_case_pattern; 10 | } 11 | 12 | function paintCaseStart($test_name) { 13 | preg_match($this->_test_case_pattern, $test_name, $matches); 14 | if (!empty($matches[1])) { 15 | echo $matches[1] . "\n"; 16 | } else { 17 | echo $test_name . "\n"; 18 | } 19 | } 20 | 21 | function paintCaseEnd() { 22 | echo "\n"; 23 | } 24 | 25 | function paintMethodStart($test_name) { 26 | if (!preg_match('/^test(.*)$/i', $test_name, $matches)) { 27 | return; 28 | } 29 | $test_name = $matches[1]; 30 | 31 | $test_name = preg_replace('/([A-Z])([A-Z])/', '$1 $2', $test_name); 32 | echo '- ' . strtolower(preg_replace('/([a-zA-Z])([A-Z0-9])/', '$1 $2', $test_name)); 33 | } 34 | 35 | function paintMethodEnd() { 36 | echo "\n"; 37 | } 38 | 39 | function paintFail() { 40 | echo " [FAILED]"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Connection/Configuration.php: -------------------------------------------------------------------------------- 1 | Testing Crystal configuration options'; 12 | 13 | } 14 | 15 | 16 | function TestBlankCongigurationParam() 17 | { 18 | 19 | $method = Crystal::db(); 20 | $test_object = (is_object($method->conn))?'True':'False'; 21 | $this->assertTrue($test_object); 22 | } 23 | 24 | 25 | function TestAlternativeCongigurationParam() 26 | { 27 | 28 | $method = Crystal::db('production'); 29 | $test_object = (is_object($method->conn))?'True':'False'; 30 | $this->assertTrue($test_object); 31 | } 32 | 33 | 34 | 35 | function TestCongigurationArrayParam() 36 | { 37 | 38 | $method = Crystal::db($config_mysql); 39 | $test_object = (is_object($method->conn))?'True':'False'; 40 | $this->assertTrue($test_object); 41 | } 42 | 43 | 44 | function TestAlternativeconfigFileParam() 45 | { 46 | 47 | $method = Crystal::db($config_file, 'production'); 48 | $test_object = (is_object($method->conn))?'True':'False'; 49 | $this->assertTrue($test_object); 50 | } 51 | 52 | 53 | 54 | 55 | 56 | } -------------------------------------------------------------------------------- /tests/QueryBuilders/Groupby.php: -------------------------------------------------------------------------------- 1 | Testing Crystal group_by() function'; 10 | $this->db = Crystal::db(); 11 | } 12 | 13 | 14 | function TestStringParam() 15 | { 16 | $this->db->clear_sql(); 17 | $method = $this->db->group_by('product_id'); 18 | $this->assertEqual($method->sql, " GROUP BY 'product_id' "); 19 | } 20 | 21 | 22 | function TestMultipleStringsParam() 23 | { 24 | $this->db->clear_sql(); 25 | $method = $this->db->group_by('product_id, category_id'); 26 | $this->assertEqual($method->sql, " GROUP BY 'product_id' , 'category_id' "); 27 | } 28 | 29 | 30 | 31 | function TestArrayParam() 32 | { 33 | $this->db->clear_sql(); 34 | $method = $this->db->group_by(array('product_id', 'category_id')); 35 | $this->assertEqual($method->sql, " GROUP BY 'product_id' , 'category_id' "); 36 | 37 | } 38 | 39 | function TestEmptyParam() 40 | { 41 | $this->db->clear_sql(); 42 | $method = $this->db->group_by(); 43 | $this->assertFalse($method->sql, 'MySQL group_by with no params should be false'); 44 | 45 | } 46 | 47 | 48 | 49 | } -------------------------------------------------------------------------------- /Crystal/Validation/MinLength.php: -------------------------------------------------------------------------------- 1 | = $value) 36 | { 37 | $this->result = TRUE; 38 | } 39 | else 40 | { 41 | $this->result = FALSE; 42 | } 43 | 44 | 45 | 46 | } 47 | else 48 | { 49 | $this->result = FALSE; 50 | } 51 | 52 | } 53 | 54 | 55 | function __toString() 56 | { 57 | return $this->result; 58 | } 59 | 60 | } 61 | /* END OF FILE **/ -------------------------------------------------------------------------------- /tests/Validation/Extension.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Extension validation with string should be false'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Extension(array('test')); 18 | $this->assertFalse($alpha->result, 'Extension validation with array should be false'); 19 | 20 | } 21 | 22 | 23 | function TestValidParam() 24 | { 25 | $alpha = new Crystal_Validation_Extension('test.jpg', array('jpg','bmp')); 26 | $this->assertTrue($alpha->result, 'Extension validation with valid extension should be true'); 27 | 28 | } 29 | 30 | function TestInValidParam() 31 | { 32 | $alpha = new Crystal_Validation_Extension('test.psd', array('jpg','bmp')); 33 | $this->assertFalse($alpha->result, 'Extension validation with wrong extension should be false'); 34 | 35 | } 36 | 37 | function TestEmptyParam() 38 | { 39 | $alpha = new Crystal_Validation_Extension(); 40 | $this->assertFalse($alpha->result, 'Extension validation with no params should be false'); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /tests/validations.php: -------------------------------------------------------------------------------- 1 | addTestFile(CRYSTAL_VALIDATION_TESTS .'Alpha.php'); 11 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'AlphaNumeric.php'); 12 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Between.php'); 13 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Boolean.php'); 14 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Comparsion.php'); 15 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Email.php'); 16 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Extension.php'); 17 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Integer.php'); 18 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Ip.php'); 19 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Matches.php'); 20 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'MaxLength.php'); 21 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'MinLength.php'); 22 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Numeric.php'); 23 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Regexp.php'); 24 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Required.php'); 25 | $test->addTestFile(CRYSTAL_VALIDATION_TESTS .'Url.php'); 26 | 27 | 28 | 29 | $test->run(new ShowPasses()); 30 | -------------------------------------------------------------------------------- /Crystal/Validation/Between.php: -------------------------------------------------------------------------------- 1 | $params[0] && $field_data < $params[1]) 38 | { 39 | $this->result = TRUE; 40 | 41 | } 42 | else 43 | { 44 | $this->result = FALSE; 45 | } 46 | 47 | 48 | 49 | } 50 | else 51 | { 52 | 53 | $this->result = FALSE; 54 | } 55 | 56 | 57 | 58 | } 59 | 60 | function __toString() 61 | { 62 | 63 | return $this->result; 64 | } 65 | 66 | } 67 | /* END OF FILE **/ -------------------------------------------------------------------------------- /tests/simpletest/test/eclipse_test.php: -------------------------------------------------------------------------------- 1 | expectOnce('write',array($expected)); 22 | $listener->setReturnValue('write',-1); 23 | 24 | $pathparts = pathinfo($fullpath); 25 | $filename = $pathparts['basename']; 26 | $test= &new TestSuite($filename); 27 | $test->addTestFile($fullpath); 28 | $test->run(new EclipseReporter(&$listener)); 29 | $this->assertEqual($expected,$listener->output); 30 | } 31 | } 32 | ?> -------------------------------------------------------------------------------- /tests/simpletest/test/shell_test.php: -------------------------------------------------------------------------------- 1 | assertIdentical($shell->execute('echo Hello'), 0); 11 | $this->assertPattern('/Hello/', $shell->getOutput()); 12 | } 13 | 14 | function testBadCommand() { 15 | $shell = &new SimpleShell(); 16 | $this->assertNotEqual($ret = $shell->execute('blurgh! 2>&1'), 0); 17 | } 18 | } 19 | 20 | class TestOfShellTesterAndShell extends ShellTestCase { 21 | 22 | function testEcho() { 23 | $this->assertTrue($this->execute('echo Hello')); 24 | $this->assertExitCode(0); 25 | $this->assertoutput('Hello'); 26 | } 27 | 28 | function testFileExistence() { 29 | $this->assertFileExists(dirname(__FILE__) . '/all_tests.php'); 30 | $this->assertFileNotExists('wibble'); 31 | } 32 | 33 | function testFilePatterns() { 34 | $this->assertFilePattern('/all[_ ]tests/i', dirname(__FILE__) . '/all_tests.php'); 35 | $this->assertNoFilePattern('/sputnik/i', dirname(__FILE__) . '/all_tests.php'); 36 | } 37 | } 38 | ?> -------------------------------------------------------------------------------- /Crystal/Manipulation/Mysql/Options.php: -------------------------------------------------------------------------------- 1 | options = ''; 30 | 31 | $this->options .= self::process_options($params); 32 | 33 | 34 | } 35 | 36 | 37 | function process_options($options) 38 | { 39 | 40 | $this->options = ''; 41 | 42 | 43 | if(array_key_exists('primary_key', $options)) 44 | { 45 | $this->options .= "PRIMARY KEY (" . Crystal_Helper_Mysql::add_apostrophe($options['primary_key']) . " ) "; 46 | } 47 | 48 | 49 | } 50 | 51 | public function __toString() 52 | { 53 | return $this->options; 54 | } 55 | 56 | 57 | /* 58 | CREATE TABLE `magento`.`admin_user` ( 59 | `id` INT NOT NULL AUTO_INCREMENT , 60 | `title` VARCHAR( 128 ) NOT NULL , 61 | `content` TEXT NOT NULL , 62 | PRIMARY KEY ( `id` ) 63 | ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci; 64 | */ 65 | 66 | 67 | } -------------------------------------------------------------------------------- /Crystal/Manipulation/Postgres/Options.php: -------------------------------------------------------------------------------- 1 | options = ''; 30 | 31 | $this->options .= self::process_options($params); 32 | 33 | 34 | } 35 | 36 | 37 | function process_options($options) 38 | { 39 | 40 | $this->options = ''; 41 | 42 | 43 | if(array_key_exists('primary_key', $options)) 44 | { 45 | $this->options .= "PRIMARY KEY (" . Crystal_Helper_Postgres::add_single_quote($options['primary_key']) . " ) "; 46 | } 47 | 48 | 49 | } 50 | 51 | public function __toString() 52 | { 53 | return $this->options; 54 | } 55 | 56 | 57 | /* 58 | CREATE TABLE `magento`.`admin_user` ( 59 | `id` INT NOT NULL AUTO_INCREMENT , 60 | `title` VARCHAR( 128 ) NOT NULL , 61 | `content` TEXT NOT NULL , 62 | PRIMARY KEY ( `id` ) 63 | ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci; 64 | */ 65 | 66 | 67 | } -------------------------------------------------------------------------------- /Crystal/Query/Expression.php: -------------------------------------------------------------------------------- 1 | query->sql = "SELECT MIN(?) AS ?"; 27 | $this->query->params = $expression[0]; 28 | $this->query->type = 'min'; 29 | break; 30 | 31 | case 'max': 32 | $this->query->sql = "SELECT MAX(?) AS ?"; 33 | $this->query->params = $expression[0]; 34 | $this->query->type = 'max'; 35 | break; 36 | 37 | case 'average': 38 | $this->query->sql = "SELECT AVG(?) AS ?"; 39 | $this->query->params = $expression[0]; 40 | $this->query->type = 'average'; 41 | break; 42 | 43 | case 'summary': 44 | $this->query->sql = "SELECT SUM(?) AS ?"; 45 | $this->query->params = $expression[0]; 46 | $this->query->type = 'summary'; 47 | break; 48 | 49 | default: 50 | throw new Crystal_Query_Expression("Undefined expression: " . $method); 51 | break; 52 | } 53 | 54 | 55 | return $this->query; 56 | 57 | } 58 | 59 | 60 | } -------------------------------------------------------------------------------- /Crystal/Query/Insert.php: -------------------------------------------------------------------------------- 1 | query->type = 'insert'; 22 | 23 | /** CHECKS TABLE **/ 24 | if(is_string($params[0])) 25 | { 26 | $this->query->sql = 'INSERT INTO ?'; 27 | $this->query->params[] = $params[0]; 28 | 29 | } 30 | else 31 | { 32 | throw new Crystal_Query_Exception("Expecting string for table in insert() function"); 33 | } 34 | 35 | 36 | /** CHECK COLUMNS **/ 37 | if(is_array($params[1])) 38 | { 39 | $data = $params[1]; 40 | } 41 | else 42 | { 43 | throw new Crystal_Query_Exception("Expecting array for data in insert() function"); 44 | } 45 | 46 | $total_columns = count($params[1]); 47 | 48 | $elements = str_repeat('?,', $total_columns); 49 | // Remove the last comma 50 | $elements = substr($elements,'',-1); 51 | 52 | $this->query->sql .= sprintf("(%s)", $elements); 53 | $this->query->sql .= sprintf("VALUES(%s)", $elements); 54 | $this->query->params[] = $params[1]; 55 | 56 | 57 | 58 | return $this->query; 59 | 60 | 61 | } 62 | 63 | 64 | 65 | } -------------------------------------------------------------------------------- /Crystal/Query/Join.php: -------------------------------------------------------------------------------- 1 | query->sql = "LEFT JOIN ? ON ?"; 25 | $this->query->params = $params; 26 | $this->query->type = 'left_join'; 27 | break; 28 | 29 | 30 | case 'right_join': 31 | $this->query->sql = "RIGHT JOIN ? ON ?"; 32 | $this->query->params = $params; 33 | $this->query->type = 'right_join'; 34 | break; 35 | 36 | 37 | case 'outer_join': 38 | $this->query->sql = "OUTER JOIN ? ON ?"; 39 | $this->query->params = $params; 40 | $this->query->type = 'outer_join'; 41 | break; 42 | 43 | 44 | case 'inner_join': 45 | $this->query->sql = "INNER JOIN ? ON ?"; 46 | $this->query->params = $params; 47 | $this->query->type = 'inner_join'; 48 | break; 49 | 50 | 51 | default: 52 | $this->query->sql = "JOIN ? ON ?"; 53 | $this->query->params = $params; 54 | $this->query->type = 'join'; 55 | break; 56 | } 57 | 58 | 59 | 60 | return $this->query; 61 | 62 | } 63 | 64 | 65 | 66 | } -------------------------------------------------------------------------------- /Crystal/Query/Update.php: -------------------------------------------------------------------------------- 1 | update = "UPDATE " . Crystal_Helper_Mysql::add_apostrophe($table) . " SET "; 47 | 48 | 49 | 50 | if(isset($data)) 51 | { 52 | 53 | if($method == 'update_safe') 54 | { 55 | $this->update .= Crystal_Helper_Mysql::escape_update_values_safe($data); 56 | } 57 | else 58 | { 59 | $this->update .= Crystal_Helper_Mysql::escape_update_values($data); 60 | } 61 | 62 | 63 | } 64 | 65 | 66 | return $this->query; 67 | 68 | } 69 | 70 | 71 | 72 | } -------------------------------------------------------------------------------- /Crystal/Error/Validation.php: -------------------------------------------------------------------------------- 1 | _mock_shell; 12 | } 13 | 14 | function testGenericEquality() { 15 | $this->assertEqual('a', 'a'); 16 | $this->assertNotEqual('a', 'A'); 17 | } 18 | 19 | function testExitCode() { 20 | $this->_mock_shell = &new MockSimpleShell(); 21 | $this->_mock_shell->setReturnValue('execute', 0); 22 | $this->_mock_shell->expectOnce('execute', array('ls')); 23 | $this->assertTrue($this->execute('ls')); 24 | $this->assertExitCode(0); 25 | } 26 | 27 | function testOutput() { 28 | $this->_mock_shell = &new MockSimpleShell(); 29 | $this->_mock_shell->setReturnValue('execute', 0); 30 | $this->_mock_shell->setReturnValue('getOutput', "Line 1\nLine 2\n"); 31 | $this->assertOutput("Line 1\nLine 2\n"); 32 | } 33 | 34 | function testOutputPatterns() { 35 | $this->_mock_shell = &new MockSimpleShell(); 36 | $this->_mock_shell->setReturnValue('execute', 0); 37 | $this->_mock_shell->setReturnValue('getOutput', "Line 1\nLine 2\n"); 38 | $this->assertOutputPattern('/line/i'); 39 | $this->assertNoOutputPattern('/line 2/'); 40 | } 41 | } 42 | ?> -------------------------------------------------------------------------------- /tests/QueryBuilders/Where.php: -------------------------------------------------------------------------------- 1 | Testing Crystal where() function'; 10 | } 11 | 12 | 13 | function TestArrayParam() 14 | { 15 | 16 | $method = new Crystal_Query_Where('where', array('product_id' => '1', 'client_id' => '5')); 17 | $this->assertEqual($method->sql, " WHERE `product_id` = '1' AND `client_id` = '5' "); 18 | //echo("
" .$method->sql[22] . "
"); 19 | 20 | } 21 | 22 | function TestStringParam() 23 | { 24 | $this->db->clear_sql(); 25 | $method = $this->db->where('product_id','2'); 26 | $this->assertEqual($method->sql, " WHERE `product_id` = '2' "); 27 | 28 | 29 | } 30 | 31 | function TestColonParam() 32 | { 33 | $this->db->clear_sql(); 34 | $method = $this->db->where('product_id : 2'); 35 | $this->assertEqual($method->sql, " WHERE `product_id` = '2' "); 36 | 37 | } 38 | 39 | 40 | function TestMultipleColonParam() 41 | { 42 | $this->db->clear_sql(); 43 | $method = $this->db->where('product_id : 2, client_status : active'); 44 | $this->assertEqual($method->sql, " WHERE `product_id` = '2' AND `client_status` = 'active' "); 45 | 46 | } 47 | 48 | 49 | function TestEmptyParam() 50 | { 51 | 52 | $this->db->clear_sql(); 53 | $method = $this->db->where(); 54 | $this->assertFalse($method->sql, 'MySQL SELECT with no params should be false'); 55 | 56 | } 57 | 58 | 59 | } -------------------------------------------------------------------------------- /tests/simpletest/test/command_line_test.php: -------------------------------------------------------------------------------- 1 | assertIdentical($parser->getTest(), ''); 10 | $this->assertIdentical($parser->getTestCase(), ''); 11 | } 12 | 13 | function testNotXmlByDefault() { 14 | $parser = new SimpleCommandLineParser(array()); 15 | $this->assertFalse($parser->isXml()); 16 | } 17 | 18 | function testCanDetectRequestForXml() { 19 | $parser = new SimpleCommandLineParser(array('--xml')); 20 | $this->assertTrue($parser->isXml()); 21 | } 22 | 23 | function testCanReadAssignmentSyntax() { 24 | $parser = new SimpleCommandLineParser(array('--test=myTest')); 25 | $this->assertEqual($parser->getTest(), 'myTest'); 26 | } 27 | 28 | function testCanReadFollowOnSyntax() { 29 | $parser = new SimpleCommandLineParser(array('--test', 'myTest')); 30 | $this->assertEqual($parser->getTest(), 'myTest'); 31 | } 32 | 33 | function testCanReadShortForms() { 34 | $parser = new SimpleCommandLineParser(array('-t', 'myTest', '-c', 'MyClass', '-x')); 35 | $this->assertEqual($parser->getTest(), 'myTest'); 36 | $this->assertEqual($parser->getTestCase(), 'MyClass'); 37 | $this->assertTrue($parser->isXml()); 38 | } 39 | } 40 | ?> -------------------------------------------------------------------------------- /messages/validation_errors.php: -------------------------------------------------------------------------------- 1 | assertTrue($this->assertTrue(true)); 12 | } 13 | 14 | function testAssertFalseReturnsAssertionAsBoolean() { 15 | $this->assertTrue($this->assertFalse(false)); 16 | } 17 | 18 | function testAssertEqualReturnsAssertionAsBoolean() { 19 | $this->assertTrue($this->assertEqual(5, 5)); 20 | } 21 | 22 | function testAssertIdenticalReturnsAssertionAsBoolean() { 23 | $this->assertTrue($this->assertIdentical(5, 5)); 24 | } 25 | 26 | function testCoreAssertionsDoNotThrowErrors() { 27 | $this->assertIsA($this, 'UnitTestCase'); 28 | $this->assertNotA($this, 'WebTestCase'); 29 | } 30 | 31 | function testReferenceAssertionOnObjects() { 32 | $a = &new ReferenceForTesting(); 33 | $b = &$a; 34 | $this->assertReference($a, $b); 35 | } 36 | 37 | function testReferenceAssertionOnScalars() { 38 | $a = 25; 39 | $b = &$a; 40 | $this->assertReference($a, $b); 41 | } 42 | 43 | function testCloneOnObjects() { 44 | $a = &new ReferenceForTesting(); 45 | $b = &new ReferenceForTesting(); 46 | $this->assertClone($a, $b); 47 | } 48 | 49 | function testCloneOnScalars() { 50 | $a = 25; 51 | $b = 25; 52 | $this->assertClone($a, $b); 53 | } 54 | } 55 | ?> -------------------------------------------------------------------------------- /tests/simpletest/docs/fr/docs.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-left: 3%; 3 | padding-right: 3%; 4 | } 5 | pre { 6 | font-family: "courier new", courier; 7 | font-size: 80%; 8 | border: 1px solid; 9 | background-color: #cccccc; 10 | padding: 5px; 11 | margin-left: 5%; 12 | margin-right: 8%; 13 | } 14 | .code, .new_code, pre.new_code { 15 | font-weight: bold; 16 | } 17 | div.copyright { 18 | font-size: 80%; 19 | color: gray; 20 | } 21 | div.copyright a { 22 | color: gray; 23 | } 24 | ul.api { 25 | padding-left: 0em; 26 | padding-right: 25%; 27 | } 28 | ul.api li { 29 | margin-top: 0.2em; 30 | margin-bottom: 0.2em; 31 | list-style: none; 32 | text-indent: -3em; 33 | padding-left: 3em; 34 | } 35 | div.demo { 36 | border: 4px ridge; 37 | border-color: gray; 38 | padding: 10px; 39 | margin: 5px; 40 | margin-left: 20px; 41 | margin-right: 40px; 42 | background-color: white; 43 | } 44 | div.demo span.fail { 45 | color: red; 46 | } 47 | div.demo span.pass { 48 | color: green; 49 | } 50 | div.demo h1 { 51 | font-size: 12pt; 52 | text-align: left; 53 | font-weight: bold; 54 | } 55 | table { 56 | border: 2px outset; 57 | border-color: gray; 58 | background-color: white; 59 | margin: 5px; 60 | margin-left: 5%; 61 | margin-right: 5%; 62 | } 63 | td { 64 | font-size: 80%; 65 | } 66 | .shell { 67 | color: white; 68 | } 69 | pre.shell { 70 | border: 4px ridge; 71 | border-color: gray; 72 | padding: 10px; 73 | margin: 5px; 74 | margin-left: 20px; 75 | margin-right: 40px; 76 | background-color: black; 77 | } 78 | form.demo { 79 | background-color: lightgray; 80 | border: 4px outset; 81 | border-color: lightgray; 82 | padding: 10px; 83 | margin-right: 40%; 84 | } 85 | -------------------------------------------------------------------------------- /Crystal/Query/Groupby.php: -------------------------------------------------------------------------------- 1 | query->type = 'groupby'; 23 | 24 | if(is_array($groupby) && !empty($groupby)) 25 | { 26 | 27 | $this->query->sql = " GROUP BY"; 28 | 29 | $filtered_params = Crystal_Parser_String::parse($groupby[0]); 30 | 31 | print_r($filtered_params); 32 | /** SINGLE PARAMETER HERE */ 33 | if(is_string($filtered_params['string'])) 34 | { 35 | $this->query->sql .= " ?"; 36 | $this->query->params = $filtered_params['string']; 37 | 38 | } 39 | elseif(is_array($filtered_params) && !empty($filtered_params)) 40 | { 41 | 42 | end($filtered_params); 43 | $last_element = key($filtered_params); 44 | reset($filtered_params); 45 | 46 | 47 | foreach($filtered_params as $key => $value) 48 | { 49 | 50 | $this->query->sql .= " ?"; 51 | $this->query->params[] = $value; 52 | 53 | if($key != $last_element){ $this->query->sql .= ','; } 54 | 55 | } 56 | 57 | 58 | } 59 | else 60 | { 61 | throw new Crystal_Query_Exception('Invalid parameters in the group_by function'); 62 | } 63 | 64 | 65 | } 66 | 67 | 68 | return $this->query; 69 | 70 | } 71 | 72 | 73 | 74 | } -------------------------------------------------------------------------------- /tests/QueryBuilders/Select.php: -------------------------------------------------------------------------------- 1 | Testing Crystal select() function'; 10 | $this->db = Crystal::db(); 11 | } 12 | 13 | 14 | function TestStringParam() 15 | { 16 | $this->db->clear_sql(); 17 | $method = $this->db->select('column'); 18 | $this->assertEqual($method->sql, 'SELECT `column` '); 19 | } 20 | 21 | 22 | function TestNotParsedParam() 23 | { 24 | $this->db->clear_sql(); 25 | $method = $this->db->select('column, MIN(salary)', False); 26 | $this->assertEqual($method->sql, 'SELECT column, MIN(salary) '); 27 | } 28 | 29 | 30 | 31 | function TestArrayParam() 32 | { 33 | $this->db->clear_sql(); 34 | $method = $this->db->select(array('column')); 35 | $this->assertEqual($method->sql, 'SELECT `column` '); 36 | 37 | } 38 | 39 | function TestMultipleParams() 40 | { 41 | $this->db->clear_sql(); 42 | $method = $this->db->select(('column, another_column')); 43 | $this->assertEqual($method->sql, 'SELECT `column` , `another_column` '); 44 | 45 | } 46 | 47 | 48 | function TestStringWithColonParam() 49 | { 50 | $this->db->clear_sql(); 51 | $method = $this->db->select('very_long_column :as column'); 52 | $this->assertEqual($method->sql, 'SELECT `very_long_column` AS `column` '); 53 | 54 | } 55 | 56 | 57 | function TestMultipleParamsWithColonParam() 58 | { 59 | $this->db->clear_sql(); 60 | $method = $this->db->select('very_long_column :as column, column '); 61 | 62 | $this->assertEqual($method->sql, 'SELECT `very_long_column` AS `column` , `column` '); 63 | } 64 | 65 | 66 | function TestEmptyParam() 67 | { 68 | 69 | $this->db->clear_sql(); 70 | $method = $this->db->select(); 71 | $this->assertFalse($method->sql, 'MySQL SELECT with no params should be false'); 72 | 73 | } 74 | 75 | 76 | } -------------------------------------------------------------------------------- /Crystal/Manipulation/Postgres/Create.php: -------------------------------------------------------------------------------- 1 | create = "CREATE DATABASE " . $params[0]; 34 | break; 35 | 36 | 37 | case 'create_table': 38 | $this->create = "CREATE TABLE " . $params[0] . " (%s)"; 39 | 40 | /** TABLE OPTIONS **/ 41 | if(isset($params[1]) && !empty($params[1])) 42 | { 43 | $this->create .= self::parse_table_options($params[1]); 44 | } 45 | break; 46 | 47 | default: 48 | break; 49 | } 50 | 51 | 52 | } 53 | 54 | 55 | function parse_table_options($params) 56 | { 57 | 58 | $this->options = ''; 59 | 60 | if(array_key_exists('engine', $params)) 61 | { 62 | 63 | $this->options .= " ENGINE = " .$params['engine']; 64 | 65 | } 66 | 67 | if(array_key_exists('char_set', $params)) 68 | { 69 | 70 | $this->options .= " CHARACTER SET " .$params['char_set']; 71 | 72 | } 73 | 74 | 75 | if(array_key_exists('collation', $params)) 76 | { 77 | 78 | $this->options .= " COLLATE " .$params['collation']; 79 | 80 | } 81 | 82 | return $this->options; 83 | 84 | 85 | 86 | } 87 | 88 | 89 | 90 | 91 | 92 | 93 | public function __toString() 94 | { 95 | return $this->create; 96 | } 97 | 98 | 99 | } -------------------------------------------------------------------------------- /tests/simpletest/test/simpletest_test.php: -------------------------------------------------------------------------------- 1 | fail('Should be ignored'); 11 | } 12 | } 13 | 14 | class ShouldNeverBeRunEither extends ShouldNeverBeRun { } 15 | 16 | class TestOfStackTrace extends UnitTestCase { 17 | 18 | function testCanFindAssertInTrace() { 19 | $trace = new SimpleStackTrace(array('assert')); 20 | $this->assertEqual( 21 | $trace->traceMethod(array(array( 22 | 'file' => '/my_test.php', 23 | 'line' => 24, 24 | 'function' => 'assertSomething'))), 25 | ' at [/my_test.php line 24]'); 26 | } 27 | } 28 | 29 | class DummyResource { } 30 | 31 | class TestOfContext extends UnitTestCase { 32 | 33 | function testCurrentContextIsUnique() { 34 | $this->assertReference( 35 | SimpleTest::getContext(), 36 | SimpleTest::getContext()); 37 | } 38 | 39 | function testContextHoldsCurrentTestCase() { 40 | $context = &SimpleTest::getContext(); 41 | $this->assertReference($this, $context->getTest()); 42 | } 43 | 44 | function testResourceIsSingleInstanceWithContext() { 45 | $context = &new SimpleTestContext(); 46 | $this->assertReference( 47 | $context->get('DummyResource'), 48 | $context->get('DummyResource')); 49 | } 50 | 51 | function testClearingContextResetsResources() { 52 | $context = &new SimpleTestContext(); 53 | $resource = &$context->get('DummyResource'); 54 | $context->clear(); 55 | $this->assertClone($resource, $context->get('DummyResource')); 56 | } 57 | } 58 | ?> -------------------------------------------------------------------------------- /tests/simpletest/test/live_test.php: -------------------------------------------------------------------------------- 1 | assertTrue($socket->isError()); 17 | $this->assertPattern( 18 | '/Cannot open \\[bad_url:111\\] with \\[/', 19 | $socket->getError()); 20 | $this->assertFalse($socket->isOpen()); 21 | $this->assertFalse($socket->write('A message')); 22 | } 23 | 24 | function testSocketClosure() { 25 | $socket = &new SimpleSocket('www.lastcraft.com', 80, 15, 8); 26 | $this->assertTrue($socket->isOpen()); 27 | $this->assertTrue($socket->write("GET /test/network_confirm.php HTTP/1.0\r\n")); 28 | $socket->write("Host: www.lastcraft.com\r\n"); 29 | $socket->write("Connection: close\r\n\r\n"); 30 | $this->assertEqual($socket->read(), "HTTP/1.1"); 31 | $socket->close(); 32 | $this->assertIdentical($socket->read(), false); 33 | } 34 | 35 | function testRecordOfSentCharacters() { 36 | $socket = &new SimpleSocket('www.lastcraft.com', 80, 15); 37 | $this->assertTrue($socket->write("GET /test/network_confirm.php HTTP/1.0\r\n")); 38 | $socket->write("Host: www.lastcraft.com\r\n"); 39 | $socket->write("Connection: close\r\n\r\n"); 40 | $socket->close(); 41 | $this->assertEqual($socket->getSent(), 42 | "GET /test/network_confirm.php HTTP/1.0\r\n" . 43 | "Host: www.lastcraft.com\r\n" . 44 | "Connection: close\r\n\r\n"); 45 | } 46 | } 47 | ?> -------------------------------------------------------------------------------- /Crystal/Manipulation/Mysql/Create.php: -------------------------------------------------------------------------------- 1 | create = "CREATE DATABASE " . Crystal_Helper_Mysql::add_apostrophe($params[0]); 34 | break; 35 | 36 | 37 | case 'create_table': 38 | $this->create = "CREATE TABLE " . Crystal_Helper_Mysql::add_apostrophe($params[0]) . " (%s)"; 39 | 40 | /** TABLE OPTIONS **/ 41 | if(isset($params[1]) && !empty($params[1])) 42 | { 43 | $this->create .= self::parse_table_options($params[1]); 44 | } 45 | break; 46 | 47 | default: 48 | break; 49 | } 50 | 51 | 52 | } 53 | 54 | 55 | function parse_table_options($params) 56 | { 57 | 58 | $this->options = ''; 59 | 60 | if(array_key_exists('engine', $params)) 61 | { 62 | 63 | $this->options .= " ENGINE = " .$params['engine']; 64 | 65 | } 66 | 67 | if(array_key_exists('char_set', $params)) 68 | { 69 | 70 | $this->options .= " CHARACTER SET " .$params['char_set']; 71 | 72 | } 73 | 74 | 75 | if(array_key_exists('collation', $params)) 76 | { 77 | 78 | $this->options .= " COLLATE " .$params['collation']; 79 | 80 | } 81 | 82 | return $this->options; 83 | 84 | 85 | 86 | } 87 | 88 | 89 | 90 | 91 | 92 | 93 | public function __toString() 94 | { 95 | return $this->create; 96 | } 97 | 98 | 99 | } -------------------------------------------------------------------------------- /tests/Validation/Comparsion.php: -------------------------------------------------------------------------------- 1 | assertFalse($alpha->result, 'Comparsion validation with string should be true'); 13 | } 14 | 15 | function TestArrayParam() 16 | { 17 | $alpha = new Crystal_Validation_Comparsion(array('test')); 18 | $this->assertFalse($alpha->result, 'Comparsion validation with array having one element should be false'); 19 | 20 | } 21 | 22 | 23 | function TestValidLessOrEqualParam() 24 | { 25 | $alpha = new Crystal_Validation_Comparsion('5', array('<=', '7')); 26 | $this->assertTrue($alpha->result, 'Comparsion validation with less or equal param should be true'); 27 | 28 | } 29 | 30 | function TestValidEqualParam() 31 | { 32 | $alpha = new Crystal_Validation_Comparsion('7', array('=', '7')); 33 | $this->assertTrue($alpha->result, 'Comparsion validation with equal param should be true'); 34 | 35 | } 36 | 37 | function TestValidMoreOrEqualParam() 38 | { 39 | $alpha = new Crystal_Validation_Comparsion('8', array('>=', '7')); 40 | $this->assertTrue($alpha->result, 'Comparsion validation with more or equal param should be true'); 41 | 42 | } 43 | 44 | function TestValidMoreParam() 45 | { 46 | $alpha = new Crystal_Validation_Comparsion('8', array('>', '7')); 47 | $this->assertTrue($alpha->result, 'Comparsion validation with more param should be true'); 48 | 49 | } 50 | 51 | function TestValidLessParam() 52 | { 53 | $alpha = new Crystal_Validation_Comparsion('5', array('<', '7')); 54 | $this->assertTrue($alpha->result, 'Comparsion validation with less param should be true'); 55 | 56 | } 57 | 58 | function TestEmptyParam() 59 | { 60 | $alpha = new Crystal_Validation_Comparsion(); 61 | $this->assertFalse($alpha->result, 'Comparsion validation with no params should be false'); 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /tests/simpletest/test/collector_test.php: -------------------------------------------------------------------------------- 1 | EqualExpectation(str_replace("\\", '/', $value), $message); 11 | } 12 | 13 | function test($compare) { 14 | return parent::test(str_replace("\\", '/', $compare)); 15 | } 16 | } 17 | 18 | class TestOfCollector extends UnitTestCase { 19 | 20 | function testCollectionIsAddedToGroup() { 21 | $suite = &new MockTestSuite(); 22 | $suite->expectMinimumCallCount('addTestFile', 2); 23 | $suite->expectArguments( 24 | 'addTestFile', 25 | array(new PatternExpectation('/collectable\\.(1|2)$/'))); 26 | $collector = &new SimpleCollector(); 27 | $collector->collect($suite, dirname(__FILE__) . '/support/collector/'); 28 | } 29 | } 30 | 31 | class TestOfPatternCollector extends UnitTestCase { 32 | 33 | function testAddingEverythingToGroup() { 34 | $suite = &new MockTestSuite(); 35 | $suite->expectCallCount('addTestFile', 2); 36 | $suite->expectArguments( 37 | 'addTestFile', 38 | array(new PatternExpectation('/collectable\\.(1|2)$/'))); 39 | $collector = &new SimplePatternCollector('/.*/'); 40 | $collector->collect($suite, dirname(__FILE__) . '/support/collector/'); 41 | } 42 | 43 | function testOnlyMatchedFilesAreAddedToGroup() { 44 | $suite = &new MockTestSuite(); 45 | $suite->expectOnce('addTestFile', array(new PathEqualExpectation( 46 | dirname(__FILE__) . '/support/collector/collectable.1'))); 47 | $collector = &new SimplePatternCollector('/1$/'); 48 | $collector->collect($suite, dirname(__FILE__) . '/support/collector/'); 49 | } 50 | } 51 | ?> -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | Testing Crystal order_by() function'; 10 | $this->db = Crystal::db(); 11 | } 12 | 13 | 14 | function TestStringParam() 15 | { 16 | $this->db->clear_sql(); 17 | $method = $this->db->order_by('product_id', 'ASC'); 18 | $this->assertEqual($method->sql, " ORDER BY `product_id` ASC"); 19 | } 20 | 21 | 22 | 23 | function TestArrayParam() 24 | { 25 | $this->db->clear_sql(); 26 | $method = $this->db->order_by(array('product_id' => 'ASC')); 27 | $this->assertEqual($method->sql, " ORDER BY `product_id` ASC"); 28 | 29 | } 30 | 31 | function TestMultipleArrayParam() 32 | { 33 | $this->db->clear_sql(); 34 | $method = $this->db->order_by(array('product_id' => 'ASC', 'category_id' => 'ASC')); 35 | $this->assertEqual($method->sql, " ORDER BY `product_id` ASC , `category_id` ASC"); 36 | //echo("
" .$method->sql[31] . "
"); 37 | 38 | } 39 | 40 | 41 | function TestMinusMultipleStringParam() 42 | { 43 | $this->db->clear_sql(); 44 | $method = $this->db->order_by('product_id, -category_id'); 45 | $this->assertEqual($method->sql, " ORDER BY `product_id` DESC, `category_id` ASC"); 46 | 47 | } 48 | 49 | 50 | function TestMinusStringParam() 51 | { 52 | $this->db->clear_sql(); 53 | $method = $this->db->order_by('-category_id'); 54 | $this->assertEqual($method->sql, " ORDER BY `category_id` ASC"); 55 | 56 | } 57 | 58 | 59 | function TestStandartStringParam() 60 | { 61 | $this->db->clear_sql(); 62 | $method = $this->db->order_by('category_id'); 63 | $this->assertEqual($method->sql, " ORDER BY `category_id` DESC"); 64 | 65 | } 66 | 67 | 68 | function TestEmptyParam() 69 | { 70 | $this->db->clear_sql(); 71 | $method = $this->db->order_by(); 72 | $this->assertFalse($method->sql, 'MySQL ORDER BY with no params should be false'); 73 | 74 | } 75 | 76 | 77 | } -------------------------------------------------------------------------------- /Crystal/Loader.php: -------------------------------------------------------------------------------- 1 | _driver = $active_connection['driver']; 33 | } 34 | /** For configuration files stored at different location **/ 35 | else 36 | { 37 | $this->_driver = Crystal_Config_Reader::get_db_value($active_connection, 'driver', $additional_parameters); 38 | } 39 | 40 | 41 | } 42 | /** WORKS WITH NO PARAMETERS Crystal::db(); */ 43 | else 44 | { 45 | $this->_driver = Crystal_Config_Reader::get_db_value('default', 'driver'); 46 | 47 | 48 | } 49 | 50 | $this->_driver = ucfirst($this->_driver); 51 | 52 | 53 | 54 | 55 | } 56 | 57 | 58 | 59 | /** 60 | * CHECKS IF ACTIVE CONNECTION EXISTS 61 | * @return boolean 62 | */ 63 | private function _check_connection($active_connection) 64 | { 65 | 66 | if(isset($active_connection) && !empty($active_connection)) 67 | { 68 | 69 | return TRUE; 70 | 71 | } 72 | else 73 | { 74 | return FALSE; 75 | } 76 | 77 | } 78 | 79 | public function __toString() 80 | { 81 | return $this->_driver; 82 | } 83 | 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /tests/simpletest/test/reflection_php4_test.php: -------------------------------------------------------------------------------- 1 | assertTrue($reflection->classOrInterfaceExists()); 17 | $this->assertTrue($reflection->classOrInterfaceExistsSansAutoload()); 18 | } 19 | 20 | function testClassNonExistence() { 21 | $reflection = new SimpleReflection('UnknownThing'); 22 | $this->assertFalse($reflection->classOrInterfaceExists()); 23 | $this->assertFalse($reflection->classOrInterfaceExistsSansAutoload()); 24 | } 25 | 26 | function testDetectionOfInterfacesAlwaysFalse() { 27 | $reflection = new SimpleReflection('AnyOldThing'); 28 | $this->assertFalse($reflection->isAbstract()); 29 | $this->assertFalse($reflection->isInterface()); 30 | } 31 | 32 | function testFindingParentClass() { 33 | $reflection = new SimpleReflection('AnyOldChildThing'); 34 | $this->assertEqual(strtolower($reflection->getParent()), 'anyoldthing'); 35 | } 36 | 37 | function testMethodsListFromClass() { 38 | $reflection = new SimpleReflection('AnyOldThing'); 39 | $methods = $reflection->getMethods(); 40 | $this->assertEqualIgnoringCase($methods[0], 'aMethod'); 41 | } 42 | 43 | function testNoInterfacesForPHP4() { 44 | $reflection = new SimpleReflection('AnyOldThing'); 45 | $this->assertEqual( 46 | $reflection->getInterfaces(), 47 | array()); 48 | } 49 | 50 | function testMostGeneralPossibleSignature() { 51 | $reflection = new SimpleReflection('AnyOldThing'); 52 | $this->assertEqualIgnoringCase( 53 | $reflection->getSignature('aMethod'), 54 | 'function &aMethod()'); 55 | } 56 | 57 | function assertEqualIgnoringCase($a, $b) { 58 | return $this->assertEqual(strtolower($a), strtolower($b)); 59 | } 60 | } 61 | ?> -------------------------------------------------------------------------------- /Crystal/Connection/Adapter/Mysql.php: -------------------------------------------------------------------------------- 1 | db = mysql_connect($hostname. ':'. $port, $database_config['username'], $database_config['password'], true); 29 | /** SETS DATABASE COLLATION **/ 30 | $this->_set_charset($charset); 31 | 32 | 33 | if (!$this->db) 34 | { 35 | throw new Crystal_Connection_Exception("Cannot connect to database"); 36 | } 37 | 38 | 39 | 40 | /** CHECKS FOR database in params **/ 41 | if(isset($params) && !empty($params)) 42 | { 43 | if(array_key_exists('database', $params)) 44 | { 45 | 46 | $this->dbselect = mysql_select_db($params['database']); 47 | 48 | } 49 | 50 | } 51 | else 52 | { 53 | $this->dbselect = mysql_select_db($database_config['database'], $this->db); 54 | } 55 | 56 | 57 | 58 | if(!$this->dbselect) 59 | { 60 | throw new Crystal_Connection_Adapter_Exception("Cannot select database: " . mysql_error() ); 61 | } 62 | 63 | 64 | return $this->db; 65 | 66 | 67 | } 68 | 69 | 70 | private function _set_charset($charset = null) 71 | { 72 | 73 | if(isset($charset) && !empty($charset)) 74 | { 75 | mysql_query("SET NAMES " . $charset); 76 | } 77 | else 78 | { 79 | mysql_query("SET NAMES utf8"); 80 | } 81 | 82 | } 83 | 84 | 85 | 86 | } -------------------------------------------------------------------------------- /Crystal/Connection/Adapter/Postgres.php: -------------------------------------------------------------------------------- 1 | db = pg_connect($conn_string, PGSQL_CONNECT_FORCE_NEW); 50 | 51 | /** SETS DATABASE COLLATION **/ 52 | $this->_set_charset($database_config['char_set']=null); 53 | 54 | 55 | if (!$this->db) 56 | { 57 | throw new Crystal_Connection_Exception("Cannot connect to database"); 58 | } 59 | 60 | 61 | 62 | return $this->db; 63 | 64 | 65 | } 66 | 67 | 68 | 69 | 70 | 71 | 72 | private function _set_charset($charset) 73 | { 74 | 75 | if(isset($charset) && !empty($charset)) 76 | { 77 | pg_query("SET NAMES " . Crystal_Helper_Postgres::add_single_quote($charset)); 78 | } 79 | else 80 | { 81 | pg_query("SET NAMES 'UTF8'"); 82 | } 83 | 84 | 85 | } 86 | 87 | 88 | 89 | } -------------------------------------------------------------------------------- /Crystal/Connection/Manager.php: -------------------------------------------------------------------------------- 1 | conn = new Crystal_Connection_Adapter_Mysql($db_config); 65 | break; 66 | 67 | 68 | case 'postgres': 69 | $this->conn = new Crystal_Connection_Adapter_Postgres($db_config); 70 | break; 71 | 72 | 73 | 74 | default: 75 | throw new Crystal_Connection_Exception("Invalid database adapter"); 76 | break; 77 | } 78 | 79 | 80 | 81 | return $this->conn; 82 | 83 | 84 | } 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | } 94 | 95 | -------------------------------------------------------------------------------- /tests/simpletest/test/adapter_test.php: -------------------------------------------------------------------------------- 1 | assertTrue(true, "PEAR true"); 14 | $this->assertFalse(false, "PEAR false"); 15 | } 16 | 17 | function testName() { 18 | $this->assertTrue($this->getName() == get_class($this)); 19 | } 20 | 21 | function testPass() { 22 | $this->pass("PEAR pass"); 23 | } 24 | 25 | function testNulls() { 26 | $value = null; 27 | $this->assertNull($value, "PEAR null"); 28 | $value = 0; 29 | $this->assertNotNull($value, "PEAR not null"); 30 | } 31 | 32 | function testType() { 33 | $this->assertType("Hello", "string", "PEAR type"); 34 | } 35 | 36 | function testEquals() { 37 | $this->assertEquals(12, 12, "PEAR identity"); 38 | $this->setLooselyTyped(true); 39 | $this->assertEquals("12", 12, "PEAR equality"); 40 | } 41 | 42 | function testSame() { 43 | $same = &new SameTestClass(); 44 | $this->assertSame($same, $same, "PEAR same"); 45 | } 46 | 47 | function testRegExp() { 48 | $this->assertRegExp('/hello/', "A big hello from me", "PEAR regex"); 49 | } 50 | } 51 | 52 | class TestOfPhpUnitAdapter extends TestCase { 53 | function TestOfPhpUnitAdapter() { 54 | $this->TestCase('TestOfPhpUnitAdapter'); 55 | } 56 | 57 | function testBoolean() { 58 | $this->assert(true, 'PHP Unit true'); 59 | } 60 | 61 | function testName() { 62 | $this->assert($this->name() == 'TestOfPhpUnitAdapter'); 63 | } 64 | 65 | function testEquals() { 66 | $this->assertEquals(12, 12, 'PHP Unit equality'); 67 | } 68 | 69 | function testMultilineEquals() { 70 | $this->assertEquals("a\nb\n", "a\nb\n", 'PHP Unit equality'); 71 | } 72 | 73 | function testRegExp() { 74 | $this->assertRegexp('/hello/', 'A big hello from me', 'PHPUnit regex'); 75 | } 76 | } 77 | ?> -------------------------------------------------------------------------------- /Crystal.php: -------------------------------------------------------------------------------- 1 | [0] => '>', [1] => 'number' 31 | * or [0] => '>', [1] => 'number' 32 | * 33 | **/ 34 | $comparsion = (is_array($comparsion_options[0]))?$comparsion_options[0]:$comparsion_options; 35 | 36 | 37 | switch ($comparsion[0]) 38 | { 39 | case '>=': 40 | if($value >= $comparsion[1]) 41 | { 42 | $this->result = TRUE; 43 | } 44 | else 45 | { 46 | $this->result = FALSE; 47 | } 48 | break; 49 | 50 | case '<=': 51 | if($value <= $comparsion[1]) 52 | { 53 | $this->result = TRUE; 54 | } 55 | else 56 | { 57 | $this->result = FALSE; 58 | } 59 | break; 60 | 61 | 62 | case '>': 63 | if($value > $comparsion[1]) 64 | { 65 | $this->result = TRUE; 66 | } 67 | else 68 | { 69 | $this->result = FALSE; 70 | } 71 | break; 72 | 73 | 74 | 75 | case '<': 76 | if($value < $comparsion[1]) 77 | { 78 | $this->result = TRUE; 79 | } 80 | else 81 | { 82 | $this->result = FALSE; 83 | } 84 | break; 85 | 86 | 87 | case '=': 88 | if($value == $comparsion[1]) 89 | { 90 | $this->result = TRUE; 91 | } 92 | else 93 | { 94 | $this->result = FALSE; 95 | } 96 | break; 97 | 98 | 99 | default: 100 | break; 101 | } 102 | 103 | } 104 | 105 | function __toString() 106 | { 107 | return $this->result; 108 | } 109 | 110 | } 111 | /* END OF FILE **/ -------------------------------------------------------------------------------- /tests/simpletest/test/unit_tests.php: -------------------------------------------------------------------------------- 1 | TestSuite('Unit tests'); 14 | $path = dirname(__FILE__); 15 | $this->addFile($path . '/errors_test.php'); 16 | if (version_compare(phpversion(), '5') >= 0) { 17 | $this->addFile($path . '/exceptions_test.php'); 18 | } 19 | $this->addFile($path . '/autorun_test.php'); 20 | $this->addFile($path . '/compatibility_test.php'); 21 | $this->addFile($path . '/simpletest_test.php'); 22 | $this->addFile($path . '/dumper_test.php'); 23 | $this->addFile($path . '/expectation_test.php'); 24 | $this->addFile($path . '/unit_tester_test.php'); 25 | if (version_compare(phpversion(), '5', '>=')) { 26 | $this->addFile($path . '/reflection_php5_test.php'); 27 | } else { 28 | $this->addFile($path . '/reflection_php4_test.php'); 29 | } 30 | $this->addFile($path . '/mock_objects_test.php'); 31 | if (version_compare(phpversion(), '5', '>=')) { 32 | $this->addFile($path . '/interfaces_test.php'); 33 | } 34 | $this->addFile($path . '/collector_test.php'); 35 | $this->addFile($path . '/adapter_test.php'); 36 | $this->addFile($path . '/socket_test.php'); 37 | $this->addFile($path . '/encoding_test.php'); 38 | $this->addFile($path . '/url_test.php'); 39 | $this->addFile($path . '/cookies_test.php'); 40 | $this->addFile($path . '/http_test.php'); 41 | $this->addFile($path . '/authentication_test.php'); 42 | $this->addFile($path . '/user_agent_test.php'); 43 | $this->addFile($path . '/parser_test.php'); 44 | $this->addFile($path . '/tag_test.php'); 45 | $this->addFile($path . '/form_test.php'); 46 | $this->addFile($path . '/page_test.php'); 47 | $this->addFile($path . '/frames_test.php'); 48 | $this->addFile($path . '/browser_test.php'); 49 | $this->addFile($path . '/web_tester_test.php'); 50 | $this->addFile($path . '/shell_tester_test.php'); 51 | $this->addFile($path . '/xml_test.php'); 52 | $this->addFile($path . '/../extensions/testdox/test.php'); 53 | } 54 | } 55 | ?> 56 | -------------------------------------------------------------------------------- /Crystal/Query/Orderby.php: -------------------------------------------------------------------------------- 1 | query->sql = " ORDER BY "; 27 | $this->query->type = 'order_by'; 28 | 29 | 30 | $filtered_params = Crystal_Parser_String::parse($order[0]); 31 | 32 | /** WORKS FOR SINGLE ELEMENTS order_by('product_id') **/ 33 | if(is_string($filtered_params['string'])) 34 | { 35 | 36 | $filtered_order = self::_check_order($filtered_params['string']); 37 | 38 | $this->query->sql .= " ? ? "; 39 | $this->query->params = array($filtered_order['column'], $filtered_order['order']); 40 | 41 | } 42 | /** WORKS FOR MULTIPLE ELEMENTS order_by('product_id, -category_id') **/ 43 | else 44 | { 45 | 46 | 47 | end($filtered_params); 48 | $last_element = key($filtered_params); 49 | reset($filtered_params); 50 | 51 | foreach($filtered_params as $key => $value) 52 | { 53 | $filtered_order = self::_check_order($value); 54 | 55 | $this->query->sql .= " ? ? "; 56 | $this->query->params[] = array($filtered_order['column'], $filtered_order['order']); 57 | 58 | 59 | if($key != $last_element){ $this->query->sql .=','; } 60 | 61 | } 62 | 63 | 64 | } 65 | 66 | 67 | 68 | } 69 | else 70 | { 71 | 72 | $this->order = ''; 73 | 74 | } 75 | 76 | return $this->query->sql; 77 | 78 | } 79 | 80 | private function _check_order($string) 81 | { 82 | $asc = strpos($string, '-'); 83 | 84 | $order = array(); 85 | 86 | if($asc == True or $asc === 0) 87 | { 88 | 89 | $order['column'] = preg_replace('/-/', '', $string, 1); 90 | $order['order'] = 'ASC'; 91 | 92 | } 93 | else 94 | { 95 | 96 | $order['column'] = $string; 97 | $order['order'] = 'DESC'; 98 | 99 | } 100 | 101 | return $order; 102 | 103 | } 104 | 105 | 106 | public function __toString() 107 | { 108 | return $this->order; 109 | } 110 | 111 | 112 | } -------------------------------------------------------------------------------- /tests/simpletest/docs/en/docs.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-left: 3%; 3 | padding-right: 3%; 4 | } 5 | h1, h2, h3 { 6 | font-family: sans-serif; 7 | } 8 | h1 { 9 | text-align: center; 10 | } 11 | pre { 12 | font-family: "courier new", courier, typewriter, monospace; 13 | font-size: 90%; 14 | border: 1px solid; 15 | border-color: #999966; 16 | background-color: #ffffcc; 17 | padding: 5px; 18 | margin-left: 20px; 19 | margin-right: 40px; 20 | } 21 | .code, .new_code, pre.new_code { 22 | font-family: "courier new", courier, typewriter, monospace; 23 | font-weight: bold; 24 | } 25 | div.copyright { 26 | font-size: 80%; 27 | color: gray; 28 | } 29 | div.copyright a { 30 | margin-top: 1em; 31 | color: gray; 32 | } 33 | ul.api { 34 | border: 2px outset; 35 | border-color: gray; 36 | background-color: white; 37 | margin: 5px; 38 | margin-left: 5%; 39 | margin-right: 5%; 40 | } 41 | ul.api li { 42 | margin-top: 0.2em; 43 | margin-bottom: 0.2em; 44 | list-style: none; 45 | text-indent: -3em; 46 | padding-left: 1em; 47 | } 48 | div.demo { 49 | border: 4px ridge; 50 | border-color: gray; 51 | padding: 10px; 52 | margin: 5px; 53 | margin-left: 20px; 54 | margin-right: 40px; 55 | background-color: white; 56 | } 57 | div.demo span.fail { 58 | color: red; 59 | } 60 | div.demo span.pass { 61 | color: green; 62 | } 63 | div.demo h1 { 64 | font-size: 12pt; 65 | text-align: left; 66 | font-weight: bold; 67 | } 68 | div.menu { 69 | text-align: center; 70 | } 71 | table { 72 | border: 2px outset; 73 | border-color: gray; 74 | background-color: white; 75 | margin: 5px; 76 | margin-left: 5%; 77 | margin-right: 5%; 78 | } 79 | td { 80 | font-size: 90%; 81 | } 82 | .shell { 83 | color: white; 84 | } 85 | pre.shell { 86 | border: 4px ridge; 87 | border-color: gray; 88 | padding: 10px; 89 | margin: 5px; 90 | margin-left: 20px; 91 | margin-right: 40px; 92 | background-color: #000100; 93 | color: #99ff99; 94 | font-size: 90%; 95 | } 96 | pre.file { 97 | color: black; 98 | border: 1px solid; 99 | border-color: black; 100 | padding: 10px; 101 | margin: 5px; 102 | margin-left: 20px; 103 | margin-right: 40px; 104 | background-color: white; 105 | font-size: 90%; 106 | } 107 | form.demo { 108 | background-color: lightgray; 109 | border: 4px outset; 110 | border-color: lightgray; 111 | padding: 10px; 112 | margin-right: 40%; 113 | } 114 | dl, dd { 115 | margin: 10px; 116 | margin-left: 30px; 117 | } 118 | em { 119 | font-weight: bold; 120 | font-family: "courier new", courier, typewriter, monospace; 121 | } 122 | -------------------------------------------------------------------------------- /tests/simpletest/autorun.php: -------------------------------------------------------------------------------- 1 | createSuiteFromClasses( 30 | basename(initial_file()), 31 | $loader->selectRunnableTests($candidates)); 32 | $result = $suite->run(new DefaultReporter()); 33 | if (SimpleReporter::inCli()) { 34 | exit($result ? 0 : 1); 35 | } 36 | } 37 | 38 | /** 39 | * Checks the current test context to see if a test has 40 | * ever been run. 41 | * @return boolean True if tests have run. 42 | */ 43 | function tests_have_run() { 44 | if ($context = SimpleTest::getContext()) { 45 | return (boolean)$context->getTest(); 46 | } 47 | return false; 48 | } 49 | 50 | /** 51 | * The first autorun file. 52 | * @return string Filename of first autorun script. 53 | */ 54 | function initial_file() { 55 | static $file = false; 56 | if (! $file) { 57 | $file = reset(get_included_files()); 58 | } 59 | return $file; 60 | } 61 | 62 | /** 63 | * Just the classes from the first autorun script. May 64 | * get a few false positives, as it just does a regex based 65 | * on following the word "class". 66 | * @return array List of all possible classes in first 67 | * autorun script. 68 | */ 69 | function classes_defined_in_initial_file() { 70 | if (preg_match_all('/\bclass\s+(\w+)/i', file_get_contents(initial_file()), $matches)) { 71 | return array_map('strtolower', $matches[1]); 72 | } 73 | return array(); 74 | } 75 | 76 | /** 77 | * Every class since the first autorun include. This 78 | * is safe enough if require_once() is alwyas used. 79 | * @return array Class names. 80 | */ 81 | function capture_new_classes() { 82 | global $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES; 83 | return array_map('strtolower', array_diff(get_declared_classes(), 84 | $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES ? 85 | $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES : array())); 86 | } 87 | ?> -------------------------------------------------------------------------------- /Crystal/Helper/Postgres.php: -------------------------------------------------------------------------------- 1 | $value) 89 | { 90 | 91 | $updated_cols[] = self::sanitize_string($key) . "= " . self::add_single_quote($value) . " "; 92 | 93 | 94 | } 95 | 96 | $temp = implode(',', $updated_cols); 97 | 98 | 99 | return $temp; 100 | 101 | } 102 | 103 | 104 | static function escape_update_values_safe($cols) 105 | { 106 | 107 | foreach($cols as $key => $value) 108 | { 109 | 110 | $updated_cols[] = self::sanitize_string($key) . "=" . self::add_single_quoute($value); 111 | 112 | 113 | } 114 | 115 | $temp = implode(',', $updated_cols); 116 | 117 | 118 | return $temp; 119 | 120 | } 121 | 122 | static function clean_db_result($rows) 123 | { 124 | 125 | if(isset($rows) && !empty($rows)) 126 | { 127 | 128 | foreach($rows as $key => $column) 129 | { 130 | 131 | if(!is_numeric($column)) 132 | { 133 | 134 | $rows[$key] = stripslashes($column); 135 | 136 | } 137 | 138 | } 139 | 140 | return $rows; 141 | 142 | 143 | } 144 | 145 | 146 | 147 | 148 | 149 | } 150 | 151 | 152 | 153 | 154 | } -------------------------------------------------------------------------------- /Crystal/Query/Select.php: -------------------------------------------------------------------------------- 1 | query->type = 'select'; 21 | 22 | if($columns !=null) 23 | { 24 | if(is_array($columns)) 25 | { 26 | 27 | /** 28 | * Exception for non parsed queries: select('products, MIN(price)', False) 29 | * 30 | **/ 31 | if(isset($columns[1]) && $columns[1] == FALSE) 32 | { 33 | $this->query->sql = "SELECT ?"; 34 | $this->query->params = $columns[0]; 35 | } 36 | else 37 | { 38 | $total_elements = count($columns); 39 | 40 | /** Checks for special params like :as and explodes the string to array **/ 41 | $parsed_columns = Crystal_Parser_String::parse($columns[0]); 42 | 43 | 44 | /** Single column **/ 45 | if(is_string($parsed_columns['string'])) 46 | { 47 | $this->query->sql = "SELECT ?"; 48 | $this->query->params = $parsed_columns['string']; 49 | 50 | } 51 | /** Single column with params **/ 52 | elseif(!isset($parsed_columns[0])) 53 | { 54 | $this->select .= Crystal_Helper_Mysql::add_apostrophe($parsed_columns['column']); 55 | $this->select .= $parsed_columns['param']; 56 | $this->select .= Crystal_Helper_Mysql::add_apostrophe($parsed_columns['value']); 57 | } 58 | elseif(is_array($parsed_columns)) 59 | { 60 | 61 | $this->query->sql = "SELECT "; 62 | $last_key = end($parsed_columns); 63 | 64 | foreach($parsed_columns as $key => $column) 65 | { 66 | /** checks for column aliases select('producsts p') */ 67 | if(ereg(" ", $column)) 68 | { 69 | 70 | $this->query->sql .= "? ? "; 71 | 72 | $this->query->params[] = explode(' ', $column); 73 | } 74 | else 75 | { 76 | $this->query->sql .= '? '; 77 | $this->query->params[] = $column; 78 | 79 | } 80 | 81 | if($column != $last_key){ $this->query->sql .= ','; } 82 | } 83 | 84 | } 85 | else 86 | { 87 | throw new Crystal_Query_Exception("Invalid parameters in select()"); 88 | } 89 | 90 | 91 | 92 | } 93 | 94 | 95 | } 96 | 97 | 98 | 99 | } 100 | else 101 | { 102 | 103 | $this->query->sql = null; 104 | } 105 | 106 | 107 | 108 | return $this->query; 109 | 110 | } 111 | 112 | 113 | 114 | } -------------------------------------------------------------------------------- /Crystal/Config/Reader.php: -------------------------------------------------------------------------------- 1 | _command = $command; 34 | $this->_dry_command = $dry_command ? $dry_command : $command; 35 | $this->_size = false; 36 | } 37 | 38 | /** 39 | * Accessor for the test name for subclasses. 40 | * @return string Name of the test. 41 | * @access public 42 | */ 43 | function getLabel() { 44 | return $this->_command; 45 | } 46 | 47 | /** 48 | * Runs the top level test for this class. Currently 49 | * reads the data as a single chunk. I'll fix this 50 | * once I have added iteration to the browser. 51 | * @param SimpleReporter $reporter Target of test results. 52 | * @returns boolean True if no failures. 53 | * @access public 54 | */ 55 | function run(&$reporter) { 56 | $shell = &new SimpleShell(); 57 | $shell->execute($this->_command); 58 | $parser = &$this->_createParser($reporter); 59 | if (! $parser->parse($shell->getOutput())) { 60 | trigger_error('Cannot parse incoming XML from [' . $this->_command . ']'); 61 | return false; 62 | } 63 | return true; 64 | } 65 | 66 | /** 67 | * Accessor for the number of subtests. 68 | * @return integer Number of test cases. 69 | * @access public 70 | */ 71 | function getSize() { 72 | if ($this->_size === false) { 73 | $shell = &new SimpleShell(); 74 | $shell->execute($this->_dry_command); 75 | $reporter = &new SimpleReporter(); 76 | $parser = &$this->_createParser($reporter); 77 | if (! $parser->parse($shell->getOutput())) { 78 | trigger_error('Cannot parse incoming XML from [' . $this->_dry_command . ']'); 79 | return false; 80 | } 81 | $this->_size = $reporter->getTestCaseCount(); 82 | } 83 | return $this->_size; 84 | } 85 | 86 | /** 87 | * Creates the XML parser. 88 | * @param SimpleReporter $reporter Target of test results. 89 | * @return SimpleTestXmlListener XML reader. 90 | * @access protected 91 | */ 92 | function &_createParser(&$reporter) { 93 | return new SimpleTestXmlParser($reporter); 94 | } 95 | } 96 | ?> -------------------------------------------------------------------------------- /tests/simpletest/test/dumper_test.php: -------------------------------------------------------------------------------- 1 | assertEqual( 13 | $dumper->clipString("Hello", 6), 14 | "Hello", 15 | "Hello, 6->%s"); 16 | $this->assertEqual( 17 | $dumper->clipString("Hello", 5), 18 | "Hello", 19 | "Hello, 5->%s"); 20 | $this->assertEqual( 21 | $dumper->clipString("Hello world", 3), 22 | "Hel...", 23 | "Hello world, 3->%s"); 24 | $this->assertEqual( 25 | $dumper->clipString("Hello world", 6, 3), 26 | "Hello ...", 27 | "Hello world, 6, 3->%s"); 28 | $this->assertEqual( 29 | $dumper->clipString("Hello world", 3, 6), 30 | "...o w...", 31 | "Hello world, 3, 6->%s"); 32 | $this->assertEqual( 33 | $dumper->clipString("Hello world", 4, 11), 34 | "...orld", 35 | "Hello world, 4, 11->%s"); 36 | $this->assertEqual( 37 | $dumper->clipString("Hello world", 4, 12), 38 | "...orld", 39 | "Hello world, 4, 12->%s"); 40 | } 41 | 42 | function testDescribeNull() { 43 | $dumper = new SimpleDumper(); 44 | $this->assertPattern('/null/i', $dumper->describeValue(null)); 45 | } 46 | 47 | function testDescribeBoolean() { 48 | $dumper = new SimpleDumper(); 49 | $this->assertPattern('/boolean/i', $dumper->describeValue(true)); 50 | $this->assertPattern('/true/i', $dumper->describeValue(true)); 51 | $this->assertPattern('/false/i', $dumper->describeValue(false)); 52 | } 53 | 54 | function testDescribeString() { 55 | $dumper = new SimpleDumper(); 56 | $this->assertPattern('/string/i', $dumper->describeValue('Hello')); 57 | $this->assertPattern('/Hello/', $dumper->describeValue('Hello')); 58 | } 59 | 60 | function testDescribeInteger() { 61 | $dumper = new SimpleDumper(); 62 | $this->assertPattern('/integer/i', $dumper->describeValue(35)); 63 | $this->assertPattern('/35/', $dumper->describeValue(35)); 64 | } 65 | 66 | function testDescribeFloat() { 67 | $dumper = new SimpleDumper(); 68 | $this->assertPattern('/float/i', $dumper->describeValue(0.99)); 69 | $this->assertPattern('/0\.99/', $dumper->describeValue(0.99)); 70 | } 71 | 72 | function testDescribeArray() { 73 | $dumper = new SimpleDumper(); 74 | $this->assertPattern('/array/i', $dumper->describeValue(array(1, 4))); 75 | $this->assertPattern('/2/i', $dumper->describeValue(array(1, 4))); 76 | } 77 | 78 | function testDescribeObject() { 79 | $dumper = new SimpleDumper(); 80 | $this->assertPattern( 81 | '/object/i', 82 | $dumper->describeValue(new DumperDummy())); 83 | $this->assertPattern( 84 | '/DumperDummy/i', 85 | $dumper->describeValue(new DumperDummy())); 86 | } 87 | } 88 | ?> -------------------------------------------------------------------------------- /tests/simpletest/extensions/phpunit_test_case.php: -------------------------------------------------------------------------------- 1 | SimpleTestCase($label); 31 | } 32 | 33 | /** 34 | * Sends pass if the test condition resolves true, 35 | * a fail otherwise. 36 | * @param $condition Condition to test true. 37 | * @param $message Message to display. 38 | * @public 39 | */ 40 | function assert($condition, $message = false) { 41 | parent::assert(new TrueExpectation(), $condition, $message); 42 | } 43 | 44 | /** 45 | * Will test straight equality if set to loose 46 | * typing, or identity if not. 47 | * @param $first First value. 48 | * @param $second Comparison value. 49 | * @param $message Message to display. 50 | * @public 51 | */ 52 | function assertEquals($first, $second, $message = false) { 53 | parent::assert(new EqualExpectation($first), $second, $message); 54 | } 55 | 56 | /** 57 | * Simple string equality. 58 | * @param $first First value. 59 | * @param $second Comparison value. 60 | * @param $message Message to display. 61 | * @public 62 | */ 63 | function assertEqualsMultilineStrings($first, $second, $message = false) { 64 | parent::assert(new EqualExpectation($first), $second, $message); 65 | } 66 | 67 | /** 68 | * Tests a regex match. 69 | * @param $pattern Regex to match. 70 | * @param $subject String to search in. 71 | * @param $message Message to display. 72 | * @public 73 | */ 74 | function assertRegexp($pattern, $subject, $message = false) { 75 | parent::assert(new PatternExpectation($pattern), $subject, $message); 76 | } 77 | 78 | /** 79 | * Sends an error which we interpret as a fail 80 | * with a different message for compatibility. 81 | * @param $message Message to display. 82 | * @public 83 | */ 84 | function error($message) { 85 | parent::fail("Error triggered [$message]"); 86 | } 87 | 88 | /** 89 | * Accessor for name. 90 | * @public 91 | */ 92 | function name() { 93 | return $this->getLabel(); 94 | } 95 | } 96 | ?> 97 | -------------------------------------------------------------------------------- /tests/simpletest/test/compatibility_test.php: -------------------------------------------------------------------------------- 1 | = 0) { 13 | eval('interface ComparisonInterface { }'); 14 | eval('class ComparisonClassWithInterface implements ComparisonInterface { }'); 15 | } 16 | 17 | class TestOfCompatibility extends UnitTestCase { 18 | 19 | function testIsA() { 20 | $this->assertTrue(SimpleTestCompatibility::isA( 21 | new ComparisonClass(), 22 | 'ComparisonClass')); 23 | $this->assertFalse(SimpleTestCompatibility::isA( 24 | new ComparisonClass(), 25 | 'ComparisonSubclass')); 26 | $this->assertTrue(SimpleTestCompatibility::isA( 27 | new ComparisonSubclass(), 28 | 'ComparisonClass')); 29 | } 30 | 31 | function testIdentityOfNumericStrings() { 32 | $numericString1 = "123"; 33 | $numericString2 = "00123"; 34 | $this->assertNotIdentical($numericString1, $numericString2); 35 | } 36 | 37 | function testIdentityOfObjects() { 38 | $object1 = new ComparisonClass(); 39 | $object2 = new ComparisonClass(); 40 | $this->assertIdentical($object1, $object2); 41 | } 42 | 43 | function testReferences () { 44 | $thing = "Hello"; 45 | $thing_reference = &$thing; 46 | $thing_copy = $thing; 47 | $this->assertTrue(SimpleTestCompatibility::isReference( 48 | $thing, 49 | $thing)); 50 | $this->assertTrue(SimpleTestCompatibility::isReference( 51 | $thing, 52 | $thing_reference)); 53 | $this->assertFalse(SimpleTestCompatibility::isReference( 54 | $thing, 55 | $thing_copy)); 56 | } 57 | 58 | function testObjectReferences () { 59 | $object = &new ComparisonClass(); 60 | $object_reference = &$object; 61 | $object_copy = new ComparisonClass(); 62 | $object_assignment = $object; 63 | $this->assertTrue(SimpleTestCompatibility::isReference( 64 | $object, 65 | $object)); 66 | $this->assertTrue(SimpleTestCompatibility::isReference( 67 | $object, 68 | $object_reference)); 69 | $this->assertFalse(SimpleTestCompatibility::isReference( 70 | $object, 71 | $object_copy)); 72 | if (version_compare(phpversion(), '5', '>=')) { 73 | $this->assertTrue(SimpleTestCompatibility::isReference( 74 | $object, 75 | $object_assignment)); 76 | } else { 77 | $this->assertFalse(SimpleTestCompatibility::isReference( 78 | $object, 79 | $object_assignment)); 80 | } 81 | } 82 | 83 | function testInteraceComparison() { 84 | if (version_compare(phpversion(), '5', '<')) { 85 | return; 86 | } 87 | 88 | $object = new ComparisonClassWithInterface(); 89 | $this->assertFalse(SimpleTestCompatibility::isA( 90 | new ComparisonClass(), 91 | 'ComparisonInterface')); 92 | $this->assertTrue(SimpleTestCompatibility::isA( 93 | new ComparisonClassWithInterface(), 94 | 'ComparisonInterface')); 95 | } 96 | } 97 | ?> -------------------------------------------------------------------------------- /tests/simpletest/selector.php: -------------------------------------------------------------------------------- 1 | _name = $name; 31 | } 32 | 33 | function getName() { 34 | return $this->_name; 35 | } 36 | 37 | /** 38 | * Compares with name attribute of widget. 39 | * @param SimpleWidget $widget Control to compare. 40 | * @access public 41 | */ 42 | function isMatch($widget) { 43 | return ($widget->getName() == $this->_name); 44 | } 45 | } 46 | 47 | /** 48 | * Used to extract form elements for testing against. 49 | * Searches by visible label or alt text. 50 | * @package SimpleTest 51 | * @subpackage WebTester 52 | */ 53 | class SimpleByLabel { 54 | var $_label; 55 | 56 | /** 57 | * Stashes the name for later comparison. 58 | * @param string $label Visible text to match. 59 | */ 60 | function SimpleByLabel($label) { 61 | $this->_label = $label; 62 | } 63 | 64 | /** 65 | * Comparison. Compares visible text of widget or 66 | * related label. 67 | * @param SimpleWidget $widget Control to compare. 68 | * @access public 69 | */ 70 | function isMatch($widget) { 71 | if (! method_exists($widget, 'isLabel')) { 72 | return false; 73 | } 74 | return $widget->isLabel($this->_label); 75 | } 76 | } 77 | 78 | /** 79 | * Used to extract form elements for testing against. 80 | * Searches dy id attribute. 81 | * @package SimpleTest 82 | * @subpackage WebTester 83 | */ 84 | class SimpleById { 85 | var $_id; 86 | 87 | /** 88 | * Stashes the name for later comparison. 89 | * @param string $id ID atribute to match. 90 | */ 91 | function SimpleById($id) { 92 | $this->_id = $id; 93 | } 94 | 95 | /** 96 | * Comparison. Compares id attribute of widget. 97 | * @param SimpleWidget $widget Control to compare. 98 | * @access public 99 | */ 100 | function isMatch($widget) { 101 | return $widget->isId($this->_id); 102 | } 103 | } 104 | 105 | /** 106 | * Used to extract form elements for testing against. 107 | * Searches by visible label, name or alt text. 108 | * @package SimpleTest 109 | * @subpackage WebTester 110 | */ 111 | class SimpleByLabelOrName { 112 | var $_label; 113 | 114 | /** 115 | * Stashes the name/label for later comparison. 116 | * @param string $label Visible text to match. 117 | */ 118 | function SimpleByLabelOrName($label) { 119 | $this->_label = $label; 120 | } 121 | 122 | /** 123 | * Comparison. Compares visible text of widget or 124 | * related label or name. 125 | * @param SimpleWidget $widget Control to compare. 126 | * @access public 127 | */ 128 | function isMatch($widget) { 129 | if (method_exists($widget, 'isLabel')) { 130 | if ($widget->isLabel($this->_label)) { 131 | return true; 132 | } 133 | } 134 | return ($widget->getName() == $this->_label); 135 | } 136 | } 137 | ?> -------------------------------------------------------------------------------- /tests/simpletest/remote.php: -------------------------------------------------------------------------------- 1 | _url = $url; 35 | $this->_dry_url = $dry_url ? $dry_url : $url; 36 | $this->_size = false; 37 | } 38 | 39 | /** 40 | * Accessor for the test name for subclasses. 41 | * @return string Name of the test. 42 | * @access public 43 | */ 44 | function getLabel() { 45 | return $this->_url; 46 | } 47 | 48 | /** 49 | * Runs the top level test for this class. Currently 50 | * reads the data as a single chunk. I'll fix this 51 | * once I have added iteration to the browser. 52 | * @param SimpleReporter $reporter Target of test results. 53 | * @returns boolean True if no failures. 54 | * @access public 55 | */ 56 | function run(&$reporter) { 57 | $browser = &$this->_createBrowser(); 58 | $xml = $browser->get($this->_url); 59 | if (! $xml) { 60 | trigger_error('Cannot read remote test URL [' . $this->_url . ']'); 61 | return false; 62 | } 63 | $parser = &$this->_createParser($reporter); 64 | if (! $parser->parse($xml)) { 65 | trigger_error('Cannot parse incoming XML from [' . $this->_url . ']'); 66 | return false; 67 | } 68 | return true; 69 | } 70 | 71 | /** 72 | * Creates a new web browser object for fetching 73 | * the XML report. 74 | * @return SimpleBrowser New browser. 75 | * @access protected 76 | */ 77 | function &_createBrowser() { 78 | $browser = &new SimpleBrowser(); 79 | return $browser; 80 | } 81 | 82 | /** 83 | * Creates the XML parser. 84 | * @param SimpleReporter $reporter Target of test results. 85 | * @return SimpleTestXmlListener XML reader. 86 | * @access protected 87 | */ 88 | function &_createParser(&$reporter) { 89 | $parser = &new SimpleTestXmlParser($reporter); 90 | return $parser; 91 | } 92 | 93 | /** 94 | * Accessor for the number of subtests. 95 | * @return integer Number of test cases. 96 | * @access public 97 | */ 98 | function getSize() { 99 | if ($this->_size === false) { 100 | $browser = &$this->_createBrowser(); 101 | $xml = $browser->get($this->_dry_url); 102 | if (! $xml) { 103 | trigger_error('Cannot read remote test URL [' . $this->_dry_url . ']'); 104 | return false; 105 | } 106 | $reporter = &new SimpleReporter(); 107 | $parser = &$this->_createParser($reporter); 108 | if (! $parser->parse($xml)) { 109 | trigger_error('Cannot parse incoming XML from [' . $this->_dry_url . ']'); 110 | return false; 111 | } 112 | $this->_size = $reporter->getTestCaseCount(); 113 | } 114 | return $this->_size; 115 | } 116 | } 117 | ?> -------------------------------------------------------------------------------- /Crystal/Manipulation/Mysql/Fields.php: -------------------------------------------------------------------------------- 1 | $rows) 43 | { 44 | 45 | 46 | $this->fields .= Crystal_Helper_Mysql::add_apostrophe($column); 47 | 48 | $this->fields .= self::process_rows($rows, $column, $last_column); 49 | 50 | } 51 | 52 | if(isset($this->primary_key)) 53 | { 54 | $this->fields .= $this->primary_key; 55 | } 56 | break; 57 | 58 | 59 | case 'add_fields': 60 | 61 | $this->fields = "ADD"; 62 | 63 | foreach ($params as $column => $rows) 64 | { 65 | 66 | 67 | $this->fields .= Crystal_Helper_Mysql::add_apostrophe($column); 68 | 69 | $this->fields .= self::process_rows($rows, $column, $last_column); 70 | 71 | } 72 | break; 73 | 74 | case 'remove_fields': 75 | 76 | $this->fields = ''; 77 | 78 | foreach($params as $key => $value) 79 | { 80 | $this->fields .= "DROP" . Crystal_Helper_Mysql::add_apostrophe($value); 81 | 82 | 83 | if($key != $last_column) 84 | { 85 | $this->fields .= ","; 86 | } 87 | 88 | } 89 | 90 | break; 91 | 92 | 93 | default: 94 | break; 95 | 96 | } 97 | 98 | } 99 | 100 | 101 | function process_rows($rows, $column, $last_column) 102 | { 103 | $this->row = ''; 104 | 105 | 106 | if(array_key_exists('type', $rows)) 107 | { 108 | $this->row .= strtoupper($rows['type']) . " "; 109 | } 110 | 111 | 112 | if(array_key_exists('constraint', $rows)) 113 | { 114 | $this->row .= "(" . $rows['constraint'] . ")"; 115 | } 116 | 117 | 118 | if(array_key_exists('choises', $rows)) 119 | { 120 | 121 | 122 | 123 | $last_field = end($rows['choises']); 124 | 125 | $this->row .= " ( "; 126 | 127 | foreach($rows['choises'] as $key => $value) 128 | { 129 | 130 | $this->row .= Crystal_Helper_Mysql::add_single_quote($value); 131 | 132 | if($value != $last_field){$this->row .= ","; } 133 | 134 | } 135 | 136 | $this->row .= ")"; 137 | 138 | } 139 | 140 | 141 | if(array_key_exists('null', $rows)) 142 | { 143 | $this->row .= " NULL"; 144 | } 145 | else 146 | { 147 | $this->row .= " NOT NULL "; 148 | } 149 | 150 | 151 | if(array_key_exists('auto_increment', $rows)) 152 | { 153 | $this->row .= " AUTO_INCREMENT "; 154 | 155 | } 156 | 157 | 158 | 159 | 160 | if(array_key_exists('default', $rows)) 161 | { 162 | $this->row .= " DEFAULT " . Crystal_Helper_Mysql::add_single_quote($rows['default']); 163 | 164 | } 165 | 166 | 167 | 168 | 169 | 170 | if(array_key_exists('primary_key', $rows)) 171 | { 172 | $this->primary_key = ", PRIMARY KEY ( " . Crystal_Helper_Mysql::add_apostrophe($column) . ")"; 173 | 174 | } 175 | 176 | if($column != $last_column) 177 | { 178 | $this->row .= ","; 179 | } 180 | 181 | 182 | return $this->row; 183 | 184 | } 185 | 186 | 187 | public function __toString() 188 | { 189 | return $this->fields; 190 | } 191 | 192 | 193 | } -------------------------------------------------------------------------------- /Crystal/Query/Where.php: -------------------------------------------------------------------------------- 1 | query->type = 'where'; 29 | 30 | /** WORKS WITH STRING PARAMETER 31 | * where('client_status : active') 32 | ***/ 33 | if($first_element == '0') 34 | { 35 | if(isset($params[1])) 36 | { 37 | // DISABLE SQL ESCAPING 38 | if($params[1] == false) 39 | { 40 | $this->query->sql = "WHERE ?"; 41 | $this->query->params = $params[0]; 42 | 43 | } 44 | else 45 | { 46 | 47 | /** THE NEW UNIFIED SYNTAX COMES HERE 48 | * 49 | * where('product_id : ?, client_id : ?',1,2) 50 | @params 0 is the query, 1 and beyond are the params 51 | */ 52 | $parsed_columns = Crystal_Parser_String::parse($params[0]); 53 | 54 | $this->query->sql = "WHERE ? = ? "; 55 | 56 | 57 | /** ALTERNATIVE WHERE SYNTAX where('product_id, 1); 58 | * 59 | */ 60 | if(isset($parsed_columns['colon']) && $parsed_columns['colon'] == False) 61 | { 62 | $this->query->params = $params; 63 | } 64 | else 65 | { 66 | 67 | $sliced_params = array_slice($params, 1); 68 | 69 | 70 | 71 | 72 | // REPEAT AND 73 | $total_params = count($sliced_params)-1 ; // substract the WHERE part 74 | 75 | /* only one parameter */ 76 | if($total_params == 0) 77 | { 78 | $this->query->params = array($parsed_columns['column'], $params[1]); 79 | } 80 | else 81 | { 82 | 83 | $this->query->sql .= str_repeat("AND ? = ?", $total_params); 84 | 85 | 86 | foreach($parsed_columns as $key => $value) 87 | { 88 | 89 | $this->query->params[] = array($value['column'], $sliced_params[$key]); 90 | } 91 | 92 | } 93 | 94 | 95 | } 96 | 97 | } 98 | 99 | } 100 | 101 | 102 | } 103 | break; 104 | 105 | 106 | case 'or': 107 | if($first_element == '0') 108 | { 109 | $this->query->sql = "OR ? "; 110 | $this->query->params = array($params); 111 | 112 | } 113 | else 114 | { 115 | 116 | foreach($params as $key => $value) 117 | { 118 | 119 | $this->query->sql = "OR ? "; 120 | $this->query->params = array($key, $value); 121 | 122 | } 123 | 124 | } 125 | break; 126 | 127 | 128 | 129 | 130 | 131 | 132 | case 'in': 133 | $this->where .= " IN ("; 134 | 135 | foreach($params as $key => $value) 136 | { 137 | if($value != $last_element) 138 | { 139 | $this->where .= Crystal_Helper_Mysql::add_apostrophe($value) .","; 140 | } 141 | else 142 | { 143 | $this->where .= Crystal_Helper_Mysql::add_apostrophe($value); 144 | } 145 | 146 | } 147 | $this->where .= ")"; 148 | break; 149 | 150 | 151 | 152 | 153 | 154 | case 'like': 155 | $this->where .= " LIKE "; 156 | $this->where .= Crystal_Helper_Mysql::add_single_quote("%" . $params[0] . "%") ; 157 | break; 158 | 159 | 160 | 161 | 162 | 163 | default: 164 | throw new Crystal_Query_Exception("Invalid method: " . $method); 165 | break; 166 | } 167 | 168 | 169 | return $this->query; 170 | 171 | } 172 | 173 | 174 | } -------------------------------------------------------------------------------- /tests/simpletest/extensions/testdox/test.php: -------------------------------------------------------------------------------- 1 | assertIsA($dox, 'SimpleScorer'); 14 | $this->assertIsA($dox, 'SimpleReporter'); 15 | } 16 | 17 | function testOutputsNameOfTestCase() { 18 | $dox = new TestDoxReporter(); 19 | ob_start(); 20 | $dox->paintCaseStart('TestOfTestDoxReporter'); 21 | $buffer = ob_get_clean(); 22 | $this->assertWantedPattern('/^TestDoxReporter/', $buffer); 23 | } 24 | 25 | function testOutputOfTestCaseNameFilteredByConstructParameter() { 26 | $dox = new TestDoxReporter('/^(.*)Test$/'); 27 | ob_start(); 28 | $dox->paintCaseStart('SomeGreatWidgetTest'); 29 | $buffer = ob_get_clean(); 30 | $this->assertWantedPattern('/^SomeGreatWidget/', $buffer); 31 | } 32 | 33 | function testIfTest_case_patternIsEmptyAssumeEverythingMatches() { 34 | $dox = new TestDoxReporter(''); 35 | ob_start(); 36 | $dox->paintCaseStart('TestOfTestDoxReporter'); 37 | $buffer = ob_get_clean(); 38 | $this->assertWantedPattern('/^TestOfTestDoxReporter/', $buffer); 39 | } 40 | 41 | function testEmptyLineInsertedWhenCaseEnds() { 42 | $dox = new TestDoxReporter(); 43 | ob_start(); 44 | $dox->paintCaseEnd('TestOfTestDoxReporter'); 45 | $buffer = ob_get_clean(); 46 | $this->assertEqual("\n", $buffer); 47 | } 48 | 49 | function testPaintsTestMethodInTestDoxFormat() { 50 | $dox = new TestDoxReporter(); 51 | ob_start(); 52 | $dox->paintMethodStart('testSomeGreatTestCase'); 53 | $buffer = ob_get_clean(); 54 | $this->assertEqual("- some great test case", $buffer); 55 | unset($buffer); 56 | 57 | $random = rand(100, 200); 58 | ob_start(); 59 | $dox->paintMethodStart("testRandomNumberIs{$random}"); 60 | $buffer = ob_get_clean(); 61 | $this->assertEqual("- random number is {$random}", $buffer); 62 | } 63 | 64 | function testDoesNotOutputAnythingOnNoneTestMethods() { 65 | $dox = new TestDoxReporter(); 66 | ob_start(); 67 | $dox->paintMethodStart('nonMatchingMethod'); 68 | $buffer = ob_get_clean(); 69 | $this->assertEqual('', $buffer); 70 | } 71 | 72 | function testPaintMethodAddLineBreak() { 73 | $dox = new TestDoxReporter(); 74 | ob_start(); 75 | $dox->paintMethodEnd('someMethod'); 76 | $buffer = ob_get_clean(); 77 | $this->assertEqual("\n", $buffer); 78 | $this->assertNoErrors(); 79 | } 80 | 81 | function testProperlySpacesSingleLettersInMethodName() { 82 | $dox = new TestDoxReporter(); 83 | ob_start(); 84 | $dox->paintMethodStart('testAVerySimpleAgainAVerySimpleMethod'); 85 | $buffer = ob_get_clean(); 86 | $this->assertEqual('- a very simple again a very simple method', $buffer); 87 | } 88 | 89 | function testOnFailureThisPrintsFailureNotice() { 90 | $dox = new TestDoxReporter(); 91 | ob_start(); 92 | $dox->paintFail(); 93 | $buffer = ob_get_clean(); 94 | $this->assertEqual(' [FAILED]', $buffer); 95 | } 96 | 97 | function testWhenMatchingMethodNamesTestPrefixIsCaseInsensitive() { 98 | $dox = new TestDoxReporter(); 99 | ob_start(); 100 | $dox->paintMethodStart('TESTSupportsAllUppercaseTestPrefixEvenThoughIDoNotKnowWhyYouWouldDoThat'); 101 | $buffer = ob_get_clean(); 102 | $this->assertEqual( 103 | '- supports all uppercase test prefix even though i do not know why you would do that', 104 | $buffer 105 | ); 106 | } 107 | } 108 | 109 | -------------------------------------------------------------------------------- /tests/simpletest/reflection_php4.php: -------------------------------------------------------------------------------- 1 | _interface = $interface; 25 | } 26 | 27 | /** 28 | * Checks that a class has been declared. 29 | * @return boolean True if defined. 30 | * @access public 31 | */ 32 | function classExists() { 33 | return class_exists($this->_interface); 34 | } 35 | 36 | /** 37 | * Needed to kill the autoload feature in PHP5 38 | * for classes created dynamically. 39 | * @return boolean True if defined. 40 | * @access public 41 | */ 42 | function classExistsSansAutoload() { 43 | return class_exists($this->_interface); 44 | } 45 | 46 | /** 47 | * Checks that a class or interface has been 48 | * declared. 49 | * @return boolean True if defined. 50 | * @access public 51 | */ 52 | function classOrInterfaceExists() { 53 | return class_exists($this->_interface); 54 | } 55 | 56 | /** 57 | * Needed to kill the autoload feature in PHP5 58 | * for classes created dynamically. 59 | * @return boolean True if defined. 60 | * @access public 61 | */ 62 | function classOrInterfaceExistsSansAutoload() { 63 | return class_exists($this->_interface); 64 | } 65 | 66 | /** 67 | * Gets the list of methods on a class or 68 | * interface. 69 | * @returns array List of method names. 70 | * @access public 71 | */ 72 | function getMethods() { 73 | return get_class_methods($this->_interface); 74 | } 75 | 76 | /** 77 | * Gets the list of interfaces from a class. If the 78 | * class name is actually an interface then just that 79 | * interface is returned. 80 | * @returns array List of interfaces. 81 | * @access public 82 | */ 83 | function getInterfaces() { 84 | return array(); 85 | } 86 | 87 | /** 88 | * Finds the parent class name. 89 | * @returns string Parent class name. 90 | * @access public 91 | */ 92 | function getParent() { 93 | return strtolower(get_parent_class($this->_interface)); 94 | } 95 | 96 | /** 97 | * Determines if the class is abstract, which for PHP 4 98 | * will never be the case. 99 | * @returns boolean True if abstract. 100 | * @access public 101 | */ 102 | function isAbstract() { 103 | return false; 104 | } 105 | 106 | /** 107 | * Determines if the the entity is an interface, which for PHP 4 108 | * will never be the case. 109 | * @returns boolean True if interface. 110 | * @access public 111 | */ 112 | function isInterface() { 113 | return false; 114 | } 115 | 116 | /** 117 | * Scans for final methods, but as it's PHP 4 there 118 | * aren't any. 119 | * @returns boolean True if the class has a final method. 120 | * @access public 121 | */ 122 | function hasFinal() { 123 | return false; 124 | } 125 | 126 | /** 127 | * Gets the source code matching the declaration 128 | * of a method. 129 | * @param string $method Method name. 130 | * @access public 131 | */ 132 | function getSignature($method) { 133 | return "function &$method()"; 134 | } 135 | } 136 | ?> -------------------------------------------------------------------------------- /Crystal/Helper/Mysql.php: -------------------------------------------------------------------------------- 1 | conn = $db_connection; 22 | 23 | } 24 | 25 | static public function add_apostrophe($string) 26 | { 27 | 28 | if(is_string($string)) 29 | { 30 | return " `".self::escape_string($string)."` "; 31 | } 32 | elseif(is_numeric($string) or $string == False) 33 | { 34 | 35 | return $string; 36 | 37 | } 38 | else 39 | { 40 | throw new Crystal_Helper_Exception("Helper accepts only strings for add_apostrophe function"); 41 | } 42 | 43 | 44 | } 45 | 46 | 47 | 48 | /** ACCEPTS ONLY STRING **/ 49 | static public function sanitize_string($string) 50 | { 51 | 52 | if(is_string($string)) 53 | { 54 | 55 | return self::escape_string($string); 56 | } 57 | elseif(is_numeric($string) or $string == False) 58 | { 59 | 60 | return $string; 61 | 62 | } 63 | else 64 | { 65 | throw new Crystal_Helper_Exception("Helper accepts only strings for add_apostrophe function"); 66 | } 67 | 68 | 69 | } 70 | 71 | 72 | static public function add_single_quote($string) 73 | { 74 | 75 | if(is_string($string)) 76 | { 77 | return " '" . self::escape_string($string) . "' "; 78 | } 79 | elseif(is_numeric($string) or $string == False) 80 | { 81 | 82 | return $string; 83 | 84 | } 85 | else 86 | { 87 | throw new Crystal_Helper_Exception("Helper accepts only strings for add_single_quote function"); 88 | } 89 | 90 | } 91 | 92 | 93 | 94 | 95 | static public function add_double_quote($string) 96 | { 97 | if(is_string($string)) 98 | { 99 | return '"' . self::escape_string($string) . '"'; 100 | } 101 | elseif(is_numeric($string) or $string == False) 102 | { 103 | 104 | return $string; 105 | 106 | } 107 | else 108 | { 109 | throw new Crystal_Helper_Exception("Helper accepts only strings for add_double_quote function"); 110 | } 111 | 112 | } 113 | 114 | static public function escape_update_values($cols) 115 | { 116 | 117 | 118 | foreach($cols as $key => $value) 119 | { 120 | 121 | $updated_cols[] = self::add_apostrophe($key) . "= " . self::add_single_quote($value) . " "; 122 | 123 | } 124 | 125 | $temp = implode(',', $updated_cols); 126 | 127 | 128 | return $temp; 129 | 130 | } 131 | 132 | 133 | static public function escape_update_values_safe($cols) 134 | { 135 | 136 | foreach($cols as $key => $value) 137 | { 138 | 139 | $updated_cols[] = self::add_apostrophe($key) . "=" . self::add_single_quoute($value); 140 | 141 | 142 | } 143 | 144 | $temp = implode(',', $updated_cols); 145 | 146 | 147 | return $temp; 148 | 149 | } 150 | 151 | static public function clean_db_result($rows) 152 | { 153 | 154 | if(isset($rows) && !empty($rows)) 155 | { 156 | 157 | foreach($rows as $key => $column) 158 | { 159 | 160 | if(!is_numeric($column)) 161 | { 162 | 163 | $rows[$key] = stripslashes($column); 164 | 165 | } 166 | 167 | } 168 | 169 | return $rows; 170 | 171 | 172 | } 173 | 174 | 175 | } 176 | 177 | 178 | static public function escape_string($string) 179 | { 180 | 181 | if (function_exists('mysql_real_escape_string')) 182 | { 183 | $string = mysql_real_escape_string($string); 184 | } 185 | elseif (function_exists('mysql_escape_string')) 186 | { 187 | 188 | $string = mysql_escape_string($string); 189 | } 190 | else 191 | { 192 | $string = addslashes($string); 193 | } 194 | 195 | return $string; 196 | 197 | 198 | 199 | } 200 | 201 | 202 | 203 | } -------------------------------------------------------------------------------- /Crystal/Manipulation/Postgres/Fields.php: -------------------------------------------------------------------------------- 1 | $rows) 42 | { 43 | 44 | 45 | $this->fields .= Crystal_Helper_Postgres::add_double_quote($column) ." "; 46 | 47 | $this->fields .= self::process_rows($rows, $column, $last_column, $table); 48 | 49 | } 50 | 51 | if(isset($this->primary_key)) 52 | { 53 | $this->fields .= $this->primary_key; 54 | } 55 | break; 56 | 57 | 58 | 59 | case 'add_fields': 60 | 61 | $this->fields = "ADD"; 62 | 63 | foreach ($params as $column => $rows) 64 | { 65 | 66 | 67 | $this->fields .= Crystal_Helper_Postgres::add_single_quote($column); 68 | 69 | $this->fields .= self::process_rows($rows, $column, $last_column); 70 | 71 | } 72 | break; 73 | 74 | case 'remove_fields': 75 | 76 | $this->fields = ''; 77 | 78 | foreach($params as $key => $value) 79 | { 80 | $this->fields .= "DROP" . Crystal_Helper_Postgres::add_single_quote($value); 81 | 82 | 83 | if($key != $last_column) 84 | { 85 | $this->fields .= ","; 86 | } 87 | 88 | } 89 | 90 | break; 91 | 92 | 93 | default: 94 | break; 95 | 96 | } 97 | 98 | } 99 | 100 | 101 | function process_rows($rows, $column, $last_column, $table) 102 | { 103 | $this->row = ''; 104 | 105 | 106 | if(array_key_exists('type', $rows)) 107 | { 108 | 109 | if($rows['type'] == 'key') 110 | { 111 | $this->row .= "serial"; 112 | } 113 | else 114 | { 115 | $this->row .= strtoupper($rows['type']) . " "; 116 | } 117 | 118 | } 119 | 120 | 121 | if(array_key_exists('constraint', $rows)) 122 | { 123 | $this->row .= "(" . $rows['constraint'] . ")"; 124 | } 125 | 126 | 127 | if(array_key_exists('choises', $rows)) 128 | { 129 | 130 | 131 | 132 | $last_field = end($rows['choises']); 133 | 134 | $this->row .= " ( "; 135 | 136 | foreach($rows['choises'] as $key => $value) 137 | { 138 | 139 | $this->row .= Crystal_Helper_Postgres::add_single_quote($value); 140 | 141 | if($value != $last_field){$this->row .= ","; } 142 | 143 | } 144 | 145 | $this->row .= ")"; 146 | 147 | } 148 | 149 | 150 | if(array_key_exists('null', $rows)) 151 | { 152 | $this->row .= " NULL"; 153 | } 154 | else 155 | { 156 | $this->row .= " NOT NULL "; 157 | } 158 | 159 | 160 | if(array_key_exists('auto_increment', $rows)) 161 | { 162 | $this->row .= " AUTO_INCREMENT "; 163 | 164 | } 165 | 166 | 167 | 168 | 169 | if(array_key_exists('default', $rows)) 170 | { 171 | $this->row .= " DEFAULT " . Crystal_Helper_Postgres::add_single_quote($rows['default']); 172 | 173 | } 174 | 175 | 176 | 177 | if(array_key_exists('primary_key', $rows)) 178 | { 179 | $this->primary_key = ", CONSTRAINT " . $table[0] . "_pkey PRIMARY KEY (" . $column . ")" ; 180 | 181 | } 182 | 183 | if($column != $last_column) 184 | { 185 | $this->row .= ","; 186 | } 187 | 188 | 189 | return $this->row; 190 | 191 | } 192 | 193 | 194 | public function __toString() 195 | { 196 | return $this->fields; 197 | } 198 | 199 | 200 | } -------------------------------------------------------------------------------- /tests/simpletest/invoker.php: -------------------------------------------------------------------------------- 1 | _test_case = &$test_case; 39 | } 40 | 41 | /** 42 | * Accessor for test case being run. 43 | * @return SimpleTestCase Test case. 44 | * @access public 45 | */ 46 | function &getTestCase() { 47 | return $this->_test_case; 48 | } 49 | 50 | /** 51 | * Runs test level set up. Used for changing 52 | * the mechanics of base test cases. 53 | * @param string $method Test method to call. 54 | * @access public 55 | */ 56 | function before($method) { 57 | $this->_test_case->before($method); 58 | } 59 | 60 | /** 61 | * Invokes a test method and buffered with setUp() 62 | * and tearDown() calls. 63 | * @param string $method Test method to call. 64 | * @access public 65 | */ 66 | function invoke($method) { 67 | $this->_test_case->setUp(); 68 | $this->_test_case->$method(); 69 | $this->_test_case->tearDown(); 70 | } 71 | 72 | /** 73 | * Runs test level clean up. Used for changing 74 | * the mechanics of base test cases. 75 | * @param string $method Test method to call. 76 | * @access public 77 | */ 78 | function after($method) { 79 | $this->_test_case->after($method); 80 | } 81 | } 82 | 83 | /** 84 | * Do nothing decorator. Just passes the invocation 85 | * straight through. 86 | * @package SimpleTest 87 | * @subpackage UnitTester 88 | */ 89 | class SimpleInvokerDecorator { 90 | var $_invoker; 91 | 92 | /** 93 | * Stores the invoker to wrap. 94 | * @param SimpleInvoker $invoker Test method runner. 95 | */ 96 | function SimpleInvokerDecorator(&$invoker) { 97 | $this->_invoker = &$invoker; 98 | } 99 | 100 | /** 101 | * Accessor for test case being run. 102 | * @return SimpleTestCase Test case. 103 | * @access public 104 | */ 105 | function &getTestCase() { 106 | return $this->_invoker->getTestCase(); 107 | } 108 | 109 | /** 110 | * Runs test level set up. Used for changing 111 | * the mechanics of base test cases. 112 | * @param string $method Test method to call. 113 | * @access public 114 | */ 115 | function before($method) { 116 | $this->_invoker->before($method); 117 | } 118 | 119 | /** 120 | * Invokes a test method and buffered with setUp() 121 | * and tearDown() calls. 122 | * @param string $method Test method to call. 123 | * @access public 124 | */ 125 | function invoke($method) { 126 | $this->_invoker->invoke($method); 127 | } 128 | 129 | /** 130 | * Runs test level clean up. Used for changing 131 | * the mechanics of base test cases. 132 | * @param string $method Test method to call. 133 | * @access public 134 | */ 135 | function after($method) { 136 | $this->_invoker->after($method); 137 | } 138 | } 139 | ?> -------------------------------------------------------------------------------- /tests/simpletest/collector.php: -------------------------------------------------------------------------------- 1 | 7 | * @package SimpleTest 8 | * @subpackage UnitTester 9 | * @version $Id: collector.php 1723 2008-04-08 00:34:10Z lastcraft $ 10 | */ 11 | 12 | /** 13 | * The basic collector for {@link GroupTest} 14 | * 15 | * @see collect(), GroupTest::collect() 16 | * @package SimpleTest 17 | * @subpackage UnitTester 18 | */ 19 | class SimpleCollector { 20 | 21 | /** 22 | * Strips off any kind of slash at the end so as to normalise the path. 23 | * @param string $path Path to normalise. 24 | * @return string Path without trailing slash. 25 | */ 26 | function _removeTrailingSlash($path) { 27 | if (substr($path, -1) == DIRECTORY_SEPARATOR) { 28 | return substr($path, 0, -1); 29 | } elseif (substr($path, -1) == '/') { 30 | return substr($path, 0, -1); 31 | } else { 32 | return $path; 33 | } 34 | } 35 | 36 | /** 37 | * Scans the directory and adds what it can. 38 | * @param object $test Group test with {@link GroupTest::addTestFile()} method. 39 | * @param string $path Directory to scan. 40 | * @see _attemptToAdd() 41 | */ 42 | function collect(&$test, $path) { 43 | $path = $this->_removeTrailingSlash($path); 44 | if ($handle = opendir($path)) { 45 | while (($entry = readdir($handle)) !== false) { 46 | if ($this->_isHidden($entry)) { 47 | continue; 48 | } 49 | $this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry); 50 | } 51 | closedir($handle); 52 | } 53 | } 54 | 55 | /** 56 | * This method determines what should be done with a given file and adds 57 | * it via {@link GroupTest::addTestFile()} if necessary. 58 | * 59 | * This method should be overriden to provide custom matching criteria, 60 | * such as pattern matching, recursive matching, etc. For an example, see 61 | * {@link SimplePatternCollector::_handle()}. 62 | * 63 | * @param object $test Group test with {@link GroupTest::addTestFile()} method. 64 | * @param string $filename A filename as generated by {@link collect()} 65 | * @see collect() 66 | * @access protected 67 | */ 68 | function _handle(&$test, $file) { 69 | if (is_dir($file)) { 70 | return; 71 | } 72 | $test->addTestFile($file); 73 | } 74 | 75 | /** 76 | * Tests for hidden files so as to skip them. Currently 77 | * only tests for Unix hidden files. 78 | * @param string $filename Plain filename. 79 | * @return boolean True if hidden file. 80 | * @access private 81 | */ 82 | function _isHidden($filename) { 83 | return strncmp($filename, '.', 1) == 0; 84 | } 85 | } 86 | 87 | /** 88 | * An extension to {@link SimpleCollector} that only adds files matching a 89 | * given pattern. 90 | * 91 | * @package SimpleTest 92 | * @subpackage UnitTester 93 | * @see SimpleCollector 94 | */ 95 | class SimplePatternCollector extends SimpleCollector { 96 | var $_pattern; 97 | 98 | /** 99 | * 100 | * @param string $pattern Perl compatible regex to test name against 101 | * See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE} 102 | * for full documentation of valid pattern.s 103 | */ 104 | function SimplePatternCollector($pattern = '/php$/i') { 105 | $this->_pattern = $pattern; 106 | } 107 | 108 | /** 109 | * Attempts to add files that match a given pattern. 110 | * 111 | * @see SimpleCollector::_handle() 112 | * @param object $test Group test with {@link GroupTest::addTestFile()} method. 113 | * @param string $path Directory to scan. 114 | * @access protected 115 | */ 116 | function _handle(&$test, $filename) { 117 | if (preg_match($this->_pattern, $filename)) { 118 | parent::_handle($test, $filename); 119 | } 120 | } 121 | } 122 | ?> -------------------------------------------------------------------------------- /Crystal/Manipulation/Mysql/Builder.php: -------------------------------------------------------------------------------- 1 | active_connection = $active_connection; 27 | $this->conn = new Crystal_Connection_Manager($this->active_connection); 28 | $this->helper = new Crystal_Helper_Mysql($this->conn); 29 | 30 | } 31 | 32 | 33 | /** USED FOR GENERATING QUERY **/ 34 | function __call($name, $arguments) 35 | { 36 | 37 | /** TODO - Rewrite it, not the most elegant solution **/ 38 | $constant = "Crystal_Manipulation_Mysql_"; 39 | 40 | 41 | /** METHOD MAPPER **/ 42 | $exceptions = array( 43 | 'create_database' => 'create', 44 | 'create_table' => 'create', 45 | 'drop_database' => 'drop', 46 | 'drop_table' => 'drop', 47 | 'alter_table' => 'alter', 48 | 'add_fields' => 'fields', 49 | 'remove_fields' => 'fields', 50 | 'rename_table' => 'rename' 51 | ); 52 | 53 | 54 | /** NEEDED FOR METHODS THAT MUST REPLACE %s in PREVIOUS METHODS **/ 55 | $replacement_exceptions = array('with_fields' => 'fields'); 56 | 57 | $default_method = $constant . ucfirst($name); 58 | 59 | 60 | 61 | /** CHECKS FOR ARRAY **/ 62 | if(is_array($arguments[0])) 63 | { 64 | $filtered_arguments = $arguments[0]; 65 | } 66 | else 67 | { 68 | 69 | $filtered_arguments = $arguments; 70 | } 71 | 72 | 73 | 74 | if(array_key_exists($name, $exceptions)) 75 | { 76 | 77 | $rescue_method = $constant . ucfirst($exceptions[$name]); 78 | 79 | $this->sql .= new $rescue_method($name, $filtered_arguments); 80 | 81 | 82 | } 83 | elseif(array_key_exists($name, $replacement_exceptions)) 84 | { 85 | 86 | $rescue_method = $constant . ucfirst($replacement_exceptions[$name]); 87 | 88 | $this->replacement .= new $rescue_method($name, $filtered_arguments); 89 | 90 | 91 | 92 | } 93 | elseif(class_exists($default_method)) 94 | { 95 | 96 | $this->sql .= new $default_method($name, $filtered_arguments); 97 | 98 | } 99 | else 100 | { 101 | 102 | throw new Crystal_Methods_Mysql_Exception('Invalid or not existing method' . $name); 103 | 104 | } 105 | 106 | 107 | /** TIME FOR STRING REPLACEMENT **/ 108 | if(isset($this->replacement)) 109 | { 110 | $this->sql = preg_replace('/%s/', $this->replacement, $this->sql); 111 | unset($this->replacement); 112 | } 113 | 114 | 115 | 116 | 117 | /** CRUCIAL FOR METHOD CHAIN **/ 118 | 119 | return $this; 120 | 121 | 122 | } 123 | 124 | public function in_database($database) 125 | { 126 | 127 | $this->database = array('database' => $database); 128 | 129 | return $this; 130 | 131 | } 132 | 133 | 134 | public function execute() 135 | { 136 | 137 | /** IN DATABASE Exception **/ 138 | if(isset($this->database)) 139 | { 140 | 141 | $this->conn = new Crystal_Connection_Manager($this->active_connection, $this->database); 142 | 143 | } 144 | 145 | $this->query = mysql_query($this->sql); 146 | 147 | 148 | 149 | if (!$this->query) 150 | { 151 | throw new Crystal_Exception("Mysql Error:" . mysql_error()); 152 | return; 153 | } 154 | else 155 | { 156 | $this->sql = NULL; 157 | return $this->query; 158 | } 159 | 160 | 161 | } 162 | 163 | 164 | 165 | function print_sql() 166 | { 167 | 168 | if($this->sql == FALSE) 169 | { 170 | 171 | throw new Crystal_Methods_Mysql_Exception("No valid sql to print"); 172 | } 173 | else 174 | { 175 | $this->print_query = print_r('
'. $this->sql); 176 | 177 | return $this->print_query; 178 | } 179 | 180 | } 181 | 182 | } --------------------------------------------------------------------------------