Esempio n. 1
0
	function cached($url) {
		if (Configure::read('Cache.check') === true) {
			$path = $this->here;
			if ($this->here == '/') {
				$path = 'home';
			}
			if($this->Session->check('Auth.User._id')){
				//$path = $_SESSION['Auth']['User']['_id'].'_'.strtolower(Inflector::slug($path));
				$path = '4d33940fda220a9606000003_'.strtolower(Inflector::slug($path));
			}else{
				$path = strtolower(Inflector::slug($path));
			}

			$filename = CACHE . 'views' . DS . $path . '.php';

			if (!file_exists($filename)) {
				$filename = CACHE . 'views' . DS . $path . '_index.php';
			}

			if (file_exists($filename)) {
				if (!class_exists('View')) {
					App::import('View', 'View', false);
				}
				$controller = null;
				$view =& new View($controller);
				$return = $view->renderCache($filename, getMicrotime());
				if (!$return) {
					ClassRegistry::removeObject('view');
				}
				return $return;
			}
		}
		return false;
	}
 /**
  * [ADMIN] サイトマップXML生成実行ページ
  */
 public function admin_index()
 {
     $path = WWW_ROOT . Configure::read('Sitemapxml.filename');
     if ($this->request->data) {
         $sitemap = $this->requestAction('/admin/sitemapxml/sitemapxml/create', array('return', $this->request->data));
         ClassRegistry::removeObject('View');
         $File = new File($path);
         $File->write($sitemap);
         $File->close();
         $this->setMessage('サイトマップの生成が完了しました。');
         chmod($path, 0666);
     }
     $dirWritable = true;
     $fileWritable = true;
     if (file_exists($path)) {
         if (!is_writable($path)) {
             $fileWritable = false;
         }
     } else {
         if (!is_writable(dirname($path))) {
             $dirWritable = false;
         }
     }
     $this->set('path', $path);
     $this->set('fileWritable', $fileWritable);
     $this->set('dirWritable', $dirWritable);
     $this->pageTitle = 'サイトマップXML作成';
     $this->render('index');
 }
Esempio n. 3
0
 public function startTest($method)
 {
     parent::startTest($method);
     $this->loadFixtures('Roster', 'Payment', 'PaymentOption', 'Involvement', 'PaymentType', 'Role', 'RolesRoster', 'RosterStatus');
     $CreditCard = new MockRosterCreditCard();
     $CreditCard->setReturnValue('save', true);
     ClassRegistry::removeObject('CreditCard');
     ClassRegistry::addObject('CreditCard', $CreditCard);
     $this->Roster =& ClassRegistry::init('Roster');
 }
Esempio n. 4
0
 /**
  * startTest
  *
  * @return void
  * @access public
  */
 public function startTest()
 {
     ClassRegistry::flush();
     Router::reload();
     $null = null;
     $this->View = new View($null);
     ClassRegistry::removeObject('view');
     ClassRegistry::addObject('view', $this->View);
     $this->TinyMce = new TinyMceHelper();
     $this->TinyMce->Html = new HtmlHelper();
 }
Esempio n. 5
0
 public function startTest($method)
 {
     parent::startTest($method);
     $this->loadFixtures('Attachment');
     $this->SysEmail =& ClassRegistry::init('SysEmail');
     $this->Document =& ClassRegistry::init('Document');
     // detach behaviors so they get deleted properly (since the files don't really exist)
     $this->Document->Behaviors->detach('Media.Transfer');
     $this->Document->Behaviors->detach('Media.Polymorphic');
     $this->Document->Behaviors->detach('Media.Coupler');
     ClassRegistry::removeObject('Document');
     ClassRegistry::addObject('Document', $this->Document);
 }
Esempio n. 6
0
 /**
  * Start test callback
  * 
  * @return void
  */
 public function startTest($method)
 {
     parent::startTest($method);
     $this->Http = new MockHttpSocket();
     ClassRegistry::removeObject('http_socket');
     if ($this->__useTestSocket) {
         ClassRegistry::addObject('http_socket', $this->Http);
     }
     if ($this->__useTestSocket) {
         Configure::write('Bitly', array('login' => 'testLogin', 'apiKey' => 'testApiKey'));
     }
     $this->Model = ClassRegistry::init('ModelTest');
     $this->BitlyApi = $this->Model->Behaviors->BitlyApi;
 }
