Skip to content

Commit

Permalink
Merge pull request #3741 from Spuds/Working
Browse files Browse the repository at this point in the history
test package install
  • Loading branch information
Spuds authored Jan 28, 2024
2 parents f220216 + 4d82cbe commit a0df93e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
4 changes: 1 addition & 3 deletions sources/ElkArte/Packages/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ public function action_install2()
// Installing in themes will require some help
require_once(SUBSDIR . '/Themes.subs.php');

// @todo Perhaps do it in steps, if necessary?
$this->_uninstalling = $this->_req->query->sa === 'uninstall2';

// Load up the package FTP information?
Expand Down Expand Up @@ -619,7 +618,6 @@ public function action_install2()
{
$_SESSION['last_backup_for'] = $this->_filename . ($this->_uninstalling ? '$$' : '$');

// @todo Internationalize this?
package_create_backup(($this->_uninstalling ? 'backup_' : 'before_') . strtok($this->_filename, '.'));
}

Expand Down Expand Up @@ -709,7 +707,7 @@ public function action_install2()
{
$tables[] = $log[1];
}
elseif (in_array($log[1], $tables))
elseif (in_array($log[1], $tables, true))
{
unset($db_package_log[$k]);
}
Expand Down
76 changes: 76 additions & 0 deletions tests/sources/admin/PackagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,80 @@ public function testActionInstall()
$this->assertFalse($context['is_installed']);
$this->assertEquals('<strong>Test successful</strong>', $context['actions'][7]['description'], $context['actions'][7]['description']);
}

public function testActionInstall2()
{
global $context;

$req = HttpReq::instance();
$req->query->ve = '1.1';
$req->query->package = 'elk_ResizeAttachedImages.zip';
$req->query->sa = 'install2';
$req->query->area = 'packages';

// Stupid package subs still uses the super global directly
$_REQUEST['ve'] = '1.1';
$_REQUEST['package'] = 'elk_ResizeAttachedImages.zip';

// Get the controller, call index
$controller = new Packages(new EventManager());
$controller->setUser(User::$info);
$controller->pre_dispatch();
$controller->action_index();
$req->query->sa = null;
$req->query->area = null;

$this->assertTrue($context['install_finished']);
}

public function testActionUninstall()
{
global $context;

$req = HttpReq::instance();
$req->query->ve = '1.1';
$req->query->package = 'elk_ResizeAttachedImages.zip';
$req->query->sa = 'uninstall';
$req->query->area = 'packages';

// Stupid package subs still uses the super global directly
$_REQUEST['ve'] = '1.1';
$_REQUEST['package'] = 'elk_ResizeAttachedImages.zip';

// Get the controller, call index
$controller = new Packages(new EventManager());
$controller->setUser(User::$info);
$controller->pre_dispatch();
$controller->action_index();
$req->query->sa = null;
$req->query->area = null;

$this->assertTrue($context['uninstalling']);
}

public function testActionUninstall2()
{
global $context;

$req = HttpReq::instance();
$req->query->ve = '1.1';
$req->query->package = 'elk_ResizeAttachedImages.zip';
$req->query->sa = 'uninstall2';
$req->query->area = 'packages';
$req->post->do_db_changes = 1;

// Stupid package subs still uses the super global directly
$_REQUEST['ve'] = '1.1';
$_REQUEST['package'] = 'elk_ResizeAttachedImages.zip';

// Get the controller, call index
$controller = new Packages(new EventManager());
$controller->setUser(User::$info);
$controller->pre_dispatch();
$controller->action_index();
$req->query->sa = null;
$req->query->area = null;

$this->assertFalse($context['is_installed']);
}
}

0 comments on commit a0df93e

Please sign in to comment.