From 64fda37b961dd9ce85a7d27ae9fda360f1a9060e Mon Sep 17 00:00:00 2001 From: alphadevx Date: Thu, 13 Aug 2015 18:29:11 +0100 Subject: [PATCH] #165 - added a unit test for SequenceView::listView() --- Alpha/View/SequenceView.php | 14 ++- test/Alpha/Test/View/SequenceViewTest.php | 100 ++++++++++++++++++++++ 2 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 test/Alpha/Test/View/SequenceViewTest.php diff --git a/Alpha/View/SequenceView.php b/Alpha/View/SequenceView.php index 79467727..c8910b44 100644 --- a/Alpha/View/SequenceView.php +++ b/Alpha/View/SequenceView.php @@ -4,6 +4,7 @@ use Alpha\Controller\Front\FrontController; use Alpha\Util\Logging\Logger; +use Alpha\Util\Config\ConfigProvider; use Alpha\Exception\IllegalArguementException; use Alpha\Model\Type\String; use Alpha\View\Widget\Button; @@ -157,14 +158,8 @@ public function listView($fields=array()) $fields['formFields'] = $html; - // View button - if (strpos($fields['URI'], '/tk/') !== false) { - $button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';", 'View', 'viewBut'); - $fields['viewButton'] = $button->render(); - } else { - $button = new Button("document.location = '".$this->BO->get('URL')."';", 'View', 'viewBut'); - $fields['viewButton'] = $button->render(); - } + $button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';", 'View', 'viewBut'); + $fields['viewButton'] = $button->render(); // supressing the edit/delete buttons for Sequences $fields['adminButtons'] = ''; @@ -172,12 +167,13 @@ public function listView($fields=array()) // buffer security fields to $formSecurityFields variable $fields['formSecurityFields'] = $this->renderSecurityFields(); - $this->loadTemplate($this->BO, 'list', $fields); + $html = $this->loadTemplate($this->BO, 'list', $fields); if (method_exists($this, 'after_listView_callback')) $this->after_listView_callback(); self::$logger->debug('< + * @license http://www.opensource.org/licenses/bsd-license.php The BSD License + * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework). + * All rights reserved. + * + *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the
+ * following conditions are met:
+ *
+ * * Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer in the documentation and/or other
+ *   materials provided with the distribution.
+ * * Neither the name of the Alpha Framework nor the names
+ *   of its contributors may be used to endorse or promote
+ *   products derived from this software without specific
+ *   prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * + */ +class SequenceViewTest extends \PHPUnit_Framework_TestCase +{ + /** + * {@inheritDoc} + * + * @since 2.0 + */ + protected function setUp() + { + $config = ConfigProvider::getInstance(); + $config->set('session.provider.name', 'Alpha\Util\Http\Session\SessionProviderArray'); + + $sequence = new Sequence(); + $sequence->rebuildTable(); + $sequence->set('prefix', 'TEST'); + $sequence->set('sequence', 1); + $sequence->save(); + } + + /** + * {@inheritDoc} + * + * @since 2.0 + */ + protected function tearDown() + { + $sequence = new Sequence(); + $sequence->dropTable(); + } + + /** + * Testing the listView() method + * + * @since 2.0 + */ + public function testListView() + { + $sequence = new Sequence(); + $sequence->load(1); + $view = View::getInstance($sequence); + + $this->assertNotEmpty($view->listView(array('URI' => '/')), 'Testing the listView() method'); + $this->assertTrue(strpos($view->listView(array('URI' => '/')),'TEST') !== false, 'Testing the listView() method'); + } +} + +?> \ No newline at end of file