[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/tests/tests/install/ -> install.php (source)

   1  <?php
   2  
   3  /**
   4   * Checks install misc functions
   5   *
   6   * @group install
   7   */
   8  class Install_Tests extends PHPUnit\Framework\TestCase {
   9  
  10      /**
  11       * Check if YOURLS is declared installed
  12       */
  13  	public function test_install() {
  14          $this->assertTrue( yourls_is_installed() );
  15      }
  16  
  17      /**
  18       * Check that tables were correctly populated during install
  19       */
  20  	public function test_init_tables() {
  21          // This should fail because these inserts have been taken care of during install
  22          $this->assertFalse( yourls_initialize_options() );
  23          $this->assertFalse( yourls_insert_sample_links() );
  24      }
  25  
  26      /**
  27       * Test (sort of) table creation
  28       */
  29  	public function test_create_tables() {
  30  
  31          /* The expected result has:
  32           *   - success messages: the table are created with a "CREATE IF NOT EXISTS",
  33           *     hence, will not be recreated once more, they're already created
  34           *     upon install procedure
  35           *   - error messages: the function cannot initialize options and links, since
  36           *     they have been populated during install procedure as well
  37           *
  38           * A more thorough test would be to mockup the DB connection and create another
  39           * set of tables (with another prefix for instance).
  40           * Well. Consider this for next DB engine maybe? :)
  41           */
  42  
  43          $expected = array(
  44              'success' => array (
  45                  "Table 'yourls_url' created.",
  46                  "Table 'yourls_options' created.",
  47                  "Table 'yourls_log' created.",
  48                  "YOURLS tables successfully created.",
  49              ),
  50              'error' => array (
  51                  'Could not initialize options',
  52                  'Could not insert sample short URLs',
  53              ),
  54          );
  55  
  56          $this->assertSame( $expected, yourls_create_sql_tables() );
  57      }
  58  
  59      /**
  60       * Test (sort of) defining constants
  61       */
  62      public function test_correct_config() {
  63          $test = new \YOURLS\Config\Config(YOURLS_CONFIGFILE);
  64  
  65          // This should return a readable file
  66          $readable = is_readable($test->find_config(YOURLS_CONFIGFILE));
  67          $this->assertTrue($readable);
  68          // For the record, $this->assertFileIsReadable() was introduced around PHPUnit 5.6
  69  
  70          // redefining YOURLS_ constants should not throw any error ("constant already defined...")
  71          // or define any new constants
  72          $consts = get_defined_constants(true);
  73          $before = $consts['user'];
  74          $test->define_core_constants();
  75          $consts = get_defined_constants(true);
  76          $after = $consts['user'];
  77          $this->assertSame($before,$after);
  78      }
  79  
  80      /**
  81       * Test incorrect config provided
  82       */
  83      public function test_incorrect_config() {
  84          $this->expectException(YOURLS\Exceptions\ConfigException::class);
  85          $this->expectExceptionMessageMatches('/User defined config not found at \'[0-9a-z]+\'/');
  86  
  87          $test = new \YOURLS\Config\Config(rand_str());
  88          $test->find_config();
  89      }
  90  
  91      /**
  92       * Test config not found
  93       */
  94      public function test_not_found_config() {
  95          $this->expectException(YOURLS\Exceptions\ConfigException::class);
  96          $this->expectExceptionMessage('Cannot find config.php. Please read the readme.html to learn how to install YOURLS');
  97  
  98          $test = new \YOURLS\Config\Config();
  99          $test->set_root(rand_str());
 100          $test->find_config();
 101      }
 102  
 103      /**
 104       * Test Init actions. Not sure this is a good idea, might become cumbersome to maintain?
 105       */
 106      public function test_init_defaults() {
 107          $test = new \YOURLS\Config\InitDefaults();
 108  
 109          $expected = array (
 110              'include_core_funcs' => true,
 111              'default_timezone' => true,
 112              'load_default_textdomain' => true,
 113              'check_maintenance_mode' => true,
 114              'fix_request_uri' => true,
 115              'redirect_ssl' => true,
 116              'include_db' => true,
 117              'include_cache' => true,
 118              'return_if_fast_init' => true,
 119              'get_all_options' => true,
 120              'register_shutdown' => true,
 121              'core_loaded' => true,
 122              'redirect_to_install' => true,
 123              'check_if_upgrade_needed' => true,
 124              'load_plugins' => true,
 125              'plugins_loaded_action' => true,
 126              'check_new_version' => true,
 127              'init_admin' => true,
 128          );
 129  
 130          $actual = get_class_vars(get_class($test));
 131  
 132          $this->assertSame($expected, $actual);
 133      }
 134  
 135  }


Generated: Tue Jan 21 05:10:11 2025 Cross-referenced by PHPXref 0.7.1