コード例 #1
0
 /**
  * tearDown
  *
  * @return void
  */
 public function tearDown()
 {
     unset($this->Table, $this->Behavior, $this->Email);
     Router::fullBaseUrl($this->fullBaseBackup);
     Email::dropTransport('test');
     parent::tearDown();
 }
コード例 #2
0
ファイル: UrlHelper.php プロジェクト: JesseDarellMoore/CS499
 /**
  * Generate URL for given asset file. Depending on options passed provides full URL with domain name.
  * Also calls Helper::assetTimestamp() to add timestamp to local files
  *
  * @param string|array $path Path string or URL array
  * @param array $options Options array. Possible keys:
  *   `fullBase` Return full URL with domain name
  *   `pathPrefix` Path prefix for relative URLs
  *   `ext` Asset extension to append
  *   `plugin` False value will prevent parsing path as a plugin
  * @return string Generated URL
  */
 public function assetUrl($path, array $options = [])
 {
     if (is_array($path)) {
         return $this->build($path, !empty($options['fullBase']));
     }
     if (strpos($path, '://') !== false) {
         return $path;
     }
     if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
         list($plugin, $path) = $this->_View->pluginSplit($path, false);
     }
     if (!empty($options['pathPrefix']) && $path[0] !== '/') {
         $path = $options['pathPrefix'] . $path;
     }
     if (!empty($options['ext']) && strpos($path, '?') === false && substr($path, -strlen($options['ext'])) !== $options['ext']) {
         $path .= $options['ext'];
     }
     if (preg_match('|^([a-z0-9]+:)?//|', $path)) {
         return $path;
     }
     if (isset($plugin)) {
         $path = Inflector::underscore($plugin) . '/' . $path;
     }
     $path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path)));
     if (!empty($options['fullBase'])) {
         $path = rtrim(Router::fullBaseUrl(), '/') . '/' . ltrim($path, '/');
     }
     return $path;
 }
コード例 #3
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     unset($this->Users);
     Router::fullBaseUrl($this->fullBaseBackup);
     Email::drop('default');
     Email::dropTransport('test');
     Email::config('default', $this->configEmail);
     parent::tearDown();
 }
コード例 #4
0
 /**
  * setUp
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->EmailSender = $this->getMockBuilder('CakeDC\\Users\\Email\\EmailSender')->setMethods(['_getEmailInstance', 'getMailer'])->getMock();
     $this->UserMailer = $this->getMockBuilder('CakeDC\\Users\\Mailer\\UserMailer')->setMethods(['send'])->getMock();
     $this->fullBaseBackup = Router::fullBaseUrl();
     Router::fullBaseUrl('http://users.test');
     Email::configTransport('test', ['className' => 'Debug']);
 }
コード例 #5
0
ファイル: Macros.php プロジェクト: Cheren/union
 /**
  * Replace array keys in macros key.
  *
  * @param array $list
  * @return array
  */
 protected function _getList(array $list = [])
 {
     $result = [];
     $list['base_url'] = Router::fullBaseUrl();
     foreach ($list as $key => $value) {
         $key = '{' . $key . '}';
         $result[$key] = $value;
     }
     return $result;
 }
コード例 #6
0
ファイル: MacrosTest.php プロジェクト: UnionCMS/Core
 /**
  * @return void
  */
 public function testSetGet()
 {
     $macros = new Macros();
     $this->assertSame(['base_url' => Router::fullBaseUrl()], $macros->get());
     $macros->set('test_1', 'Test 1')->set('test_2', 'Test 2')->set('test_3', 'Test 3');
     $this->assertSame(['test_3' => 'Test 3', 'test_2' => 'Test 2', 'test_1' => 'Test 1', 'base_url' => Router::fullBaseUrl()], $macros->get());
     $this->assertSame('Test 3', $macros->get('test_3'));
     $entity = new Entity(['status' => 'Publish']);
     $macros = new Macros($entity);
     $this->assertSame(['base_url' => 'http://localhost', 'status' => 'Publish'], $macros->get());
 }
