Skip to content

Commit

Permalink
Merge pull request #135 from FriendsOfCake/issue-134
Browse files Browse the repository at this point in the history
Issue 134
  • Loading branch information
lorenzo committed Mar 13, 2016
2 parents 1e69510 + a30bc48 commit 1030a62
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 19 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
},
"autoload-dev": {
"psr-4": {
"BootstrapUI\\Test\\": "tests"
"BootstrapUI\\Test\\": "tests",
"TestApp\\": "tests/test_app/TestApp"
}
}
}
10 changes: 6 additions & 4 deletions src/View/UIViewTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ trait UIViewTrait
/**
* Initialization hook method.
*
* ### Options: Associative array with valid keys:
* @param array $options Associative array with valid keys:
* - `layout`:
* - If empty or true will use the plugin's layout
* - If not set or true will use the plugin's layout
* - If a layout name passed it will be used
* - If false do nothing (will keep your layout)
*
* @return void
*/
public function initializeUI(array $options = [])
{
if (!isset($options['layout']) || $options['layout'] === true) {
if ((!isset($options['layout']) || $options['layout'] === true) &&
$this->layout === 'default'
) {
$this->layout = 'BootstrapUI.default';
} elseif (!empty($options['layout']) || $options['layout'] === '') {
} elseif (isset($options['layout']) && is_string($options['layout'])) {
$this->layout = $options['layout'];
}

Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase/View/UIViewTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BootstrapUI\View;

use Cake\Core\Configure;
use Cake\TestSuite\TestCase;

class UIViewTraitTest extends TestCase
Expand All @@ -17,6 +18,7 @@ public function setUp()
{
parent::setUp();

Configure::write('App.namespace', 'TestApp');
$this->View = new UIView();
$this->View->layout = 'default';
}
Expand Down Expand Up @@ -63,4 +65,12 @@ public function testInitializeUI()
]);
$this->assertSame('', $this->View->layout);
}

public function testCellRendering()
{
$cell = $this->View->cell('Articles');

$this->assertEquals('display', $cell->template);
$this->assertEquals("articles cell display\n", "{$cell}");
}
}
41 changes: 27 additions & 14 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,37 @@

require_once 'vendor/autoload.php';

// Path constants to a few helpful things.
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}

define('ROOT', dirname(__DIR__) . DS);
define('CAKE_CORE_INCLUDE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp');
define('CORE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp' . DS);
define('CAKE', CORE_PATH . 'src' . DS);
define('TESTS', ROOT . 'tests');
define('APP', ROOT . 'tests' . DS . 'test_files' . DS . 'app' . DS);
define('APP_DIR', 'app');
define('ROOT', dirname(__DIR__));
define('APP_DIR', 'TestApp');
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', dirname(APP) . DS . 'webroot' . DS);

define('TMP', sys_get_temp_dir() . DS);
define('CONFIG', APP . 'config' . DS);
define('CACHE', TMP);
define('LOGS', TMP);
define('LOGS', TMP . 'logs' . DS);
define('CACHE', TMP . 'cache' . DS);
define('SESSIONS', TMP . 'sessions' . DS);

define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'vendor' . DS . 'cakephp' . DS . 'cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . 'src' . DS);
define('CORE_TESTS', CORE_PATH . 'tests' . DS);
define('CORE_TEST_CASES', CORE_TESTS . 'TestCase');
define('TEST_APP', ROOT . DS . 'tests' . DS . 'test_app' . DS);

// Point app constants to the test app.
define('APP', TEST_APP . 'TestApp' . DS);
define('WWW_ROOT', TEST_APP . 'webroot' . DS);
define('CONFIG', TEST_APP . 'config' . DS);

//@codingStandardsIgnoreStart
@mkdir(LOGS);
@mkdir(SESSIONS);
@mkdir(CACHE);
@mkdir(CACHE . 'views');
@mkdir(CACHE . 'models');
//@codingStandardsIgnoreEnd

require_once CORE_PATH . 'config/bootstrap.php';

Expand Down Expand Up @@ -65,4 +78,4 @@
]
]);

Plugin::load('BootstrapUI', ['path' => ROOT]);
Plugin::load('BootstrapUI', ['path' => ROOT . DS]);
1 change: 1 addition & 0 deletions tests/test_app/TestApp/Template/Cell/Articles/display.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
articles cell display
15 changes: 15 additions & 0 deletions tests/test_app/TestApp/View/Cell/ArticlesCell.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace TestApp\View\Cell;

class ArticlesCell extends \Cake\View\Cell
{

/**
* Default cell action.
*
* @return void
*/
public function display()
{
}
}
File renamed without changes.
Empty file removed tests/test_files/plugins/.gitkeep
Empty file.
Empty file removed tests/test_files/webroot/.gitkeep
Empty file.

0 comments on commit 1030a62

Please sign in to comment.