[icinga-checkins] icinga.org: icinga-web/next: Adapt test to match cronk cache setting

git at icinga.org git at icinga.org
Mon May 6 17:15:00 CEST 2013


Module: icinga-web
Branch: next
Commit: 619d5eb07893f2d7d04fcabf41a7d6f2463aa806
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=619d5eb07893f2d7d04fcabf41a7d6f2463aa806

Author: Marius Hein <marius.hein at netways.de>
Date:   Mon Jan 14 12:41:08 2013 +0100

Adapt test to match cronk cache setting

Conflicts:

	etc/conf.d/module_appkit.xml

---

 .../models/Provider/CronksDataModel.class.php      |   13 ++++--
 etc/conf.d/module_appkit.xml                       |    3 +-
 tests/phpunit/tests/module/ModuleLoadingTest.php   |   50 +++++++++++++-------
 3 files changed, 43 insertions(+), 23 deletions(-)

diff --git a/app/modules/Cronks/models/Provider/CronksDataModel.class.php b/app/modules/Cronks/models/Provider/CronksDataModel.class.php
index 847bbf3..e431e9f 100644
--- a/app/modules/Cronks/models/Provider/CronksDataModel.class.php
+++ b/app/modules/Cronks/models/Provider/CronksDataModel.class.php
@@ -101,7 +101,9 @@ class Cronks_Provider_CronksDataModel extends CronksBaseModel implements AgaviIS
         
         $this->initializeXmlData();
 
-        $this->cronks = $this->getCronks(true);
+        if (!isset($parameters['lazy'])) {
+            $this->cronks = $this->getCronks(true);
+        }
 
     }
     