コード例 #7
0
 public function afterForgot($event, $user)
 {
     $email = new Email('default');
     $email->viewVars(['user' => $user, 'resetUrl' => Router::fullBaseUrl() . Router::url(['prefix' => false, 'plugin' => 'Users', 'controller' => 'Users', 'action' => 'reset', $user['email'], $user['request_key']]), 'baseUrl' => Router::fullBaseUrl(), 'loginUrl' => Router::fullBaseUrl() . '/login']);
     $email->from(Configure::read('Users.email.from'));
     $email->subject(Configure::read('Users.email.afterForgot.subject'));
     $email->emailFormat('both');
     $email->transport(Configure::read('Users.email.transport'));
     $email->template('Users.afterForgot', 'Users.default');
     $email->to($user['email']);
     $email->send();
 }
コード例 #8
0
 public function read($path)
 {
     $dir = new Folder($path);
     $read = $dir->read();
     $result = [];
     foreach ($read[0] as $folder) {
         $info = new Folder($path . DS . $folder);
         $reference = Router::fullBaseUrl() . '/' . $this->toRelative($path . '/' . $folder);
         $data = ['name' => $folder, 'type' => 'folder', 'path' => $path . DS . $folder, 'reference' => $reference, 'extension' => 'folder', 'size' => $info->dirsize()];
         $result[] = $data;
     }
     foreach ($read[1] as $file) {
         $info = new File($path . DS . $file, false);
         $reference = Router::fullBaseUrl() . '/' . $this->toRelative($path . '/' . $file);
         $data = ['name' => $info->info()['basename'], 'type' => 'file', 'path' => $path, 'reference' => $reference, 'extension' => $info->info()['extension'], 'size' => $info->info()['filesize']];
         $result[] = $data;
     }
     return $result;
 }
コード例 #9
0
 /**
  * {@inheritDoc}
  */
 public function getUser(Request $request)
 {
     $auth = $request->header('Authorization');
     if (empty($auth) && function_exists('apache_request_headers')) {
         $headers = apache_request_headers();
         $auth = empty($headers['Authorization']) ? null : $headers['Authorization'];
     }
     if (empty($auth)) {
         return false;
     }
     if (strpos($auth, ' ') === false) {
         return false;
     }
     list($authType, $authString) = explode(' ', $auth, 2);
     $authParams = explode(',', $authString);
     if (count($authParams) < 3) {
         return false;
     }
     switch (strtolower($authType)) {
         case 'url-encoded-api-key':
             $postFields = ['messageDigest' => $authParams[1], 'timestamp' => $authParams[2], 'message' => Router::fullBaseUrl() . $request->here()];
             break;
         case 'nonce-encoded-api-key':
         case 'nonce-encoded-wssession-key':
             $postFields = ['nonceKey' => $authParams[1], 'messageDigest' => $authParams[2]];
             break;
         default:
             //unknown auth type
             return false;
     }
     $postFields['wsId'] = $authParams[0];
     $result = $this->client()->post("https://ws.byu.edu/authentication/services/rest/v1/provider/{$authType}/validate", $postFields);
     if (!$result || !$result->isOk()) {
         return false;
     }
     $response = json_decode($result->body(), true);
     if (empty($response['netId'])) {
         return false;
     }
     $response['username'] = $response['netId'];
     return $response;
 }
コード例 #10
0
ファイル: UrlHelper.php プロジェクト: UnionCMS/Core
 /**
  * Generates URL for given asset file.
  *
  * @param array|string $path
  * @param array $options
  * @return array|null|string
  */
 public function assetUrl($path, array $options = [])
 {
     if (is_array($path)) {
         return $this->build($path, !empty($options['fullBase']));
     }
     if (empty(FS::ext($path))) {
         $path .= '.' . $options['ext'];
     }
     $Path = $this->_View->getPath();
     $relative = $Path->isVirtual($path) ? $Path->get($path) : $Path->get('root:' . $path);
     if (strpos($path, '://') !== false) {
         return $path;
     }
     if ($relative !== null) {
         $path = $Path->url($this->_encodeUrl($this->assetTimestamp($relative)), false);
         if (!empty($options['fullBase'])) {
             $path = rtrim(Router::fullBaseUrl(), '/') . '/' . ltrim($path, '/');
         }
         return $path;
     }
     return null;
 }
