From 279e74d06be7e2fc98c3df3cd867d1ecfd3e6de4 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 14:49:36 -0300 Subject: Squashed 'mod/landing/' content from commit d1ea0d2 git-subtree-dir: mod/landing git-subtree-split: d1ea0d2593cbf55a3804224fd587dbde00672a8c --- test/landing_test.php | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 test/landing_test.php (limited to 'test/landing_test.php') diff --git a/test/landing_test.php b/test/landing_test.php new file mode 100644 index 000000000..24264e938 --- /dev/null +++ b/test/landing_test.php @@ -0,0 +1,117 @@ +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 + } + +} -- cgit v1.2.3