diff --git a/composer.json b/composer.json index df950c2c..5075d81f 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ }, "autoload-dev": { "psr-4": { - "BootstrapUI\\Test\\": "tests" + "BootstrapUI\\Test\\": "tests", + "TestApp\\": "tests/test_app/TestApp" } } } diff --git a/src/View/UIViewTrait.php b/src/View/UIViewTrait.php index d7b1745f..c6a43235 100644 --- a/src/View/UIViewTrait.php +++ b/src/View/UIViewTrait.php @@ -11,9 +11,9 @@ 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) * @@ -21,9 +21,11 @@ trait UIViewTrait */ 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']; } diff --git a/tests/TestCase/View/UIViewTraitTest.php b/tests/TestCase/View/UIViewTraitTest.php index c34f9545..79e8d640 100644 --- a/tests/TestCase/View/UIViewTraitTest.php +++ b/tests/TestCase/View/UIViewTraitTest.php @@ -2,6 +2,7 @@ namespace BootstrapUI\View; +use Cake\Core\Configure; use Cake\TestSuite\TestCase; class UIViewTraitTest extends TestCase @@ -17,6 +18,7 @@ public function setUp() { parent::setUp(); + Configure::write('App.namespace', 'TestApp'); $this->View = new UIView(); $this->View->layout = 'default'; } @@ -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}"); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 680e4d4a..c2234c15 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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'; @@ -65,4 +78,4 @@ ] ]); -Plugin::load('BootstrapUI', ['path' => ROOT]); +Plugin::load('BootstrapUI', ['path' => ROOT . DS]); diff --git a/tests/test_app/TestApp/Template/Cell/Articles/display.ctp b/tests/test_app/TestApp/Template/Cell/Articles/display.ctp new file mode 100644 index 00000000..f7bae393 --- /dev/null +++ b/tests/test_app/TestApp/Template/Cell/Articles/display.ctp @@ -0,0 +1 @@ +articles cell display diff --git a/tests/test_app/TestApp/View/Cell/ArticlesCell.php b/tests/test_app/TestApp/View/Cell/ArticlesCell.php new file mode 100644 index 00000000..dd1798d7 --- /dev/null +++ b/tests/test_app/TestApp/View/Cell/ArticlesCell.php @@ -0,0 +1,15 @@ +