Esempio n. 7
0
 /**
  * Initialize the fixture.
  *
  * @param object	Cake's DBO driver (e.g: DboMysql).
  * @access public
  *
  */
 function init()
 {
     if (isset($this->import) && (is_string($this->import) || is_array($this->import))) {
         $import = array();
         if (is_string($this->import) || is_array($this->import) && isset($this->import['model'])) {
             $import = array_merge(array('records' => false), is_array($this->import) ? $this->import : array());
             $import['model'] = is_array($this->import) ? $this->import['model'] : $this->import;
         } elseif (isset($this->import['table'])) {
             $import = array_merge(array('connection' => 'default', 'records' => false), $this->import);
         }
         if (isset($import['model']) && (class_exists($import['model']) || App::import('Model', $import['model']))) {
             $connection = isset($import['connection']) ? $import['connection'] : 'default';
             ClassRegistry::config(array('ds' => $connection));
             $model =& ClassRegistry::init($import['model']);
             $db =& ConnectionManager::getDataSource($model->useDbConfig);
             $db->cacheSources = false;
             $this->fields = $model->schema(true);
             $this->fields[$model->primaryKey]['key'] = 'primary';
             ClassRegistry::config(array('ds' => 'test_suite'));
             ClassRegistry::removeObject($model->alias);
         } elseif (isset($import['table'])) {
             $model =& new Model(null, $import['table'], $import['connection']);
             $db =& ConnectionManager::getDataSource($import['connection']);
             $db->cacheSources = false;
             $model->useDbConfig = $import['connection'];
             $model->name = Inflector::camelize(Inflector::singularize($import['table']));
             $model->table = $import['table'];
             $model->tablePrefix = $db->config['prefix'];
             $this->fields = $model->schema(true);
         }
         if (isset($import['records']) && $import['records'] !== false && isset($model) && isset($db)) {
             $this->records = array();
             $query = array('fields' => array_keys($this->fields), 'table' => $db->fullTableName($model->table), 'alias' => $model->alias, 'conditions' => array(), 'order' => null, 'limit' => null, 'group' => null);
             foreach ($query['fields'] as $index => $field) {
                 $query['fields'][$index] = $db->name($query['alias']) . '.' . $db->name($field);
             }
             $records = $db->fetchAll($db->buildStatement($query, $model), false, $model->alias);
             if ($records !== false && !empty($records)) {
                 $this->records = Set::extract($records, '{n}.' . $model->alias);
             }
         }
     }
     if (!isset($this->table)) {
         $this->table = Inflector::underscore(Inflector::pluralize($this->name));
     }
     if (!isset($this->primaryKey) && isset($this->fields['id'])) {
         $this->primaryKey = 'id';
     }
 }
Esempio n. 8
0
 public function dispatch($event, $data = array())
 {
     $return = array();
     // Set shell reference
     ClassRegistry::addObject('EventShell', $this->Dispatcher);
     $result = $this->CakeEvents->dispatchEvent($event, am($data, array('Dispatcher' => $this->Dispatcher)));
     ClassRegistry::removeObject('EventShell');
     if ($result) {
         foreach ($result as $eventResult) {
             if ($eventResult['returns']) {
                 $return[$eventResult['name']] = $eventResult['returns'];
             }
         }
     }
     return $return;
 }
Esempio n. 9
0
 /**
  * Wrapper method to Events::dispatchEvent
  *
  * @param string $event Name of the event
  * @param array $data Any data to attach
  * 
  * @return mixed FALSE -or- assoc result array
  */
 public function dispatch($event, $data = array())
 {
     $return = array();
     // Set controller reference
     ClassRegistry::addObject('EventController', $this->Controller);
     // Do whatever it does
     $result = $this->CakeEvents->dispatchEvent($event, am($data, array('Controller' => $this->Controller)));
     // Unset controller reference
     ClassRegistry::removeObject('EventController');
     if ($result) {
         foreach ($result as $eventResult) {
             if ($eventResult['returns']) {
                 $return[$eventResult['name']] = $eventResult['returns'];
             }
         }
     }
     return $return;
 }
