/**
  * @depends icingaDatabaseAccessibleTest::testInsert
  * @group Database
  */
 public function testRoleAdd()
 {
     try {
         info("Testing actions for group modification\n");
         info("\tTesting icinga-web action: Creating groups\n");
         $context = AgaviContext::getInstance();
         $arguments = new AgaviRequestDataHolder();
         $role = $this->roleParams;
         foreach ($role as $name => $value) {
             $arguments->setParameter($name, $value);
         }
         // insert user
         $container = $context->getController()->createExecutionContainer("AppKit", "Admin.Groups.Edit", $arguments, "simple", "write");
         IcingaWebTestTool::assertInstanceOf("AgaviExecutionContainer", $container, "Couldn't create add-group action");
         $result = $container->execute();
         $this->assertNotEquals($result->getHttpStatusCode(), "404", "Action for adding groups not found");
         // Check if user is really added
         $result = Doctrine_Core::getTable("NsmRole")->findBy("role_name", $role["role_name"])->getFirst();
         IcingaWebTestTool::assertInstanceOf("NsmRole", $result, "No group found, something seemed to go wrong");
         success("\tCreating roles suceeded!\n");
         self::$idFixture = $result["role_id"];
         return true;
     } catch (Exception $e) {
         $this->fail("Adding a role failed!" . $e->getMessage());
     }
 }
Example #2
0
 /**
  * @group Bug
  */
 public function testBug()
 {
     $ctx = IcingaWebTestTool::getContext();
     $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), self::TEMPLATE, '.xml');
     $template = new CronkGridTemplateXmlParser($file->getRealPath(), $ctx);
     $template->parseTemplate();
     $worker = CronkGridTemplateWorkerFactory::createWorker($template, $ctx, self::CONNECTION);
     $this->assertGreaterThanOrEqual(0, $worker->countResults());
 }
Example #3
0
 public function testBug()
 {
     static $cronk_name = 'Bug3062Test_Cronk_Record';
     $ctx = IcingaWebTestTool::getContext();
     $model = $ctx->getModel('Provider.CronksData', 'Cronks');
     $testCronkData = array('cid' => $cronk_name, 'name' => $cronk_name, 'description' => $cronk_name, 'categories' => 'my', 'ae:parameter' => array('entity1' => 'd=1&d=2&d=3', 'entity2' => '<a></a>', 'entity3' => '"a", \'b\''));
     $record = $model->createCronkRecord($testCronkData);
     $this->assertInstanceOf('Cronk', $record);
     $this->assertEquals($cronk_name, $record->cronk_uid);
     $this->assertEquals($cronk_name, $record->cronk_name);
 }
 /**
  * @depends testLibs
  * @group Bootstrap
  **/
 public function testBootstrap()
 {
     $ctx = AgaviContext::getInstance('testing');
     IcingaWebTestTool::assertInstanceOf('AppKitAgaviContext', $ctx, "AgaviContext has wrong instance");
     IcingaWebTestTool::assertInstanceOf('AgaviDoctrineDatabase', $ctx->getDatabaseManager()->getDatabase());
     IcingaWebTestTool::assertInstanceOf('Doctrine_Manager', $ctx->getDatabaseManager()->getDatabase()->getDoctrineManager());
     try {
         $ctx->getDatabaseManager()->getDatabase()->connect();
     } catch (Doctrine_Connection_Exception $e) {
         $this->fail('No database connection');
     }
 }
 public function testUpdateCredentialPermission()
 {
     $model = new TestDataStoreModel();
     $e = null;
     try {
         $model->doUpdate("no data");
     } catch (DataStorePermissionException $p) {
         $e = $p;
     }
     IcingaWebTestTool::assertInstanceOf("DataStorePermissionException", $e, "Wrong or no exception thrown on disallowed write");
     $this->checkCalls($model, array(false, false, false, false), "disallowed update");
     $context = AgaviContext::getInstance();
     $context->getUser()->addCredential("testCredential");
     $model->doUpdate("no data");
     $this->checkCalls($model, array(false, false, true, false), "allowed update");
 }
 /**
  * Check if logs are writeable
  * @group Installation 
  */
 public function testLogDir()
 {
     info("\tTesting log write-access for web user\n");
     $root = AgaviConfig::get("core.root_dir");
     $logDir = $root . "/log";
     $wwwUser = IcingaWebTestTool::getProperty('www-user');
     $wwwGroup = IcingaWebTestTool::getProperty('www-group');
     $command = "touch " . $logDir . "/testfile.txt";
     if (!function_exists('posix_getuid') || posix_getuid() == 0) {
         $command = "su " . $wwwUser . " -c '" . $command . "'";
     }
     exec($command);
     if (!file_exists($logDir . "/testfile.txt")) {
         error("Web user " . $wwwUser . " couldn't create logfile in " . $logDir . "Please check that the either the user " . $wwwUser . " or the group " . $wwwGroup . " has " . "write access to this folder - otherwise icinga-web won't work\n");
         $this->fail("Couldn't write log files");
     } else {
         success("\tLog-directory is writeable for wwwGroup!\n");
     }
 }
 /**
  * @depends testShowLoginMask
  * @group Interface
  */
 public function testCorrectLogin()
 {
     info("\tTesting correct login\n");
     $root = AgaviConfig::get("core.root_dir");
     $params = new AgaviRequestDataHolder();
     $params->setParameters(array("dologin" => 1, "password" => IcingaWebTestTool::getProperty('testLogin-pass'), "username" => IcingaWebTestTool::getProperty('testLogin-name')));
     $ctx = AgaviContext::getInstance('web');
     $container = $ctx->getController()->createExecutionContainer("AppKit", "Login.AjaxLogin", $params, "json", "write");
     $json = null;
     try {
         $result = $container->execute();
         $json = json_decode($result->getContent(), true);
         if (!$json) {
             throw new Exception("Invalid result given " . $result->getContent());
         }
     } catch (Exception $e) {
         $this->fail("Login threw an exception " . $e->getMessage());
     }
     if (!$json["success"]) {
         $this->fail("Login failed with test credentials. Please check the credentials in test.properties");
     }
     success("\tLogin successful\n");
 }
 /**
  * @group Module
  */
 public function testModuleTranslations()
 {
     $ctx = IcingaWebTestTool::getContext();
     $tm = $ctx->getTranslationManager();
     $tm->setLocale('en');
     $this->assertEquals('en', $tm->getCurrentLocaleIdentifier());
     $this->assertEquals('test1-trans', $tm->_('test1', 'testdummy.text_simple'));
     $this->assertEquals('test2-trans', $tm->_('test2', 'testdummy.text_simple'));
     $this->assertEquals(date('Y'), $tm->_d(date('Y-m-d H:i:s'), 'testdummy.date_year'));
     $this->assertEquals(date('m'), $tm->_d(date('Y-m-d H:i:s'), 'testdummy.date_month'));
 }
