aboutsummaryrefslogtreecommitdiff
path: root/mod/landing/test/landing_test.php
blob: 24264e9388a2c26a7e555b1f1a2d659b12baaa30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
 * Elgg Landing Test
 *
 * @package ElggLanding
 * @subpackage Test
 */
class ElggLandingTest extends ElggCoreUnitTest {

	/**
	 * Called before each test object.
	 */
	public function __construct() {
		parent::__construct();
		
		// all __construct() code should come after here
		$user = new ElggUser();
		$user->username       = 'test_astronaut';
		$user->email          = 'astronaut@example.net';
		$user->name           = 'Astronaut Landing';
		$user->access_id      = ACCESS_PUBLIC;
		$user->salt           = generate_random_cleartext_password();
		$user->password       = generate_user_password($user, 'foo.bar.baz');
		$user->owner_guid     = 0;
		$user->container_guid = 0;
		$user->save();

		$this->user = $user;
	}

	/**
	 * Called before each test method.
	 */
	public function setUp() {
		$this->user->landing_mode = NULL;
		$this->user->landing_url  = NULL;
		$this->user->save();
	}

	/**
	 * Called after each test method.
	 */
	public function tearDown() {
		// do not allow SimpleTest to interpret Elgg notices as exceptions
		$this->swallowErrors();
		logout($this->user);
	}

	/**
	 * Called after each test object.
	 */
	public function __destruct() {
		$this->user->delete();
		// all __destruct() code should go above here
		parent::__destruct();
	}

	/**
     * User must be able to login
	 */
	public function testUserCanLogin() {
		$this->assertTrue(login($this->user->username, 'foo.bar.baz'));
	}		

    /**
     * The landing plugin requires that $forward_url is declared
	 * global in actions/login.php
	 */
	public function testGlobalForwardURL() {
		//		require elgg_get_config('path') . 'actions/login.php';
		login($this->user->username, 'foo.bar.baz');
		$this->assertTrue(in_array('forward_url', array_keys($GLOBALS), TRUE));
	}

	public function testLandingToDefault() {
		set_plugin_usersetting('landing_mode', 'default', $this->user->guid, 'landing');
		$this->assertEqual('default', $this->user->landing_mode);
		login($this->user->username, 'foo.bar.baz');
		$this->assertEqual('', $forward_url);
	}

	public function testLandingToProfile() {
		set_plugin_usersetting('landing_mode', 'profile', $this->user->guid, 'landing');
		$this->assertEqual('profile', $this->user->landing_mode);
		login($this->user->username, 'foo.bar.baz');
		if (elgg_is_active_plugin('profile')) {
			$this->assertEqual("/profile/{$this->user->username}", $forward_url);
		} else {
			$this->assertEqual("/view/{$this->user->guid}", $forward_url);
		}
	}

	public function testLandingToDashboard() {
		if (elgg_is_active_plugin('dashboard')) {
			set_plugin_usersetting('landing_mode', 'dashboard', $this->user->guid, 'landing');
			$this->assertEqual('dashboard', $this->user->landing_mode);
			login($this->user->username, 'foo.bar.baz');
			$this->assertEqual('/dashboard', $forward_url);
		}
	}

	public function testLandingToCustomPage() {
		set_plugin_usersetting('landing_mode', 'custom', $this->user->guid, 'landing');
		set_plugin_usersetting('landing_url', '/some/existing/page', $this->user->guid, 'landing');
		$this->assertEqual('custom', $this->user->landing_mode);
		login($this->user->username, 'foo.bar.baz');
		$this->assertEqual('/some/existing/page', $forward_url);
	}

	public function testLandingToNonExistentCustomPage() {
		set_plugin_usersetting('landing_mode', 'custom', $this->user->guid, 'landing');
		$this->assertEqual('custom', $this->user->landing_mode);
		login($this->user->username, 'foo.bar.baz');
		$this->assertEqual(-1, $forward_url); // -1 means REFERRER
	}

}