コード例 #11
0
ファイル: UrlHelperTest.php プロジェクト: rashmi/newrepo
 /**
  * test image()
  *
  * @return void
  */
 public function testImage()
 {
     $result = $this->Helper->image('foo.jpg');
     $this->assertEquals('img/foo.jpg', $result);
     $result = $this->Helper->image('foo.jpg', ['fullBase' => true]);
     $this->assertEquals(Router::fullBaseUrl() . '/img/foo.jpg', $result);
     $result = $this->Helper->image('dir/sub dir/my image.jpg');
     $this->assertEquals('img/dir/sub%20dir/my%20image.jpg', $result);
     $result = $this->Helper->image('foo.jpg?one=two&three=four');
     $this->assertEquals('img/foo.jpg?one=two&amp;three=four', $result);
     $result = $this->Helper->image('dir/big+tall/image.jpg');
     $this->assertEquals('img/dir/big%2Btall/image.jpg', $result);
     $result = $this->Helper->image('cid:foo.jpg');
     $this->assertEquals('cid:foo.jpg', $result);
     $result = $this->Helper->image('CID:foo.jpg');
     $this->assertEquals('CID:foo.jpg', $result);
 }
コード例 #12
0
 /**
  * test assetUrl application
  *
  * @return void
  */
 public function testAssetUrl()
 {
     Router::connect('/:controller/:action/*');
     $this->Helper->webroot = '';
     $result = $this->Helper->assetUrl(array('controller' => 'js', 'action' => 'post', 'ext' => 'js'), array('fullBase' => true));
     $this->assertEquals(Router::fullBaseUrl() . '/js/post.js', $result);
     $result = $this->Helper->assetUrl('foo.jpg', array('pathPrefix' => 'img/'));
     $this->assertEquals('img/foo.jpg', $result);
     $result = $this->Helper->assetUrl('foo.jpg', array('fullBase' => true));
     $this->assertEquals(Router::fullBaseUrl() . '/foo.jpg', $result);
     $result = $this->Helper->assetUrl('style', array('ext' => '.css'));
     $this->assertEquals('style.css', $result);
     $result = $this->Helper->assetUrl('dir/sub dir/my image', array('ext' => '.jpg'));
     $this->assertEquals('dir/sub%20dir/my%20image.jpg', $result);
     $result = $this->Helper->assetUrl('foo.jpg?one=two&three=four');
     $this->assertEquals('foo.jpg?one=two&amp;three=four', $result);
     $result = $this->Helper->assetUrl('dir/big+tall/image', array('ext' => '.jpg'));
     $this->assertEquals('dir/big%2Btall/image.jpg', $result);
 }
コード例 #13
0
 /**
  * Set Canonical based on configuration array
  */
 public function testSetCanonical()
 {
     $expected = ['canonical' => Router::fullBaseUrl() . '/articles/view?slug=test-title-one', 'active' => true];
     $actual = $this->Articles->setCanonical($this->defaultEntity, '/articles/view?slug=test-title-one', $this->defaultConfig['urls'][0]);
     $this->assertEquals($expected, $actual);
     $actual = $this->Articles->setCanonical($this->defaultEntity, '/articles/view?slug=test-title-one', []);
     $this->assertFalse($actual);
 }