Esempio n. 10
0
 public function startTest($method)
 {
     parent::startTest($method);
     $this->Payments =& new TestPaymentsController();
     $this->Payments->__construct();
     $this->Payments->constructClasses();
     $this->Payments->Notifier->QueueEmail = new MockPaymentsQueueEmailComponent();
     $this->Payments->Notifier->QueueEmail->enabled = true;
     $this->Payments->Notifier->QueueEmail->initialize($this->Payments);
     $this->Payments->Notifier->QueueEmail->setReturnValue('_smtp', true);
     $this->Payments->Notifier->QueueEmail->setReturnValue('_mail', true);
     $CreditCard = new CreditCard();
     $CreditCard->setGateway(new TestPaymentsControllerAuthorizeDotNetComponent());
     ClassRegistry::removeObject('CreditCard');
     ClassRegistry::addObject('CreditCard', $CreditCard);
     ClassRegistry::init('CreditCard');
     // necessary fixtures
     $this->loadFixtures('Payment', 'User', 'Roster', 'PaymentType', 'PaymentOption', 'Involvement', 'InvolvementType', 'Profile', 'Address', 'Leader');
     $this->testController = $this->Payments;
 }
 public function _render($content, $title)
 {
     $this->initMessage();
     $viewClass = $this->_controller->view;
     if ($viewClass != 'View') {
         list($plugin, $viewClass) = pluginSplit($viewClass);
         $viewClass = 'View';
         App::import('View', $this->_controller->view);
     }
     $View = new $viewClass($this->Controller);
     $View->layout = $this->layout;
     if ($this->sendAs === 'both') {
         $htmlContent = $content;
         $content = $View->element('email' . DS . 'text' . DS . $this->template, array('content' => $content), true);
         $View->layoutPath = 'email' . DS . 'text';
         $content = explode("\n", $this->textMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
         $htmlContent = $View->element('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent), true);
         $View->layoutPath = 'email' . DS . 'html';
         $htmlContent = explode("\n", $this->htmlMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($htmlContent)));
         // Set message body (both html and plain text)
         // $this->message->setBody(implode("\n", $htmlContent), 'text/html')
         // ->addPart(implode("\n", $content), 'text/plain');
         ClassRegistry::removeObject('view');
         return $htmlContent;
     }
     //  $content = $View->element('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
     $View->layoutPath = 'email' . DS . $this->sendAs;
     $content = explode("\n", $rendered = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
     if ($this->sendAs === 'html') {
         $this->htmlMessage = $rendered;
     } else {
         $this->textMessage = $rendered;
     }
     // Set message body
     // $this->message->setBody($rendered, $this->getContentType($this->sendAs));
     ClassRegistry::removeObject('view');
     return $content;
 }
Esempio n. 12
0
 public function startTest($method)
 {
     parent::startTest($method);
     $this->loadFixtures('Roster', 'User', 'Involvement', 'Group', 'Date', 'Payment', 'Notification', 'PaymentOption', 'PaymentType', 'InvolvementType', 'Role', 'RolesRoster', 'Leader', 'Ministry');
     $this->Rosters =& new MockRostersController();
     $this->Rosters->__construct();
     $this->Rosters->constructClasses();
     $this->Rosters->Notifier->QueueEmail = new MockRostersQueueEmailComponent();
     $this->Rosters->Notifier->QueueEmail->enabled = true;
     $this->Rosters->Notifier->QueueEmail->initialize($this->Rosters);
     $this->Rosters->Notifier->QueueEmail->setReturnValue('_smtp', true);
     $this->Rosters->Notifier->QueueEmail->setReturnValue('_mail', true);
     $CreditCard =& new MockRostersCreditCard();
     $CreditCard->something = 'nothing';
     $CreditCard->setReturnValue('save', true);
     $CreditCard->setReturnValue('saveAll', true);
     ClassRegistry::removeObject('CreditCard');
     ClassRegistry::addObject('CreditCard', $CreditCard);
     ClassRegistry::init('CreditCard');
     $this->loadSettings();
     $this->Rosters->setReturnValue('isAuthorized', true);
     $this->testController = $this->Rosters;
 }
Esempio n. 13
0
 /**
  * Render the form
  *
  * @param string $formData Data used to build form
  *
  * @return string The rendered form
  * @access private
  */
 function __renderForm($formData)
 {
     $content = '';
     $viewClass = $this->Controller->view;
     if ($viewClass != 'View') {
         if (strpos($viewClass, '.') !== false) {
             list($plugin, $viewClass) = explode('.', $viewClass);
         }
         $viewClass = $viewClass . 'View';
         App::import('View', $this->Controller->view);
     }
     $View = new $viewClass($this->Controller);
     $View->plugin = 'cforms';
     $content = $View->element('form', array('formData' => $formData), true);
     ClassRegistry::removeObject('view');
     return $content;
 }
Esempio n. 14
0
 /**
  * test script tag output buffering when using scriptStart() and scriptEnd();
  *
  * @return void
  */
 function testScriptStartAndScriptEnd()
 {
     $result = $this->Html->scriptStart(array('safe' => true));
     $this->assertNull($result);
     echo 'this is some javascript';
     $result = $this->Html->scriptEnd();
     $expected = array('script' => array('type' => 'text/javascript'), $this->cDataStart, 'this is some javascript', $this->cDataEnd, '/script');
     $this->assertTags($result, $expected);
     $result = $this->Html->scriptStart(array('safe' => false));
     $this->assertNull($result);
     echo 'this is some javascript';
     $result = $this->Html->scriptEnd();
     $expected = array('script' => array('type' => 'text/javascript'), 'this is some javascript', '/script');
     $this->assertTags($result, $expected);
     ClassRegistry::removeObject('view');
     $View =& new HtmlHelperMockView();
     $View->expectOnce('addScript');
     ClassRegistry::addObject('view', $View);
     $result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
     $this->assertNull($result);
     echo 'this is some javascript';
     $result = $this->Html->scriptEnd();
     $this->assertNull($result);
 }
Esempio n. 15
0
 /**
  * Generates a mocked controller and mocks any classes passed to `$mocks`. By
  * default, `_stop()` is stubbed as is sending the response headers, so to not
  * interfere with testing.
  *
  * ### Mocks:
  *
  * - `methods` Methods to mock on the controller. `_stop()` is mocked by default
  * - `models` Models to mock. Models are added to the ClassRegistry so they any
  *   time they are instantiated the mock will be created. Pass as key value pairs
  *   with the value being specific methods on the model to mock. If `true` or
  *   no value is passed, the entire model will be mocked.
  * - `components` Components to mock. Components are only mocked on this controller
  *   and not within each other (i.e., components on components)
  *
  * @param string $controller Controller name
  * @param array $mocks List of classes and methods to mock
  * @return Controller Mocked controller
  * @throws MissingControllerException When controllers could not be created.
  * @throws MissingComponentException When components could not be created.
  */
 public function generate($controller, $mocks = array())
 {
     list($plugin, $controller) = pluginSplit($controller);
     if ($plugin) {
         App::uses($plugin . 'AppController', $plugin . '.Controller');
         $plugin .= '.';
     }
     App::uses($controller . 'Controller', $plugin . 'Controller');
     if (!class_exists($controller . 'Controller')) {
         throw new MissingControllerException(array('class' => $controller . 'Controller', 'plugin' => substr($plugin, 0, -1)));
     }
     ClassRegistry::flush();
     $mocks = array_merge_recursive(array('methods' => array('_stop'), 'models' => array(), 'components' => array()), (array) $mocks);
     list($plugin, $name) = pluginSplit($controller);
     $_controller = $this->getMock($name . 'Controller', $mocks['methods'], array(), '', false);
     $_controller->name = $name;
     $request = $this->getMock('CakeRequest');
     $response = $this->getMock('CakeResponse', array('_sendHeader'));
     $_controller->__construct($request, $response);
     $config = ClassRegistry::config('Model');
     foreach ($mocks['models'] as $model => $methods) {
         if (is_string($methods)) {
             $model = $methods;
             $methods = true;
         }
         if ($methods === true) {
             $methods = array();
         }
         ClassRegistry::init($model);
         list($plugin, $name) = pluginSplit($model);
         $config = array_merge((array) $config, array('name' => $model));
         $_model = $this->getMock($name, $methods, array($config));
         ClassRegistry::removeObject($name);
         ClassRegistry::addObject($name, $_model);
     }
     foreach ($mocks['components'] as $component => $methods) {
         if (is_string($methods)) {
             $component = $methods;
             $methods = true;
         }
         if ($methods === true) {
             $methods = array();
         }
         list($plugin, $name) = pluginSplit($component, true);
         $componentClass = $name . 'Component';
         App::uses($componentClass, $plugin . 'Controller/Component');
         if (!class_exists($componentClass)) {
             throw new MissingComponentException(array('class' => $componentClass));
         }
         $_component = $this->getMock($componentClass, $methods, array(), '', false);
         $_controller->Components->set($name, $_component);
     }
     $_controller->constructClasses();
     $this->__dirtyController = false;
     $this->controller = $_controller;
     return $this->controller;
 }
Esempio n. 16
0
 /**
  * test File upload input on a model not used in create();
  *
  * @return void
  */
 function testFileUploadOnOtherModel()
 {
     ClassRegistry::removeObject('view');
     $controller =& new Controller();
     $controller->name = 'ValidateUsers';
     $controller->uses = array('ValidateUser');
     $controller->constructClasses();
     $view =& new View($controller, true);
     $this->Form->create('ValidateUser', array('type' => 'file'));
     $result = $this->Form->file('ValidateProfile.city');
     $expected = array('input' => array('type' => 'file', 'name' => 'data[ValidateProfile][city]', 'id' => 'ValidateProfileCity'));
     $this->assertTags($result, $expected);
 }
Esempio n. 17
0
 /**
  * Outputs cached dispatch view cache
  *
  * @param string $url Requested URL
  * @access public
  */
 function cached($url)
 {
     if (Configure::read('Cache.check') === true) {
         $path = $this->here;
         if ($this->here == '/') {
             $path = 'home';
         }
         $path = strtolower(Inflector::slug($path));
         $filename = CACHE . 'views' . DS . $path . '.php';
         if (!file_exists($filename)) {
             $filename = CACHE . 'views' . DS . $path . '_index.php';
         }
         if (file_exists($filename)) {
             if (!class_exists('View')) {
                 App::import('View', 'View', false);
             }
             $controller = null;
             $view =& new View($controller);
             $return = $view->renderCache($filename, getMicrotime());
             if (!$return) {
                 ClassRegistry::removeObject('view');
             }
             return $return;
         }
     }
     return false;
 }
Esempio n. 18
0
 /**
  * Mock a model, maintain fixtures and table association
  *
  * @param string $model
  * @param mixed $methods
  * @param array $config
  * @throws MissingModelException
  * @return Model
  */
 public function getMockForModel($model, $methods = array(), $config = array())
 {
     $config += ClassRegistry::config('Model');
     list($plugin, $name) = pluginSplit($model, true);
     App::uses($name, $plugin . 'Model');
     $config = array_merge((array) $config, array('name' => $name));
     if (!class_exists($name)) {
         throw new MissingModelException(array($model));
     }
     $mock = $this->getMock($name, $methods, array($config));
     ClassRegistry::removeObject($name);
     ClassRegistry::addObject($name, $mock);
     return $mock;
 }
Esempio n. 19
0
 /**
  * Render the contents using the current layout and template.
  *
  * @param string $content Content to render
  * @return array Email ready to be sent
  * @access private
  */
 function _render($content)
 {
     $viewClass = $this->Controller->view;
     if ($viewClass != 'View') {
         list($plugin, $viewClass) = pluginSplit($viewClass);
         $viewClass = $viewClass . 'View';
         App::import('View', $this->Controller->view);
     }
     $View = new $viewClass($this->Controller);
     $View->layout = $this->layout;
     $msg = array();
     $content = implode("\n", $content);
     if ($this->sendAs === 'both') {
         $htmlContent = $content;
         if (!empty($this->attachments)) {
             $msg[] = '--' . $this->__boundary;
             $msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
             $msg[] = '';
         }
         $msg[] = '--alt-' . $this->__boundary;
         $msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
         $msg[] = 'Content-Transfer-Encoding: 7bit';
         $msg[] = '';
         $content = $View->element('email' . DS . 'text' . DS . $this->template, array('content' => $content), true);
         $View->layoutPath = 'email' . DS . 'text';
         $content = explode("\n", $this->textMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
         $msg = array_merge($msg, $content);
         $msg[] = '';
         $msg[] = '--alt-' . $this->__boundary;
         $msg[] = 'Content-Type: text/html; charset=' . $this->charset;
         $msg[] = 'Content-Transfer-Encoding: 7bit';
         $msg[] = '';
         $htmlContent = $View->element('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent), true);
         $View->layoutPath = 'email' . DS . 'html';
         $htmlContent = explode("\n", $this->htmlMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($htmlContent)));
         $msg = array_merge($msg, $htmlContent);
         $msg[] = '';
         $msg[] = '--alt-' . $this->__boundary . '--';
         $msg[] = '';
         ClassRegistry::removeObject('view');
         return $msg;
     }
     if (!empty($this->attachments)) {
         if ($this->sendAs === 'html') {
             $msg[] = '';
             $msg[] = '--' . $this->__boundary;
             $msg[] = 'Content-Type: text/html; charset=' . $this->charset;
             $msg[] = 'Content-Transfer-Encoding: 7bit';
             $msg[] = '';
         } else {
             $msg[] = '--' . $this->__boundary;
             $msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
             $msg[] = 'Content-Transfer-Encoding: 7bit';
             $msg[] = '';
         }
     }
     $content = $View->element('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
     $View->layoutPath = 'email' . DS . $this->sendAs;
     $content = explode("\n", $rendered = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
     if ($this->sendAs === 'html') {
         $this->htmlMessage = $rendered;
     } else {
         $this->textMessage = $rendered;
     }
     $msg = array_merge($msg, $content);
     ClassRegistry::removeObject('view');
     return $msg;
 }
Esempio n. 20
0
 /**
  * testFieldDoubleEscaping method
  *
  * @access public
  * @return void
  */
 function testFieldDoubleEscaping()
 {
     $config = array_merge($this->__config, array('driver' => 'test'));
     $test =& ConnectionManager::create('quoteTest', $config);
     $test->simulated = array();
     $this->Model =& new Article2(array('alias' => 'Article', 'ds' => 'quoteTest'));
     $this->Model->setDataSource('quoteTest');
     $this->assertEqual($this->Model->escapeField(), '`Article`.`id`');
     $result = $test->fields($this->Model, null, $this->Model->escapeField());
     $this->assertEqual($result, array('`Article`.`id`'));
     $result = $test->read($this->Model, array('fields' => $this->Model->escapeField(), 'conditions' => null, 'recursive' => -1));
     $this->assertEqual(trim($test->simulated[0]), 'SELECT `Article`.`id` FROM `' . $this->testDb->fullTableName('article', false) . '` AS `Article`   WHERE 1 = 1');
     $test->startQuote = '[';
     $test->endQuote = ']';
     $this->assertEqual($this->Model->escapeField(), '[Article].[id]');
     $result = $test->fields($this->Model, null, $this->Model->escapeField());
     $this->assertEqual($result, array('[Article].[id]'));
     $result = $test->read($this->Model, array('fields' => $this->Model->escapeField(), 'conditions' => null, 'recursive' => -1));
     $this->assertEqual(trim($test->simulated[1]), 'SELECT [Article].[id] FROM [' . $this->testDb->fullTableName('article', false) . '] AS [Article]   WHERE 1 = 1');
     ClassRegistry::removeObject('Article');
 }
 /**
  * testConcurrentInsert
  *
  * @return void
  */
 public function testConcurrentInsert()
 {
     $this->skipIf($this->db instanceof Sqlite, 'Sqlite does not throw exceptions when attempting to insert a duplicate primary key');
     ClassRegistry::removeObject('Session');
     $mockedModel = $this->getMockForModel('SessionTestModel', array('exists'), array('alias' => 'MockedSessionTestModel', 'table' => 'sessions'));
     Configure::write('Session.handler.model', 'MockedSessionTestModel');
     $counter = 0;
     // First save
     $mockedModel->expects($this->at($counter++))->method('exists')->will($this->returnValue(false));
     // Second save
     $mockedModel->expects($this->at($counter++))->method('exists')->will($this->returnValue(false));
     // Second save retry
     $mockedModel->expects($this->at($counter++))->method('exists')->will($this->returnValue(true));
     // Datasource exists check
     $mockedModel->expects($this->at($counter++))->method('exists')->will($this->returnValue(true));
     $this->storage = new DatabaseSession();
     $this->storage->write('foo', 'Some value');
     $return = $this->storage->read('foo');
     $this->assertSame('Some value', $return);
     $this->storage->write('foo', 'Some other value');
     $return = $this->storage->read('foo');
     $this->assertSame('Some other value', $return);
 }
Esempio n. 22
0
 /**
  * test that create() works without raising errors with a Mock Model
  *
  * @return void
  */
 public function testCreateNoErrorsWithMockModel()
 {
     $encoding = strtolower(Configure::read('App.encoding'));
     $ContactMock = $this->getMockBuilder('Contact')->disableOriginalConstructor()->getMock();
     ClassRegistry::removeObject('Contact');
     ClassRegistry::addObject('Contact', $ContactMock);
     $result = $this->Form->create('Contact', array('type' => 'GET'));
     $expected = array('form' => array('id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add', 'accept-charset' => $encoding));
     $this->assertTags($result, $expected);
 }
Esempio n. 23
0
 /**
  * tearDown method
  *
  * @access public
  * @return void
  */
 function endTest()
 {
     unset($this->Javascript->Html);
     unset($this->Javascript->Form);
     unset($this->Javascript);
     ClassRegistry::removeObject('view');
     unset($this->View);
 }
Esempio n. 24
0
 /**
  * beforeRender
  *
  * @return	void
  * @access	public
  */
 function beforeRender()
 {
     parent::beforeRender();
     // モバイルでは、mobileHelper::afterLayout をフックしてSJISへの変換が必要だが、
     // エラーが発生した場合には、afterLayoutでは、エラー用のビューを持ったviewクラスを取得できない。
     // 原因は、エラーが発生する前のcontrollerがviewを登録してしまっている為。
     // エラー時のview登録にフックする場所はここしかないのでここでviewの登録を削除する
     if ($this->name == 'CakeError') {
         ClassRegistry::removeObject('view');
     }
     $this->__loadDataToView();
     $this->set('isSSL', $this->RequestHandler->isSSL());
     $this->set('safeModeOn', ini_get('safe_mode'));
     $this->set('contentsTitle', $this->contentsTitle);
     $this->set('baserVersion', $this->getBaserVersion());
     $this->set('siteConfig', $this->siteConfigs);
     if (isset($this->siteConfigs['widget_area'])) {
         $this->set('widgetArea', $this->siteConfigs['widget_area']);
     }
 }
Esempio n. 25
0
 /**
  * Outputs cached dispatch for js, css, img, view cache
  *
  * @param string $url Requested URL
  * @access public
  */
 function cached($url)
 {
     if (strpos($url, 'css/') !== false || strpos($url, 'js/') !== false || strpos($url, 'img/') !== false) {
         if (strpos($url, 'ccss/') === 0) {
             include WWW_ROOT . DS . Configure::read('Asset.filter.css');
             $this->_stop();
         } elseif (strpos($url, 'cjs/') === 0) {
             include WWW_ROOT . DS . Configure::read('Asset.filter.js');
             $this->_stop();
         }
         $isAsset = false;
         $assets = array('js' => 'text/javascript', 'css' => 'text/css', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'png' => 'image/png');
         $ext = array_pop(explode('.', $url));
         foreach ($assets as $type => $contentType) {
             if ($type === $ext) {
                 $parts = explode('/', $url);
                 if ($parts[0] === 'css' || $parts[0] === 'js' || $parts[0] === 'img') {
                     $pos = 0;
                 } else {
                     $pos = strlen($parts[0]);
                 }
                 $isAsset = true;
                 break;
             }
         }
         if ($isAsset === true) {
             $ob = @ini_get("zlib.output_compression") !== '1' && extension_loaded("zlib") && strpos(env('HTTP_ACCEPT_ENCODING'), 'gzip') !== false;
             if ($ob && Configure::read('Asset.compress')) {
                 ob_start();
                 ob_start('ob_gzhandler');
             }
             $assetFile = null;
             $paths = array();
             if ($pos > 0) {
                 $plugin = substr($url, 0, $pos);
                 $url = preg_replace('/^' . preg_quote($plugin, '/') . '\\//i', '', $url);
                 $pluginPaths = Configure::read('pluginPaths');
                 $count = count($pluginPaths);
                 for ($i = 0; $i < $count; $i++) {
                     $paths[] = $pluginPaths[$i] . $plugin . DS . 'vendors' . DS;
                 }
             }
             $paths = array_merge($paths, Configure::read('vendorPaths'));
             foreach ($paths as $path) {
                 if (is_file($path . $url) && file_exists($path . $url)) {
                     $assetFile = $path . $url;
                     break;
                 }
             }
             if ($assetFile !== null) {
                 $fileModified = filemtime($assetFile);
                 header("Date: " . date("D, j M Y G:i:s ", $fileModified) . 'GMT');
                 header('Content-type: ' . $assets[$type]);
                 header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
                 header("Cache-Control: cache");
                 header("Pragma: cache");
                 if ($type === 'css' || $type === 'js') {
                     include $assetFile;
                 } else {
                     readfile($assetFile);
                 }
                 if (Configure::read('Asset.compress')) {
                     ob_end_flush();
                 }
                 return true;
             }
         }
     }
     if (Configure::read('Cache.check') === true) {
         $path = $this->here;
         if ($this->here == '/') {
             $path = 'home';
         }
         $path = strtolower(Inflector::slug($path));
         $filename = CACHE . 'views' . DS . $path . '.php';
         if (!file_exists($filename)) {
             $filename = CACHE . 'views' . DS . $path . '_index.php';
         }
         if (file_exists($filename)) {
             if (!class_exists('View')) {
                 App::import('Core', 'View');
             }
             $controller = null;
             $view =& new View($controller);
             $return = $view->renderCache($filename, getMicrotime());
             if (!$return) {
                 ClassRegistry::removeObject('view');
             }
             return $return;
         }
     }
     return false;
 }
Esempio n. 26
0
 /**
  * testMultiDimensionalField method
  *
  * @access public
  * @return void
  */
 function testMultiDimensionalField()
 {
     // PHP4 reference hack
     ClassRegistry::removeObject('view');
     ClassRegistry::addObject('view', $this->View);
     $this->Helper->setEntity('HelperTestPost', true);
     $this->Helper->setEntity('HelperTestPost.2.HelperTestComment.1.title');
     $this->assertEqual($this->View->model, 'HelperTestPost');
     $this->assertEqual($this->View->association, 'HelperTestComment');
     $this->assertEqual($this->View->modelId, 2);
     $this->assertEqual($this->View->field, 'title');
     $this->Helper->setEntity('HelperTestPost.1.HelperTestComment.1.HelperTestTag.1.created');
     $this->assertEqual($this->View->field, 'created');
     $this->assertEqual($this->View->association, 'HelperTestTag');
     $this->assertEqual($this->View->modelId, 1);
     $this->Helper->setEntity('HelperTestPost.0.HelperTestComment.1.HelperTestTag.1.fake');
     $this->assertEqual($this->View->model, 'HelperTestPost');
     $this->assertEqual($this->View->association, 'HelperTestTag');
     $this->assertEqual($this->View->field, null);
     $this->Helper->setEntity('1.HelperTestComment.1.HelperTestTag.created.year');
     $this->assertEqual($this->View->model, 'HelperTestPost');
     $this->assertEqual($this->View->association, 'HelperTestTag');
     $this->assertEqual($this->View->field, 'created');
     $this->assertEqual($this->View->modelId, 1);
     $this->assertEqual($this->View->fieldSuffix, 'year');
     $this->Helper->data['HelperTestPost'][2]['HelperTestComment'][1]['title'] = 'My Title';
     $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.title');
     $this->assertEqual($result, 'My Title');
     $this->Helper->data['HelperTestPost'][2]['HelperTestComment'][1]['created']['year'] = 2008;
     $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
     $this->assertEqual($result, 2008);
     $this->Helper->data[2]['HelperTestComment'][1]['created']['year'] = 2008;
     $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
     $this->assertEqual($result, 2008);
     $this->Helper->data['HelperTestPost']['title'] = 'My Title';
     $result = $this->Helper->value('title');
     $this->assertEqual($result, 'My Title');
     $this->Helper->data['My']['title'] = 'My Title';
     $result = $this->Helper->value('My.title');
     $this->assertEqual($result, 'My Title');
 }
Esempio n. 27
0
 /**
  * Tests prefixed datasource names for test purposes
  *
  */
 public function testPrefixedTestDatasource()
 {
     ClassRegistry::config(array('testing' => true));
     $Model = ClassRegistry::init('RegisterPrefixedDs');
     $this->assertEquals('test', $Model->useDbConfig);
     ClassRegistry::removeObject('RegisterPrefixedDs');
     $testConfig = ConnectionManager::getDataSource('test')->config;
     ConnectionManager::create('test_doesnotexist', $testConfig);
     $Model = ClassRegistry::init('RegisterArticle');
     $this->assertEquals('test', $Model->useDbConfig);
     $Model = ClassRegistry::init('RegisterPrefixedDs');
     $this->assertEquals('test_doesnotexist', $Model->useDbConfig);
 }
Esempio n. 28
0
 /**
  * testFieldSuffixForDate method
  *
  * @access public
  * @return void
  */
 function testFieldSuffixForDate()
 {
     // PHP4 reference hack
     ClassRegistry::removeObject('view');
     ClassRegistry::addObject('view', $this->View);
     $this->Helper->setEntity('HelperTestPost', true);
     $this->assertEqual($this->View->model, 'HelperTestPost');
     $this->assertEqual($this->View->field, null);
     $this->assertEqual($this->View->modelId, null);
     $this->assertEqual($this->View->association, null);
     $this->assertEqual($this->View->fieldSuffix, null);
     $this->Helper->setEntity('date.month');
     $this->assertEqual($this->View->model, 'HelperTestPost');
     $this->assertEqual($this->View->field, 'date');
     $this->assertEqual($this->View->modelId, null);
     $this->assertEqual($this->View->association, null);
     $this->assertEqual($this->View->fieldSuffix, 'month');
 }
Esempio n. 29
0
 /**
  * tearDown
  *
  * @access public
  * @return void
  */
 function tearDown()
 {
     unset($this->Toolbar, $this->Controller);
     ClassRegistry::removeObject('view');
     ClassRegistry::flush();
     Router::reload();
 }
Esempio n. 30
0
 /**
  * [PUBIC] データ送信
  *
  * @param mixed mail_content_id
  * @return void
  * @access public
  */
 function submit($id = null)
 {
     if (!$this->dbDatas['mailContent']['MailContent']['status']) {
         $this->notFound();
     }
     if (!$this->data) {
         $this->redirect(array('action' => 'index', $id));
     } else {
         // 複数のメールフォームに対応する為、プレフィックス付のCSVファイルに保存。
         // ※ nameフィールドの名称を[message]以外にする
         if ($this->dbDatas['mailContent']['MailContent']['name'] != 'message') {
             $prefix = $this->dbDatas['mailContent']['MailContent']['name'] . "_";
         } else {
             $prefix = "";
         }
         $this->Message->create($this->data);
         if ($this->Message->save(null, false)) {
             // メール送信
             $this->_sendEmail();
             // ビューを一旦初期化しないと携帯の場合に送信完了ページが文字化けしてしまう
             ClassRegistry::removeObject('view');
         } else {
             $this->Session->setFlash('【送信エラーです】<br />送信中にエラーが発生しました。しばらくたってから再度送信お願いします。');
             $this->set('sendError', true);
         }
     }
     $this->set('mailContent', $this->dbDatas['mailContent']);
     $this->render($this->dbDatas['mailContent']['MailContent']['form_template'] . DS . 'submit');
 }