Example #9
0
 /**
  * Starts an agavi context for testing purposes. This was bundled into the
  * test bootstrap method to call this only once
  * @param string $env	Name of the context
  * @return AgaviContext	The created context
  */
 public function bootstrapAgavi($env = 'testing', array $modules = array())
 {
     require IcingaWebTestTool::getRootPath() . '/lib/agavi/src/agavi.php';
     AgaviConfig::set('core.testing_dir', IcingaWebTestTool::getTestPath());
     AgaviConfig::set('core.app_dir', IcingaWebTestTool::getRootPath() . DIRECTORY_SEPARATOR . 'app');
     AgaviConfig::set('core.root_dir', IcingaWebTestTool::getRootPath());
     Agavi::bootstrap($env);
     AgaviConfig::set('core.default_context', $env);
     AppKitAgaviUtil::initializeModule('AppKit');
     AppKitAgaviUtil::initializeModule('Api');
     foreach ($modules as $module) {
         AppKitAgaviUtil::initializeModule($module);
     }
     AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext');
     return AgaviContext::getInstance($env);
 }
 /**
  * @depends testUserPreferenceAdd
  * @group Database
  */
 public function testUserPreferenceRemove()
 {
     try {
         $userid = self::$idFixture;
         info("\tTesting icinga-web action: Remove user preference\n");
         $context = AgaviContext::getInstance();
         $preferenceData = new AgaviRequestDataHolder();
         $preferenceData->setParameters(array("remove" => "true", "isLong" => "false", "upref_key" => "TEST", "upref_val" => "TESTCASE"));
         $modifyAction = $context->getController()->createExecutionContainer("AppKit", "User.Preferences", $preferenceData, "simple", "write");
         IcingaWebTestTool::assertInstanceOf("AgaviExecutionContainer", $modifyAction, "Couldn't create add-preference action");
         $result = $modifyAction->execute();
         $this->assertNotEquals($result->getHttpStatusCode(), "404", "Action for eediting user preferences not found");
         success("\tDeleting preferences suceeded!\n");
         return true;
     } catch (Exception $e) {
         $this->fail("Removing an user preference failed!" . $e->getMessage());
     }
 }
 /**
  * @group CronkCategory
  * @expectedException AppKitModelException
  * @expectedExceptionMessage Category not found: phpunit_test_123123
  */
 public function testCategoryCreation()
 {
     $ctx = IcingaWebTestTool::getContext();
     IcingaWebTestTool::authenticateTestUser();
     $catid = 'phpunit_test_123123';
     $catmodel = $ctx->getModel('Provider.CronkCategoryData', 'Cronks');
     $catmodel->createCategory(array('catid' => $catid, 'title' => 'PHPUNIT test category', 'visible' => true, 'position' => '123443'));
     $test_cat = $catmodel->getCategory($catid);
     $this->assertEquals('123443', $test_cat['position']);
     $catmodel->deleteCategoryRecord($catid);
     // Throw at least
     $test_cat = $catmodel->getCategory($catid);
 }