コード例 #14
0
 /**
  * Get the URL for a given asset name.
  *
  * Takes an build filename, and returns the URL
  * to that build file.
  *
  * @param string $file The build file that you want a URL for.
  * @param bool|array $full Whether or not the URL should have the full base path.
  * @return string The generated URL.
  * @throws RuntimeException when the build file does not exist.
  */
 public function url($file = null, $full = false)
 {
     $collection = $this->collection();
     if (!$collection->contains($file)) {
         throw new RuntimeException('Cannot get URL for build file that does not exist.');
     }
     $options = $full;
     if (!is_array($full)) {
         $options = ['full' => $full];
     }
     $options += ['full' => false];
     $target = $collection->get($file);
     $type = $target->ext();
     $config = $this->assetConfig();
     $baseUrl = $config->get($type . '.baseUrl');
     $devMode = Configure::read('debug');
     // CDN routes.
     if ($baseUrl && !$devMode) {
         return $baseUrl . $this->_getBuildName($target);
     }
     $root = str_replace('\\', '/', WWW_ROOT);
     $path = str_replace('\\', '/', $target->outputDir());
     $path = str_replace($root, '/', $path);
     if (!$devMode) {
         $path = rtrim($path, '/') . '/';
         $route = $path . $this->_getBuildName($target);
     }
     if ($devMode || $config->general('alwaysEnableController')) {
         $route = $this->_getRoute($target, $path);
     }
     if (DS === '\\') {
         $route = str_replace(DS, '/', $route);
     }
     if ($options['full']) {
         $base = Router::fullBaseUrl();
         return $base . $route;
     }
     return $route;
 }
コード例 #15
0
 /**
  * Get the url for the given page.
  *
  * @param int $page
  *
  * @return string
  */
 public function getUrl($page)
 {
     $url = Router::parse(Router::url());
     $url['page'] = $page;
     return Router::fullBaseUrl() . Router::url($url);
 }
