|
|
@@ -1,231 +0,0 @@
|
|
|
-<?php
|
|
|
-/**
|
|
|
- * ObjectTest file
|
|
|
- *
|
|
|
- * PHP 5
|
|
|
- *
|
|
|
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
|
|
- * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
- *
|
|
|
- * Licensed under The MIT License
|
|
|
- * Redistributions of files must retain the above copyright notice
|
|
|
- *
|
|
|
- * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
- * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
|
|
- * @since 1.2.0
|
|
|
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
- */
|
|
|
-namespace Cake\Test\TestCase\Core;
|
|
|
-
|
|
|
-use Cake\Core\App;
|
|
|
-use Cake\Core\Configure;
|
|
|
-use Cake\Core\Object;
|
|
|
-use Cake\Core\Plugin;
|
|
|
-use Cake\Log\Log;
|
|
|
-use Cake\Routing\Router;
|
|
|
-use Cake\TestSuite\TestCase;
|
|
|
-
|
|
|
-/**
|
|
|
- * TestObject class
|
|
|
- *
|
|
|
- */
|
|
|
-class TestObject extends Object {
|
|
|
-
|
|
|
-/**
|
|
|
- * firstName property
|
|
|
- *
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public $firstName = 'Joel';
|
|
|
-
|
|
|
-/**
|
|
|
- * lastName property
|
|
|
- *
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public $lastName = 'Moss';
|
|
|
-
|
|
|
-/**
|
|
|
- * methodCalls property
|
|
|
- *
|
|
|
- * @var array
|
|
|
- */
|
|
|
- public $methodCalls = array();
|
|
|
-
|
|
|
-/**
|
|
|
- * emptyMethod method
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function emptyMethod() {
|
|
|
- $this->methodCalls[] = 'emptyMethod';
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * oneParamMethod method
|
|
|
- *
|
|
|
- * @param mixed $param
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function oneParamMethod($param) {
|
|
|
- $this->methodCalls[] = array('oneParamMethod' => array($param));
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * twoParamMethod method
|
|
|
- *
|
|
|
- * @param mixed $param
|
|
|
- * @param mixed $paramTwo
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function twoParamMethod($param, $paramTwo) {
|
|
|
- $this->methodCalls[] = array('twoParamMethod' => array($param, $paramTwo));
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * threeParamMethod method
|
|
|
- *
|
|
|
- * @param mixed $param
|
|
|
- * @param mixed $paramTwo
|
|
|
- * @param mixed $paramThree
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function threeParamMethod($param, $paramTwo, $paramThree) {
|
|
|
- $this->methodCalls[] = array('threeParamMethod' => array($param, $paramTwo, $paramThree));
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * fourParamMethod method
|
|
|
- *
|
|
|
- * @param mixed $param
|
|
|
- * @param mixed $paramTwo
|
|
|
- * @param mixed $paramThree
|
|
|
- * @param mixed $paramFour
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function fourParamMethod($param, $paramTwo, $paramThree, $paramFour) {
|
|
|
- $this->methodCalls[] = array('fourParamMethod' => array($param, $paramTwo, $paramThree, $paramFour));
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * fiveParamMethod method
|
|
|
- *
|
|
|
- * @param mixed $param
|
|
|
- * @param mixed $paramTwo
|
|
|
- * @param mixed $paramThree
|
|
|
- * @param mixed $paramFour
|
|
|
- * @param mixed $paramFive
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function fiveParamMethod($param, $paramTwo, $paramThree, $paramFour, $paramFive) {
|
|
|
- $this->methodCalls[] = array('fiveParamMethod' => array($param, $paramTwo, $paramThree, $paramFour, $paramFive));
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * crazyMethod method
|
|
|
- *
|
|
|
- * @param mixed $param
|
|
|
- * @param mixed $paramTwo
|
|
|
- * @param mixed $paramThree
|
|
|
- * @param mixed $paramFour
|
|
|
- * @param mixed $paramFive
|
|
|
- * @param mixed $paramSix
|
|
|
- * @param mixed $paramSeven
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function crazyMethod($param, $paramTwo, $paramThree, $paramFour, $paramFive, $paramSix, $paramSeven = null) {
|
|
|
- $this->methodCalls[] = array('crazyMethod' => array($param, $paramTwo, $paramThree, $paramFour, $paramFive, $paramSix, $paramSeven));
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * methodWithOptionalParam method
|
|
|
- *
|
|
|
- * @param mixed $param
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function methodWithOptionalParam($param = null) {
|
|
|
- $this->methodCalls[] = array('methodWithOptionalParam' => array($param));
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Object Test class
|
|
|
- *
|
|
|
- */
|
|
|
-class ObjectTest extends TestCase {
|
|
|
-
|
|
|
-/**
|
|
|
- * fixtures
|
|
|
- *
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public $fixtures = array('core.post', 'core.test_plugin_comment', 'core.comment');
|
|
|
-
|
|
|
-/**
|
|
|
- * setUp method
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function setUp() {
|
|
|
- parent::setUp();
|
|
|
- $this->object = new TestObject();
|
|
|
- Configure::write('App.namespace', 'TestApp');
|
|
|
- Configure::write('Security.salt', 'not-the-default');
|
|
|
- Log::drop('stdout');
|
|
|
- Log::drop('stderr');
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * tearDown method
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function tearDown() {
|
|
|
- parent::tearDown();
|
|
|
- Plugin::unload();
|
|
|
- Log::reset();
|
|
|
- unset($this->object);
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * testLog method
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testLog() {
|
|
|
- if (file_exists(LOGS . 'error.log')) {
|
|
|
- unlink(LOGS . 'error.log');
|
|
|
- }
|
|
|
- $this->assertTrue($this->object->log('Test warning 1'));
|
|
|
- $this->assertTrue($this->object->log(array('Test' => 'warning 2')));
|
|
|
- $result = file(LOGS . 'error.log');
|
|
|
- $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Test warning 1$/', $result[0]);
|
|
|
- $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Array$/', $result[1]);
|
|
|
- $this->assertRegExp('/^\($/', $result[2]);
|
|
|
- $this->assertRegExp('/\[Test\] => warning 2$/', $result[3]);
|
|
|
- $this->assertRegExp('/^\)$/', $result[4]);
|
|
|
- unlink(LOGS . 'error.log');
|
|
|
-
|
|
|
- $this->assertTrue($this->object->log('Test warning 1', LOG_WARNING));
|
|
|
- $this->assertTrue($this->object->log(array('Test' => 'warning 2'), LOG_WARNING));
|
|
|
- $result = file(LOGS . 'error.log');
|
|
|
- $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1$/', $result[0]);
|
|
|
- $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Array$/', $result[1]);
|
|
|
- $this->assertRegExp('/^\($/', $result[2]);
|
|
|
- $this->assertRegExp('/\[Test\] => warning 2$/', $result[3]);
|
|
|
- $this->assertRegExp('/^\)$/', $result[4]);
|
|
|
- unlink(LOGS . 'error.log');
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * testToString method
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testToString() {
|
|
|
- $result = strtolower($this->object->toString());
|
|
|
- $this->assertEquals(strtolower(__NAMESPACE__) . '\testobject', $result);
|
|
|
- }
|
|
|
-
|
|
|
-}
|