浏览代码

more tests

euromark 11 年之前
父节点
当前提交
065be73ac8
共有 5 个文件被更改,包括 152 次插入8 次删除
  1. 5 1
      README.md
  2. 76 0
      docs/README.md
  3. 16 0
      src/Model/Table/Table.php
  4. 33 7
      tests/TestCase/Model/Table/TableTest.php
  5. 22 0
      tests/bootstrap.php

+ 5 - 1
README.md

@@ -21,11 +21,15 @@ Dev (currently), Alpha, Beta, RC, 1.0 stable (incl. tagged release then).
 - Disable cache also works for older IE versions.
 - Disable cache also works for older IE versions.
 - With flashMessage() you can have colorful (success, warning, error, ...) flash messages.
 - With flashMessage() you can have colorful (success, warning, error, ...) flash messages.
   They also can stack up (multiple messages per type) which the core currently doesn't support.
   They also can stack up (multiple messages per type) which the core currently doesn't support.
+- Provide enum support as "static enums"
+- Default settings for Paginator, ... can be set using Configure.
+- Provided a less error-prone inArray() method when using Utility class.
 
 
 ### Additional features
 ### Additional features
 - The Passwordable behavior allows easy to use password functionality for frontend and backend.
 - The Passwordable behavior allows easy to use password functionality for frontend and backend.
 - Tree helper for working with (complex) trees and their output.
 - Tree helper for working with (complex) trees and their output.
 - RSS and Ajax Views for better responses (Ajax also comes with an optional component).
 - RSS and Ajax Views for better responses (Ajax also comes with an optional component).
+- Slugged and Reset behavior
 - The Text, Time, Number libs and helpers etc provide extended functionality if desired.
 - The Text, Time, Number libs and helpers etc provide extended functionality if desired.
 - GoogleMapV3, Timeline, Typography, etc provide additional helper functionality.
 - GoogleMapV3, Timeline, Typography, etc provide additional helper functionality.
 - Email as a wrapper for core's Email adding some more usefulness and making debugging/testing easier.
 - Email as a wrapper for core's Email adding some more usefulness and making debugging/testing easier.
@@ -34,7 +38,7 @@ Dev (currently), Alpha, Beta, RC, 1.0 stable (incl. tagged release then).
 This plugin for the Cake 3 version also contains some 2.x shims to ease migration of existing applications from 2.x to 3.x:
 This plugin for the Cake 3 version also contains some 2.x shims to ease migration of existing applications from 2.x to 3.x:
 - find('first') and find('count')
 - find('first') and find('count')
 - Model::$validate, Model::$primaryKey, Model::$displayField and Model relations as properties
 - Model::$validate, Model::$primaryKey, Model::$displayField and Model relations as properties
-
+- Set/Multibyte class, Session component and a cut down version of JsHelper
 
 
 ## How to include
 ## How to include
 Installing the Plugin is pretty much as with every other CakePHP Plugin.
 Installing the Plugin is pretty much as with every other CakePHP Plugin.

+ 76 - 0
docs/README.md

@@ -0,0 +1,76 @@
+# CakePHP Tools Plugin Documentation
+
+## Version notice
+
+This cake3 branch only works for **CakePHP3.x** - please use the master branch for CakePHP 2.x!
+**It is still dev** (not even alpha), please be careful with using it.
+
+## Basic enhancements of the core
+
+### Model
+Extend the Tools plugin table and entity class to benefit from a few gotchas:
+```php
+<?php
+namespace App\Model\Table;
+
+use Tools\Model\Table\Table;
+
+class UsersTable extends Table {}
+```
+and
+```php
+<?php
+namespace App\Model\Entity;
+
+use Tools\Model\Entity\Entity;
+
+class User extends Entity {}
+```
+You can also make yourself your own AppTable and AppEntity class in your application and then
+extend those for each of the individual files - which I recommend for most flexibility.
+
+### Controller
+```php
+<?php
+namespace App\Controller;
+
+use Tools\Controller\Controller;
+
+class AppController extends Controller {
+
+	public $components = array('Tools.Common', 'Tools.Flash');
+
+	public $helpers = array('Tools.Common', 'Tools.Flash', 'Tools.Time', 'Tools.Number', 'Tools.Format');
+
+}
+```
+Here we can also see some of the most useful components and helpers included right away.
+
+The Common component for example will automatically provide:
+- Auto-trim on POST (to make - not only notEmpty - validation working properly).
+
+With the Flash component and it's message() method you can have colorful (success, warning, error, ...) flash messages.
+They also can stack up (multiple messages per type) which the core currently still doesn't support.
+
+The Tools plugin controller will allow you to:
+- Disable cache also works for older IE versions.
+
+
+
+
+### BC shims for easier migration from 2.x
+The session component of the core is deprecated and will throw a warning as it will soon be removed.
+Better use the plugin one right away. It is a 1:1 clone of it.
+```php
+namespace App\Controller;
+
+use Tools\Controller\Controller;
+
+class AppController extends Controller {
+
+	public $components = array('Tools.Session');
+
+}
+```
+
+

+ 16 - 0
src/Model/Table/Table.php