コード例 #16
0
    /**
     * Test method
     *
     * @return void
     */
    public function testSendResetPasswordEmail()
    {
        $behavior = $this->table->behaviors()->Password;
        $this->fullBaseBackup = Router::fullBaseUrl();
        Router::fullBaseUrl('http://users.test');
        Email::configTransport('test', ['className' => 'Debug']);
        $this->Email = new Email(['from' => '*****@*****.**', 'transport' => 'test', 'template' => 'CakeDC/Users.reset_password', 'emailFormat' => 'both']);
        $user = $this->table->newEntity(['first_name' => 'FirstName', 'email' => '*****@*****.**', 'token' => '12345']);
        $result = $behavior->sendResetPasswordEmail($user, $this->Email, 'CakeDC/Users.reset_password');
        $this->assertTextContains('From: test@example.com', $result['headers']);
        $this->assertTextContains('To: test@example.com', $result['headers']);
        $this->assertTextContains('Subject: FirstName, Your reset password link', $result['headers']);
        $this->assertTextContains('Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Hi FirstName,

Please copy the following address in your web browser http://users.test/users/users/reset-password/12345
Thank you,
', $result['message']);
        $this->assertTextContains('Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
    <title>Email/html</title>
</head>
<body>
    <p>
Hi FirstName,
</p>
<p>
    <strong><a href="http://users.test/users/users/reset-password/12345">Reset your password here</a></strong>
</p>
<p>
    If the link is not correcly displayed, please copy the following address in your web browser http://users.test/users/users/reset-password/12345</p>
<p>
    Thank you,
</p>
</body>
</html>
', $result['message']);
        Router::fullBaseUrl($this->fullBaseBackup);
        Email::dropTransport('test');
    }
コード例 #17
0
 /**
  * @param Cake\ORM\Entity $entity The entity
  * @param string $uri The Uri
  * @param array $config Configuration array for the uri
  * @return mixed array|false
  */
 public function setCanonical(Entity $entity, $uri, array $config = [])
 {
     if (array_key_exists('canonical', $config) && $config['canonical'] === true) {
         return ['canonical' => Router::fullBaseUrl() . $uri, 'active' => true];
     }
     return false;
 }
コード例 #18
0
ファイル: RouterTest.php プロジェクト: rashmi/newrepo
 /**
  * Test that Router uses the correct url including base path for requesting the current actions.
  *
  * @return void
  */
 public function testCurrentUrlWithBasePath()
 {
     Router::fullBaseUrl('http://example.com');
     $request = new Request();
     $request->addParams(['action' => 'view', 'plugin' => null, 'controller' => 'pages', 'pass' => ['1']]);
     $request->base = '/cakephp';
     $request->here = '/cakephp/pages/view/1';
     Router::setRequestInfo($request);
     $this->assertEquals('http://example.com/cakephp/pages/view/1', Router::url(null, true));
     $this->assertEquals('/cakephp/pages/view/1', Router::url());
 }
コード例 #19
0
ファイル: users.php プロジェクト: CakeDC/users
<?php

/**
 * Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
use Cake\Core\Configure;
use Cake\Routing\Router;
$config = ['Users' => ['table' => 'CakeDC/Users.Users', 'auth' => true, 'passwordHasher' => '\\Cake\\Auth\\DefaultPasswordHasher', 'Token' => ['expiration' => 3600], 'Email' => ['required' => true, 'validate' => true], 'Registration' => ['active' => true, 'reCaptcha' => true, 'allowLoggedIn' => false, 'ensureActive' => false], 'reCaptcha' => ['key' => null, 'secret' => null, 'registration' => false, 'login' => false], 'Tos' => ['required' => true], 'Social' => ['login' => false], 'GoogleAuthenticator' => ['login' => false, 'issuer' => null, 'digits' => 6, 'period' => 30, 'algorithm' => 'sha1', 'qrcodeprovider' => null, 'rngprovider' => null, 'encryptionKey' => false], 'Profile' => ['viewOthers' => true, 'route' => ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile']], 'Key' => ['Session' => ['social' => 'Users.social', 'resetPasswordUserId' => 'Users.resetPasswordUserId'], 'Form' => ['social' => 'social'], 'Data' => ['email' => 'email', 'socialEmail' => 'info.email', 'rememberMe' => 'remember_me']], 'Avatar' => ['placeholder' => 'CakeDC/Users.avatar_placeholder.png'], 'RememberMe' => ['active' => true, 'Cookie' => ['name' => 'remember_me', 'Config' => ['expires' => '1 month', 'httpOnly' => true]]]], 'GoogleAuthenticator' => ['verifyAction' => ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'verify', 'prefix' => false]], 'Auth' => ['loginAction' => ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'login', 'prefix' => false], 'authenticate' => ['all' => ['finder' => 'auth'], 'CakeDC/Users.ApiKey', 'CakeDC/Users.RememberMe', 'Form'], 'authorize' => ['CakeDC/Users.Superuser', 'CakeDC/Users.SimpleRbac']], 'OAuth' => ['path' => ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'socialLogin', 'prefix' => null], 'providers' => ['facebook' => ['className' => 'League\\OAuth2\\Client\\Provider\\Facebook', 'options' => ['graphApiVersion' => 'v2.5', 'redirectUri' => Router::fullBaseUrl() . '/auth/facebook']], 'twitter' => ['options' => ['redirectUri' => Router::fullBaseUrl() . '/auth/twitter']], 'linkedIn' => ['className' => 'League\\OAuth2\\Client\\Provider\\LinkedIn', 'options' => ['redirectUri' => Router::fullBaseUrl() . '/auth/linkedIn']], 'instagram' => ['className' => 'League\\OAuth2\\Client\\Provider\\Instagram', 'options' => ['redirectUri' => Router::fullBaseUrl() . '/auth/instagram']], 'google' => ['className' => 'League\\OAuth2\\Client\\Provider\\Google', 'options' => ['userFields' => ['url', 'aboutMe'], 'redirectUri' => Router::fullBaseUrl() . '/auth/google']]]]];
return $config;
コード例 #20
0
 /**
  * testLink method
  *
  * @return void
  */
 public function testLink()
 {
     Router::connect('/:controller/:action/*');
     $this->Html->request->webroot = '';
     $result = $this->Html->link('/home');
     $expected = array('a' => array('href' => '/home'), 'preg:/\\/home/', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link(array('action' => 'login', '<[You]>'));
     $expected = array('a' => array('href' => '/login/%3C%5BYou%5D%3E'), 'preg:/\\/login\\/&lt;\\[You\\]&gt;/', '/a');
     $this->assertTags($result, $expected);
     Router::reload();
     Router::connect('/:controller', array('action' => 'index'));
     Router::connect('/:controller/:action/*');
     $result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', '_full' => true));
     $expected = array('a' => array('href' => Router::fullBaseUrl() . '/posts'), 'Posts', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
     $expected = array('a' => array('href' => '/home', 'onclick' => 'if (confirm(&quot;Are you sure you want to do this?&quot;)) { return true; } return false;'), 'Home', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Home', '/home', array('escape' => false, 'confirm' => 'Confirm\'s "nightmares"'));
     $expected = array('a' => array('href' => '/home', 'onclick' => 'if (confirm(&quot;Confirm&#039;s \\&quot;nightmares\\&quot;&quot;)) { return true; } return false;'), 'Home', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Home', '/home', array('default' => false));
     $expected = array('a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'), 'Home', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Home', '/home', array('default' => false, 'onclick' => 'someFunction();'));
     $expected = array('a' => array('href' => '/home', 'onclick' => 'someFunction(); event.returnValue = false; return false;'), 'Home', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Next >', '#');
     $expected = array('a' => array('href' => '#'), 'Next &gt;', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Next >', '#', array('escape' => true));
     $expected = array('a' => array('href' => '#'), 'Next &gt;', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Next >', '#', array('escape' => 'utf-8'));
     $expected = array('a' => array('href' => '#'), 'Next &gt;', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Next >', '#', array('escape' => false));
     $expected = array('a' => array('href' => '#'), 'Next >', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Next >', '#', array('title' => 'to escape &#8230; or not escape?', 'escape' => false));
     $expected = array('a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'), 'Next >', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Next >', '#', array('title' => 'to escape &#8230; or not escape?', 'escape' => true));
     $expected = array('a' => array('href' => '#', 'title' => 'to escape &amp;#8230; or not escape?'), 'Next &gt;', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Next >', '#', array('title' => 'Next >', 'escapeTitle' => false));
     $expected = array('a' => array('href' => '#', 'title' => 'Next &gt;'), 'Next >', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('Original size', array('controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)));
     $expected = array('a' => array('href' => '/images/view/3?height=100&amp;width=200'), 'Original size', '/a');
     $this->assertTags($result, $expected);
     Configure::write('Asset.timestamp', false);
     $result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false));
     $expected = array('a' => array('href' => '#'), 'img' => array('src' => 'img/test.gif', 'alt' => ''), '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link($this->Html->image('test.gif'), '#', array('title' => 'hey "howdy"', 'escapeTitle' => false));
     $expected = array('a' => array('href' => '#', 'title' => 'hey &quot;howdy&quot;'), 'img' => array('src' => 'img/test.gif', 'alt' => ''), '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->image('test.gif', array('url' => '#'));
     $expected = array('a' => array('href' => '#'), 'img' => array('src' => 'img/test.gif', 'alt' => ''), '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link($this->Html->image('../favicon.ico'), '#', array('escape' => false));
     $expected = array('a' => array('href' => '#'), 'img' => array('src' => 'img/../favicon.ico', 'alt' => ''), '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->image('../favicon.ico', array('url' => '#'));
     $expected = array('a' => array('href' => '#'), 'img' => array('src' => 'img/../favicon.ico', 'alt' => ''), '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('http://www.example.org?param1=value1&param2=value2');
     $expected = array('a' => array('href' => 'http://www.example.org?param1=value1&amp;param2=value2'), 'http://www.example.org?param1=value1&amp;param2=value2', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('alert', 'javascript:alert(\'cakephp\');');
     $expected = array('a' => array('href' => 'javascript:alert(&#039;cakephp&#039;);'), 'alert', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('write me', 'mailto:example@cakephp.org');
     $expected = array('a' => array('href' => 'mailto:example@cakephp.org'), 'write me', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('call me on 0123465-798', 'tel:0123465-798');
     $expected = array('a' => array('href' => 'tel:0123465-798'), 'call me on 0123465-798', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('text me on 0123465-798', 'sms:0123465-798');
     $expected = array('a' => array('href' => 'sms:0123465-798'), 'text me on 0123465-798', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('say hello to 0123465-798', 'sms:0123465-798?body=hello there');
     $expected = array('a' => array('href' => 'sms:0123465-798?body=hello there'), 'say hello to 0123465-798', '/a');
     $this->assertTags($result, $expected);
     $result = $this->Html->link('say hello to 0123465-798', 'sms:0123465-798?body=hello "cakephp"');
     $expected = array('a' => array('href' => 'sms:0123465-798?body=hello &quot;cakephp&quot;'), 'say hello to 0123465-798', '/a');
     $this->assertTags($result, $expected);
 }
コード例 #21
0
 /**
  * test
  *
  * @return void
  */
 public function testIsUrlAuthorizedUrlAbsoluteForCurrentAppString()
 {
     $event = new Event('event');
     $event->data = ['url' => Router::fullBaseUrl() . '/route'];
     $this->Controller->Auth = $this->getMockBuilder('Cake\\Controller\\Component\\AuthComponent')->setMethods(['user', 'isAuthorized'])->disableOriginalConstructor()->getMock();
     $this->Controller->Auth->expects($this->once())->method('user')->will($this->returnValue(['id' => 1]));
     $request = new Request('/route');
     $request->params = ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'requestResetPassword', 'pass' => [], '_matchedRoute' => '/route/*'];
     $this->Controller->Auth->expects($this->once())->method('isAuthorized')->with(null, $request)->will($this->returnValue(true));
     $result = $this->Controller->UsersAuth->isUrlAuthorized($event);
     $this->assertTrue($result);
 }
コード例 #22
0
 /**
  * Getter for FractalManager instance.
  *
  * @return Manager
  */
 public function getFractalManager()
 {
     if (!$this->_fractalManager) {
         $manager = new Manager();
         $serializer = $this->config('serializer');
         $manager->setSerializer(new $serializer($this->config('baseUrl') ?: Router::fullBaseUrl()));
         $manager->parseIncludes((array) $this->request->query('include'));
         $manager->setRecursionLimit($this->config('recursionLimit'));
         $this->_fractalManager = $manager;
     }
     return $this->_fractalManager;
 }
コード例 #23
0
ファイル: JsHelper.php プロジェクト: UnionCMS/Core
 /**
  * Setup js variables.
  *
  * @return void
  */
 protected function _setJsVars()
 {
     $request = $this->request;
     $vars = ['base_url' => Router::fullBaseUrl(), 'plugin' => $request->param('plugin'), 'action' => $request->param('action'), 'prefix' => $request->param('prefix'), 'controller' => $request->param('controller'), 'alert_ok' => __d('alert', 'Ok'), 'alert_cancel' => __d('alert', 'Cancel'), 'alert_sure' => __d('alert', 'Are you sure?')];
     $this->Html->scriptBlock('window.Union = ' . json_encode($vars), ['block' => 'css']);
 }
コード例 #24
0
 /**
  * Test that Router uses App.base to build URL's when there are no stored
  * request objects.
  *
  * @return void
  */
 public function testBaseUrlWithBasePath()
 {
     Configure::write('App.base', '/cakephp');
     Router::fullBaseUrl('http://example.com');
     $this->assertEquals('http://example.com/cakephp/tasks', Router::url('/tasks', true));
 }
コード例 #25
0
 /**
  * QueueBYUEmailTask::run()
  *
  * @param mixed $data Job data
  * @param int $id The id of the QueuedTask
  * @return bool Success
  */
 public function run($data, $id = null)
 {
     if (!isset($data['settings'])) {
         $this->err('Queue BYUEmail task called without settings data.');
         return false;
     }
     if (isset($data['fullBaseUrl'])) {
         Router::fullBaseUrl($data['fullBaseUrl']);
     }
     $this->Email = new Email();
     foreach ($data['settings'] as $method => $setting) {
         $this->Email->{$method}($setting);
     }
     $message = null;
     if (!empty($data['vars'])) {
         if (isset($data['vars']['content'])) {
             $message = $data['vars']['content'];
         }
         $this->Email->viewVars($data['vars']);
     }
     $result = $this->Email->send($message);
     if ($this->Email->transport() instanceof \Cake\Mailer\Transport\DebugTransport) {
         //QueueShell ignores everything except truthiness of result,
         //so we need to log debug data ourselves
         $this->log($result, 'debug');
     }
     return $result;
 }