aboutsummaryrefslogtreecommitdiff
path: root/mod/landing/test/landing_test.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/landing/test/landing_test.php')
-rw-r--r--mod/landing/test/landing_test.php117
1 files changed, 117 insertions, 0 deletions
diff --git a/mod/landing/test/landing_test.php b/mod/landing/test/landing_test.php
new file mode 100644
index 000000000..24264e938
--- /dev/null
+++ b/mod/landing/test/landing_test.php
@@ -0,0 +1,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
+ }
+
+}