@@ -226,8 +228,11 @@ class Cronks_Provider_CronksDataModel extends CronksBaseModel implements AgaviIS
      */
     private function getXmlCronks($all=false) {
         $cached = $this->user->getStorage()->read("icinga.cronks.cache.xml");
-        if($cached)
+
+        if($cached) {
             return $cached;
+        }
+
         $out = array();
         foreach(self::$xml_cronk_data as $uid=>$cronk) {
             
@@ -259,7 +264,7 @@ class Cronks_Provider_CronksDataModel extends CronksBaseModel implements AgaviIS
                 $this->getContext()->getLoggerManager()->log('No action or module for cronk: '. $uid, AgaviLogger::ERROR);
                 continue;
             }
-            
+
             $out[$uid] = array(
                 'cronkid' => $uid,
                 'module' => $cronk['module'],
@@ -682,7 +687,7 @@ class Cronks_Provider_CronksDataModel extends CronksBaseModel implements AgaviIS
         $cronks_out = array();
         
         $categories = $this->getCategoryModel()->getCategories();
-        
+
         $cronks = $this->getCronks();
 
         foreach($categories as $category_name=>$category) {
diff --git a/etc/conf.d/module_appkit.xml b/etc/conf.d/module_appkit.xml
index 6aeddc9..4317fc6 100644
--- a/etc/conf.d/module_appkit.xml
+++ b/etc/conf.d/module_appkit.xml
@@ -10,9 +10,10 @@
             
                 <setting name="debug.verbose">
                     <!--  Debug output for db queries -->
-                    <!-- 
+                    <!--
 		    <ae:parameter>API_Views_ApiDQLViewModel</ae:parameter>
                     -->
+
                     <!-- 
 		    <ae:parameter>Api_Store_LegacyLayer_IcingaApiModel</ae:parameter>
                     -->
diff --git a/tests/phpunit/tests/module/ModuleLoadingTest.php b/tests/phpunit/tests/module/ModuleLoadingTest.php
index 362f370..f5991fc 100644
--- a/tests/phpunit/tests/module/ModuleLoadingTest.php
+++ b/tests/phpunit/tests/module/ModuleLoadingTest.php
@@ -3,7 +3,7 @@
 class ModuleLoadingTest extends PHPUnit_Framework_TestCase {
     
     const MODULE_NAME = 'TestDummy';
-    
+
     /**
      * @group Module 
      */
@@ -63,23 +63,26 @@ class ModuleLoadingTest extends PHPUnit_Framework_TestCase {
         $resource = $database->getConnection();
     }
     
-    /**

-     * @group Module

-     */

+    /**
+     * @group Module
+     */
     public function testCronkSecurityModel() {
         
         // Name of a system cronk
         static $cronk_name = 'gridInstanceStatus';
         
-        // Test init

-        IcingaWebTestTool::authenticateTestUser();

+        // Test init
+        IcingaWebTestTool::authenticateTestUser();
+
+        // Drop cache
+        unset($_SESSION["icinga.cronks.cache.xml"]);
         
-        // Initialize

-        $ctx = IcingaWebTestTool::getContext();

-        $cronks = $ctx->getModel('Provider.CronksData', 'Cronks');

-        $security = $ctx->getModel('Provider.CronksSecurity', 'Cronks');

+        // Initialize
+        $ctx = IcingaWebTestTool::getContext();
+        $cronks = $ctx->getModel('Provider.CronksData', 'Cronks');
+        $security = $ctx->getModel('Provider.CronksSecurity', 'Cronks');
 
-        // 1. Reset, test for empty groups

+        // 1. Reset, test for empty groups
         $security->setCronkUid($cronk_name);
         $cronk = $security->getCronk();
         
@@ -96,7 +99,7 @@ class ModuleLoadingTest extends PHPUnit_Framework_TestCase {
         $this->assertEquals('appkit_admin', $roles[0]['role_name']);
         $this->assertEquals('icinga_user', $roles[1]['role_name']);
         
-        $this->assertContains('appkit_admin', $security->getRoleNames());

+        $this->assertContains('appkit_admin', $security->getRoleNames());
         $this->assertContains('icinga_user', $security->getRoleNames());
 
         // Test role_ids
@@ -104,15 +107,15 @@ class ModuleLoadingTest extends PHPUnit_Framework_TestCase {
         $this->assertContains(3, $security->getRoleUids());
         
         // Test principal_ids
-        $this->assertContains(3, $security->getPrincipals());

+        $this->assertContains(3, $security->getPrincipals());
         $this->assertContains(4, $security->getPrincipals());
 
         // 3. Reset, remove roles and test again
         $security->updateRoles(array());
         $security->setCronkUid($cronk_name);
-        $roles = $security->getRoles();

+        $roles = $security->getRoles();
         
-        $this->assertNull($roles);

+        $this->assertNull($roles);
     }
     
     /**
@@ -123,7 +126,10 @@ class ModuleLoadingTest extends PHPUnit_Framework_TestCase {
         IcingaWebTestTool::authenticateTestUser();
         
         $ctx = IcingaWebTestTool::getContext();
-        
+
+        // Drop cache
+        unset($_SESSION["icinga.cronks.cache.xml"]);
+
         $cronk_model = $ctx->getModel('Provider.CronksData', 'Cronks');
         
         $this->assertTrue($cronk_model->hasCronk('dummyTestCronk1'));
@@ -154,12 +160,17 @@ class ModuleLoadingTest extends PHPUnit_Framework_TestCase {
     public function testModuleCategories() {
         
         IcingaWebTestTool::authenticateTestUser();
+
+        // Drop cache
+        unset($_SESSION["icinga.cronks.cache.xml"]);
         
         $ctx = IcingaWebTestTool::getContext();
         
         $ctx->getUser()->removeCredential('icinga.cronk.admin');
         
-        $cronk_model = $ctx->getModel('Provider.CronksData', 'Cronks');
+        $cronk_model = $ctx->getModel('Provider.CronksData', 'Cronks', array(
+            'lazy' => true
+        ));
         
         $data = $cronk_model->combinedData();
         
@@ -173,7 +184,7 @@ class ModuleLoadingTest extends PHPUnit_Framework_TestCase {
         $this->assertArrayHasKey('rows', $jarray);
         $this->assertArrayHasKey('success', $jarray);
         $this->assertArrayHasKey('total', $jarray);
-        
+
         $this->assertEquals(1, count($jarray['rows']));
         
     //    $this->assertInternalType('array', $data['categories']);
@@ -189,6 +200,9 @@ class ModuleLoadingTest extends PHPUnit_Framework_TestCase {
         $ctx = IcingaWebTestTool::getContext();
         
         $ctx->getUser()->removeCredential('icinga.cronk.admin');
+
+        // Drop cache
+        unset($_SESSION["icinga.cronks.cache.xml"]);
         
         $cronk_model = $ctx->getModel('Provider.CronksData', 'Cronks');
         





More information about the icinga-checkins mailing list