/**
  * Tests the Bluebox_Installer::listPackages() function, and its return
  * NOTE: BY DESIGN THIS FAILS IF THERE IS AN IMPROPER CONFIGURE.PHP IN THE MODULES!
  *
  * @group core.libraries.installer.listPackages
  * @test
  */
 public function testListPackages()
 {
     $packages = Bluebox_Installer::listPackages();
     foreach ($packages as $package) {
         // Sanity check on meta data
         $this->assertEquals(true, isset($package['version']));
         $this->assertEquals(true, is_string($package['packageName']));
         $this->assertEquals(true, is_string($package['displayName']));
         $this->assertEquals(true, is_string($package['author']));
         $this->assertEquals(true, is_string($package['vendor']));
         $this->assertEquals(true, is_string($package['license']));
         $this->assertEquals(true, is_string($package['summary']));
         $this->assertEquals(true, is_string($package['description']));
         $this->assertEquals(true, is_bool($package['default']));
         $this->assertEquals(true, is_bool($package['canBeDisabled']));
         $this->assertEquals(true, is_bool($package['canBeRemoved']));
         // Ensure that categories is as expected
         $this->assertEquals(true, isset($package['type']));
         // Ensure required is set
         $this->assertEquals(true, isset($package['required']));
         // Make sure that we worked out a valid directory
         $this->assertEquals(true, is_dir(MODPATH . $package['directory']));
         // Ensure that the configure class is valid
         $this->assertEquals(true, class_exists($package['configureClass']));
         // Ensure that the models is an array empty or otherwise
         $this->assertEquals(true, is_array($package['models']));
         // Ensure that if this is installed it returns all the proper rows
         if (!is_bool($package['installedAs'])) {
             $installedAs = $package['installedAs'];
             $this->assertEquals(true, is_numeric($installedAs['module_id']));
             $this->assertEquals(true, is_string($installedAs['name']));
             $this->assertEquals(true, is_string($installedAs['display_name']));
             $this->assertEquals(true, isset($installedAs['module_version']));
             $this->assertEquals(true, is_bool($installedAs['enabled']));
             $this->assertEquals(true, is_bool($installedAs['default']));
             $this->assertEquals(true, is_string($installedAs['basedir']));
         } else {
             $this->assertEquals(false, $package['installedAs']);
         }
         // Ensure this is a valid action
         if (!is_bool($package['action'])) {
             $this->assertEquals(true, in_array($package['action'], $this->validActions));
         } else {
             $this->assertEquals(false, $package['action']);
         }
     }
     // This ensures that a second loop is equal (because we are using include_once the second time
     // relies entirely on the static var already being valid)
     $secondPackages = Bluebox_Installer::listPackages();
     $this->assertEquals($packages, $secondPackages);
     // Determine from our base line what we would expect if we filtered by modules
     $expected = array();
     foreach ($packages as $name => $package) {
         if (in_array(Bluebox_Installer::TYPE_MODULE, $package['type'])) {
             $expected[$name] = $package;
         }
     }
     // Check the single include filter
     $filteredPackages = Bluebox_Installer::listPackages(Bluebox_Installer::TYPE_MODULE);
     $this->assertEquals($expected, $filteredPackages);
     // Check the lazy version of the same filter
     $filteredPackages = Bluebox_Installer::listPackages(array(Bluebox_Installer::TYPE_MODULE));
     $this->assertEquals($expected, $filteredPackages);
     // Check the explicit version of the same filter
     $filteredPackages = Bluebox_Installer::listPackages(array('include' => Bluebox_Installer::TYPE_MODULE));
     $this->assertEquals($expected, $filteredPackages);
     // Determine from our base line what we would expect if we excluded modules
     $expected = array();
     foreach ($packages as $name => $package) {
         if (!in_array(Bluebox_Installer::TYPE_MODULE, $package['type'])) {
             $expected[$name] = $package;
         }
     }
     // This filter can only be set explicitly
     $filteredPackages = Bluebox_Installer::listPackages(array('exclude' => Bluebox_Installer::TYPE_MODULE));
     $this->assertEquals($expected, $filteredPackages);
     // Determine from our base line what we would expect if we included both modules and drivers
     $expected = array();
     foreach ($packages as $name => $package) {
         if (in_array(Bluebox_Installer::TYPE_DRIVER, $package['type']) || in_array(Bluebox_Installer::TYPE_MODULE, $package['type'])) {
             $expected[$name] = $package;
         }
     }
     // This filter can only be set explicitly
     $filteredPackages = Bluebox_Installer::listPackages(array('include' => array(Bluebox_Installer::CATEGORY_MODULE, Bluebox_Installer::TYPE_DRIVER)));
     $this->assertEquals($expected, $filteredPackages);
     // Determine from our base line what we would expect if we included both modules and drivers
     $expected = array();
     foreach ($packages as $name => $package) {
         if (!in_array(Bluebox_Installer::TYPE_DRIVER, $package['type']) && !in_array(Bluebox_Installer::TYPE_MODULE, $package['type'])) {
             $expected[$name] = $package;
         }
     }
     // This filter can only be set explicitly
     $filteredPackages = Bluebox_Installer::listPackages(array('exclude' => array(Bluebox_Installer::TYPE_MODULE, Bluebox_Installer::TYPE_DRIVER)));
     $this->assertEquals($expected, $filteredPackages);
     // Ensure that if the DB check is disabled everything returns with installedAs == false
     $noDbPackages = Bluebox_Installer::listPackages(array(), true);
     foreach ($noDbPackages as $noDbPackage) {
         $this->assertEquals(false, $noDbPackage['installedAs']);
     }
 }
Exemple #2
0
 public function customize()
 {
     // get the module that these customize options apply to
     $module = $this->input->post('module', '');
     $module = str_replace('_module_permissions_custom', '', $module);
     // get the package definition for this module
     $packages = Bluebox_Installer::listPackages();
     $package = $packages[$module];
     // no package, no love
     if (empty($package)) {
         die;
     }
     $this->view->module = $module;
     $this->view->customizable = self::getCustomizable($package);
 }