Ejemplo n.º 1
0
 /**
  * @depends testReadState
  * @group Database
  */
 public function testSaveState()
 {
     info("\tTesting state-save\n");
     $token = str_shuffle("ABCDEF123456789");
     $params = array("cmd" => "write", "data" => '[{"name":"test-case-setting","value":"TEST_CASE_' . $token . '"}]', "id" => 1, "session" => "session", "user" => "user");
     $paramHolder = new AgaviRequestDataHolder();
     $paramHolder->setParameters($params);
     $controller = AgaviContext::getInstance()->getController();
     $container = $controller->createExecutionContainer("AppKit", "Ext.ApplicationState", $paramHolder, "javascript", "write");
     try {
         $result = $container->execute();
         $data = json_decode($result->getContent(), true);
     } catch (Exception $e) {
         $this->fail("An exception was thrown during state write: " . $e->getMessage());
     }
     // Check for success state
     if (@(!$data["success"])) {
         $this->fail("Could not write view state! Your cronk settings may not be saved in icinga-web.");
     }
     // Finally get sure the enry is really set
     $entryFound = false;
     foreach ($data["data"] as $entry) {
         if ($entry["name"] == 'test-case-setting' && $entry["value"] == 'TEST_CASE_' . $token) {
             $entryFound = true;
         }
     }
     if (!$entryFound) {
         $this->fail("Write returned success, but preference could not be found in DB!\n");
     }
     success("\tWriting state succeeded!\n");
 }
Ejemplo n.º 2
0
 /**
  * @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");
 }
 /**
  * @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());
     }
 }