function test_accessible_by_ids_no_ids()
 {
     $this->_login_user(200, array(100 => 'admins', 110 => 'users'));
     debug_mock::expect_write_error('ids array is empty');
     $result = $this->object->fetch_accessible_by_ids(array());
     $this->assertEqual($result, array());
 }
 function _move_tree_across($branches, $mvt, $nodecount)
 {
     foreach ($branches[0] as $nodeid => $node) {
         foreach ($branches[1] as $tnodeid => $tnode) {
             if ($nodeid == $tnodeid) {
                 debug_mock::expect_write_error(NESE_ERROR_RECURSION, array('id' => $nodeid, 'target_id' => $tnodeid));
             } else {
                 $current_source = $this->_tree->get_node($nodeid);
                 $current_target = $this->_tree->get_node($tnodeid);
                 if ($current_target['root_id'] == $current_source['root_id'] && ($current_source['l'] <= $current_target['l'] && $current_source['r'] >= $current_target['r'])) {
                     debug_mock::expect_write_error(NESE_ERROR_RECURSION, array('id' => $nodeid, 'target_id' => $tnodeid));
                 }
             }
             if (($ret = $this->_tree->move_tree($nodeid, $tnodeid, $mvt)) === false) {
                 continue;
             }
             $mnode = $this->_tree->get_node($ret);
             $this->assertEqual($ret, $nodeid, 'Nodeid was not returned as expected');
             $this->assertEqual($nodecount, count($this->_tree->get_all_nodes()), 'Node count changed');
             $p = $this->_tree->get_parent($nodeid);
             if ($mvt == NESE_MOVE_BELOW) {
                 $this->assertEqual($tnode['id'], $p['id'], 'Move below failed (parent ID)');
             }
             if ($mnode['id'] != $mnode['root_id']) {
                 $this->assertEqual($p['id'], $mnode['parent_id'], 'Parent ID is wrong');
             }
         }
     }
 }
 function test_create_no_such_action()
 {
 	debug_mock :: expect_write_error('action not found', array('class_path' => 'no_such_action'));
 	
 	$c =& action_factory :: create('no_such_action');
 	
 	$this->assertIsA($c, 'empty_action'); 
 }
 function test_create()
 {
     $c =& action_factory::create('action');
     $this->assertNotNull($c);
     debug_mock::expect_write_error('action not found', array('class_path' => 'no_such_action'));
     $c =& action_factory::create('no_such_action');
     $this->assertNull($c);
 }
 function test_save_object_access_wrong_action_no_parent_records()
 {
     $this->object->setReturnValue('get_id', -1);
     $this->parent_object->setReturnValue('get_id', -2);
     $this->parent_object->setReturnValue('get_class_id', 10);
     $this->parent_object_controller->setReturnValue('determine_action', 'display');
     debug_mock::expect_write_error('parent object has no acccess records at all', array('parent_id' => -2));
     $this->assertFalse($this->ac->save_object_access($this->object, $this->parent_object));
 }
 function test_failed_create()
 {
     debug_mock::expect_write_error('identifier is empty');
     $this->assertIdentical($this->object->create(), false);
     $this->object->set_parent_node_id(10);
     debug_mock::expect_write_error('identifier is empty');
     $this->assertIdentical($this->object->create(), false);
     $this->object->set_identifier('test');
     debug_mock::expect_write_error('tree registering failed', array('parent_node_id' => 10));
     $this->assertIdentical($this->object->create(), false);
 }
 function test_failed_create()
 {
     if (!$this->object->is_auto_identifier()) {
         debug_mock::expect_write_error('identifier is empty');
         $this->assertIdentical($this->object->create(), false);
     }
     $this->object->set_parent_node_id(1000000);
     if (!$this->object->is_auto_identifier()) {
         debug_mock::expect_write_error('identifier is empty');
         $this->assertIdentical($this->object->create(), false);
     }
     $this->object->set_identifier('test');
     if ($this->object->is_auto_identifier()) {
         debug_mock::expect_write_error(NESE_ERROR_NOT_FOUND, array('id' => 1000000));
     } else {
         debug_mock::expect_write_error('tree registering failed', array('parent_node_id' => 1000000));
     }
     $this->assertIdentical($this->object->create(), false);
 }
 function test_move_tree()
 {
     $movemodes[] = NESE_MOVE_BEFORE;
     $movemodes[] = NESE_MOVE_AFTER;
     $movemodes[] = NESE_MOVE_BELOW;
     for ($j = 0; $j < count($movemodes); $j++) {
         $mvt = $movemodes[$j];
         // Build a nice random tree
         $rnc = 1;
         $depth = 2;
         $npl = 2;
         $relation_tree = $this->_create_sub_node($rnc, $depth, $npl);
         $lastrid = false;
         $rootnodes = $this->_tree->get_root_nodes();
         $branches = array();
         $allnodes1 = $this->_tree->get_all_nodes();
         foreach ($rootnodes as $rid => $rootnode) {
             if ($lastrid) {
                 if ($rid == $lastrid) {
                     debug_mock::expect_write_error(NESE_ERROR_RECURSION);
                 }
                 $this->_tree->move_tree($rid, $lastrid, $mvt);
             }
             $branch = $this->_tree->get_branch($rid);
             if (!empty($branch)) {
                 $branches[] = $branch;
             }
             if (count($branches) == 2) {
                 $this->_move_tree_across($branches, $mvt, count($this->_tree->get_all_nodes()));
                 $branches = array();
             }
             $lastrid = $rid;
         }
         $allnodes2 = $this->_tree->get_all_nodes();
         // Just make sure that all the nodes are still there
         $this->assertFalse(count(array_diff(array_keys($allnodes1), array_keys($allnodes2))), 'Nodes got lost during the move');
     }
     return true;
 }
 function test_update_file()
 {
     $this->test_create_file();
     $obj =& site_object_factory::create('file_object');
     $this->db->sql_select('media');
     $row = $this->db->fetch_row();
     $obj->set_attribute('tmp_file_path', PROJECT_DIR . 'images/2.jpg');
     $obj->set_attribute('file_name', 'new_name.jpg');
     $obj->set_attribute('mime_type', 'image/jpeg');
     debug_mock::expect_write_error('media id not set');
     $this->assertFalse($obj->update_file(), __LINE__);
     $obj->set_attribute('media_id', $row['id']);
     $this->assertTrue($obj->update_file(), __LINE__);
     $this->db->sql_select('media');
     $arr = $this->db->get_array();
     $media_id = $obj->get_attribute('media_id');
     $this->assertTrue(is_array($arr), __LINE__);
     $this->assertEqual(sizeof($arr), 1, __LINE__);
     $this->assertEqual($arr[0]['id'], $media_id, __LINE__);
     $this->assertEqual($arr[0]['file_name'], $obj->get_attribute('file_name'), __LINE__);
     $this->assertEqual($arr[0]['mime_type'], $obj->get_attribute('mime_type'), __LINE__);
     $this->assertTrue(file_exists(MEDIA_DIR . $media_id . '.media'), __LINE__);
     $this->assertEqual(filesize(MEDIA_DIR . $media_id . '.media'), filesize($obj->get_attribute('tmp_file_path')), __LINE__);
 }
  function test_get_wrong_type_value()
  {
    $sp =& sys_param :: instance();

    debug_mock :: expect_write_error(
      'trying to get undefined type in sys_param',
      array (
        'type' => 'blabla',
        'param' => 'param_1',
      )
    );

    $number = 123.053;
    $sp->save_param('param_1', 'float', $number);

    $this->assertNull($sp->get_param('param_1', 'blabla'));
    $this->assertNull($sp->get_param('param_2'));
  }
  function test_failed_create()
  {
    if(!$this->object->is_auto_identifier())
    {
      debug_mock :: expect_write_error('identifier is empty');

      $this->assertIdentical($this->object->create(), false, 'shouldn\'t be created, since identifier is not set');
    }

    $this->object->set_parent_node_id(1000000);

    if(!$this->object->is_auto_identifier())
    {
      debug_mock :: expect_write_error('identifier is empty');

      $this->assertIdentical($this->object->create(), false, 'shouldn\'t be created, since identifier is not set');
    }

    $this->object->set_identifier('test');

    if($this->object->is_auto_identifier())
      debug_mock :: expect_write_error(TREE_ERROR_NODE_NOT_FOUND, array('id' => 1000000));
    else
      debug_mock :: expect_write_error('tree registering failed', array('parent_node_id' => 1000000));

    $this->assertIdentical($this->object->create(), false, 'shouldn\'t be created, since parent node is not valid');
  }
  function test_display_empty_view()
  { 
  	$this->request->setReturnValue('get_attribute', 'no_such_action', array('action'));
  	
  	debug_mock :: expect_write_warning('action not found', 
  		array (
					  'class' => 'site_object_controller_test_version1',
					  'action' => 'no_such_action',
					  'default_action' => 'display',
					)
		);

  	$this->assertIdentical($this->site_object_controller->determine_action($this->request), false);

		debug_mock :: expect_write_error('template is null');
		
  	$this->site_object_controller->display_view();  	
  }  
 function test_perform_with_name()
 {
     $_REQUEST['test1']['username'] = '******';
     $_REQUEST['test1']['password'] = '******';
     $_REQUEST['test1']['password_confirm'] = 'yo';
     $a1 =& new form_action1('test1');
     $this->assertIsA($a1->perform(), 'failed_response');
     $_REQUEST['test1']['submitted'] = true;
     debug_mock::expect_write_error('validation failed');
     $this->assertIsA($a1->perform(), 'not_valid_response');
     $_REQUEST['test1']['password'] = '******';
     $_REQUEST['test1']['password_confirm'] = 'yoyoyoyo';
     debug_mock::expect_write_error('validation failed');
     $this->assertIsA($a1->perform(), 'not_valid_response', 'validation occurs only once');
     $a2 =& new form_action1('test1');
     $this->assertIsA($a2->perform(), 'response');
 }
 function test_display_empty_view()
 {
     $_REQUEST['action'] = 'no_such_action';
     debug_mock::expect_write_warning('action not found', array('class' => 'site_object_controller_test_version1', 'action' => 'no_such_action', 'default_action' => 'display'));
     $this->assertIdentical($this->site_object_controller->determine_action(), false);
     debug_mock::expect_write_error('template is null');
     $this->site_object_controller->display_view();
 }
 function test_get_sub_branch_by_path_failed()
 {
   debug_mock :: expect_write_error(TREE_ERROR_NODE_NOT_FOUND,  array('id' => 1));
   $this->assertFalse($this->driver->get_sub_branch(1));
 }
 function test_change_order()
 {
     $rnc = 2;
     $depth = 2;
     $npl = 3;
     // Create a new tree
     $relation_tree = $this->_create_sub_node($rnc, $depth, $npl);
     debug_mock::expect_write_error('node not found', array('node_id' => 0));
     $this->assertFalse($this->_tree->change_node_order(0, 'up'));
     $this->assertFalse($this->_tree->change_node_order(1, 'up'));
     $this->assertFalse($this->_tree->change_node_order(1, 'down'));
     foreach (array_keys($relation_tree) as $id) {
         if (isset($relation_tree[$id]['children'])) {
             foreach ($relation_tree[$id]['children'] as $child_id) {
                 $children_before = $this->_tree->get_children($id);
                 $direction = mt_rand(0, 1) ? 'up' : 'down';
                 $result = $this->_tree->change_node_order($child_id, $direction);
                 $children_after = $this->_tree->get_children($id);
                 $pos_before = array_search($child_id, array_keys($children_before));
                 $pos_after = array_search($child_id, array_keys($children_after));
                 if ($direction == 'up') {
                     if ($pos_before == 0) {
                         $this->assertFalse($result);
                     } else {
                         $this->assertTrue($result);
                         $this->assertEqual($pos_after - $pos_before, -1);
                     }
                 } elseif ($direction == 'down') {
                     if ($pos_before == sizeof($children_before) - 1) {
                         $this->assertFalse($result);
                     } else {
                         $this->assertTrue($result);
                         $this->assertEqual($pos_after - $pos_before, 1);
                     }
                 }
             }
         }
     }
 }
 function test_perform_with_name_validation_fails()
 {
     $_REQUEST['test1']['username'] = '******';
     $_REQUEST['test1']['password'] = '******';
     $_REQUEST['test1']['password_confirm'] = 'yo';
     $this->form_action->setReturnValue('_define_dataspace_name', 'test1');
     $this->form_action->form_action();
     $this->assertIsA($this->form_action->perform(), 'failed_response');
     $_REQUEST['test1']['submitted'] = true;
     debug_mock::expect_write_error('validation failed');
     $this->assertIsA($this->form_action->perform(), 'not_valid_response');
 }
 function test_fetch_by_ids_no_ids()
 {
     debug_mock::expect_write_error('ids array is empty');
     $result = $this->object->fetch_by_ids(array());
     $this->assertEqual($result, array());
 }
  function test_update_node()
  {
    $node_id = $this->imp->create_root_node(array('identifier' => 'root', 'object_id' => 10));

    $node = array(
      'identifier' => 'test',
      'object_id' => 100,
      'id' => 12,
      'path' => '/0/',
      'root_id' => 0,
      'level' => 23,
      'parent_id' => 1000,
      'children' => 1000
    );

    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'id'));
    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'path'));
    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'root_id'));
    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'level'));
    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'children'));

    $this->assertTrue($this->imp->update_node($node_id, $node));

    $updated_node = $this->imp->get_node($node_id);

    $this->assertEqual($updated_node['object_id'], 100, 'invalid parameter: object_id');
    $this->assertEqual($updated_node['identifier'], 'test', 'invalid parameter: identifier');
    $this->assertNotEqual($updated_node, $node, 'invalid update');
  }
 function test_failed_update_file()
 {
     debug_mock::expect_write_error('media id not set');
     $this->_set_file_update_attributes();
     $this->assertFalse($this->object->update_file());
 }
 function test_failed_change_own_password_no_user_node_id()
 {
     debug_mock::expect_write_error('user not logged in - node id is not set');
     $this->assertFalse($this->object->change_own_password('changed_password'));
 }