@@ -296,6 +296,22 @@ class Table extends CakeTable {
 	}
 	}
 
 
 	/**
 	/**
+	 * Return the next auto increment id from the current table
+	 * UUIDs will return false
+	 *
+	 * @return int|bool next auto increment value or False on failure
+	 */
+	public function getNextAutoIncrement() {
+		$query = "SHOW TABLE STATUS WHERE name = '" . $this->table() . "'";
+		$statement = $this->_connection->execute($query);
+		$result = $statement->fetch();
+		if (!isset($result[10])) {
+			return false;
+		}
+		return (int)$result[10];
+	}
+
+	/**
 	 * truncate()
 	 * truncate()
 	 *
 	 *
 	 * @return void
 	 * @return void

+ 33 - 7
tests/TestCase/Model/Table/TableTest.php

@@ -15,6 +15,7 @@ use Cake\Routing\Router;
 use Cake\Network\Request;
 use Cake\Network\Request;
 use Cake\Auth\PasswordHasherFactory;
 use Cake\Auth\PasswordHasherFactory;
 use Cake\I18n\Time;
 use Cake\I18n\Time;
+use Cake\Datasource\ConnectionManager;
 
 
 class TableTest extends TestCase {
 class TableTest extends TestCase {
 
 
@@ -48,6 +49,31 @@ class TableTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
+	 * Test truncate
+	 *
+	 * @return void
+	 */
+	public function testTruncate() {
+		$is = $this->Users->find('count');
+		$this->assertEquals(4, $is);
+
+		$config = ConnectionManager::config('test');
+		if ((strpos($config['driver'], 'Mysql') !== false)) {
+			$is = $this->Users->getNextAutoIncrement();
+			$this->assertEquals(5, $is);
+		}
+
+		$is = $this->Users->truncate();
+		$is = $this->Users->find('count');
+		$this->assertEquals(0, $is);
+
+		if ((strpos($config['driver'], 'Mysql') !== false)) {
+			$is = $this->Users->getNextAutoIncrement();
+			$this->assertEquals(1, $is);
+		}
+	}
+
+	/**
 	 * Check shims
 	 * Check shims
 	 *
 	 *
 	 * @return void
 	 * @return void
@@ -82,7 +108,7 @@ class TableTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * MyModelTest::testGetRelatedInUse()
+	 * TableTest::testGetRelatedInUse()
 	 *
 	 *
 	 * @return void
 	 * @return void
 	 */
 	 */
@@ -95,7 +121,7 @@ class TableTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * MyModelTest::testGetFieldInUse()
+	 * TableTest::testGetFieldInUse()
 	 *
 	 *
 	 * @return void
 	 * @return void
 	 */
 	 */
@@ -110,7 +136,7 @@ class TableTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * MyModelTest::testValidateDate()
+	 * TableTest::testValidateDate()
 	 *
 	 *
 	 * @return void
 	 * @return void
 	 */
 	 */
@@ -196,7 +222,7 @@ class TableTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * MyModelTest::testValidateDatetime()
+	 * TableTest::testValidateDatetime()
 	 *
 	 *
 	 * @return void
 	 * @return void
 	 */
 	 */
@@ -277,7 +303,7 @@ class TableTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * MyModelTest::testValidateTime()
+	 * TableTest::testValidateTime()
 	 *
 	 *
 	 * @return void
 	 * @return void
 	 */
 	 */
@@ -307,7 +333,7 @@ class TableTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * MyModelTest::testValidateUrl()
+	 * TableTest::testValidateUrl()
 	 *
 	 *
 	 * @return void
 	 * @return void
 	 */
 	 */
@@ -371,7 +397,7 @@ class TableTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * MyModelTest::testValidateUnique()
+	 * TableTest::testValidateUnique()
 	 *
 	 *
 	 * @return void
 	 * @return void
 	 */
 	 */

+ 22 - 0
tests/bootstrap.php

@@ -1,5 +1,13 @@
 <?php
 <?php
 define('DS', DIRECTORY_SEPARATOR);
 define('DS', DIRECTORY_SEPARATOR);
+if (!defined('WINDOWS')) {
+	if (DS == '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
+		define('WINDOWS', true);
+	} else {
+		define('WINDOWS', false);
+	}
+}
+
 define('ROOT', dirname(__DIR__));
 define('ROOT', dirname(__DIR__));
 define('TMP', ROOT . DS . 'tmp' . DS);
 define('TMP', ROOT . DS . 'tmp' . DS);
 define('LOGS', TMP . 'logs' . DS);
 define('LOGS', TMP . 'logs' . DS);
@@ -75,6 +83,20 @@ if (!getenv('db_class')) {
 	putenv('db_dsn=sqlite::memory:');
 	putenv('db_dsn=sqlite::memory:');
 }
 }
 
 
+if (WINDOWS) {
+	Cake\Datasource\ConnectionManager::config('test', [
+		'className' => 'Cake\Database\Connection',
+		'driver' => 'Cake\Database\Driver\Mysql',
+		'database' => 'cake_test',
+		'username' => 'root',
+		'password' => '',
+		'timezone' => 'UTC',
+		'quoteIdentifiers' => true,
+		'cacheMetadata' => true,
+	]);
+	return;
+}
+
 Cake\Datasource\ConnectionManager::config('test', [
 Cake\Datasource\ConnectionManager::config('test', [
 	'className' => 'Cake\Database\Connection',
 	'className' => 'Cake\Database\Connection',
 	'driver' => getenv('db_class'),
 	'driver' => getenv('db_class'),