Przeglądaj źródła

#37 unit tests reorganization + build using phing

Alex Trofimov 12 lat temu
rodzic
commit
a4bed32027

+ 3 - 1
.gitignore

@@ -16,5 +16,7 @@ Thumbs.db
 
 .*.swp
 
-# Exclude composer vendors folder
+# Exclude tests files
+build.properties
 tests/vendor
+tests/composer.phar

+ 72 - 0
build.xml

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Dolphin" basedir="." default="test">
+
+    <property file="${project.basedir}/build.properties" override="true" />
+
+    <if>
+        <not><isset property="composer" /></not>
+        <then><property name="composer" value="${project.basedir}/tests/composer.phar" override="yes" /></then>
+    </if> 
+
+    <if>
+        <not><isset property="php" /></not>
+        <then><property name="php" value="php" override="yes" /></then>
+    </if> 
+
+    <!-- ============================================  -->
+    <!-- Target: prepare                               -->
+    <!-- ============================================  -->
+    <target name="prepare">
+        <echo msg="Prepage: installing necessary components" />
+        <exec command="${composer} install" dir="${project.basedir}/tests" checkreturn="true" />
+    </target>
+
+    <!-- ============================================  -->
+    <!-- Target: install                               -->
+    <!-- ============================================  -->
+    <target name="install" depends="prepare">
+        <echo msg="Installing..." />
+        <exec command="${php} cmd.php" dir="${project.basedir}/install" checkreturn="true" />
+    </target>
+
+    <!-- ============================================  -->
+    <!-- (DEFAULT) Target: test                        -->
+    <!-- ============================================  -->
+    <target name="test">
+        <echo msg="Testing..." />
+        <exec command="${php} vendor/bin/phpunit" dir="${project.basedir}/tests" checkreturn="true" />
+    </target>
+
+    <!-- ============================================  -->
+    <!-- Target: dist                                  -->
+    <!-- ============================================  -->
+    <target name="dist">
+        <echo msg="TODO: Make distributive..." />
+    </target>
+
+    <!-- ============================================  -->
+    <!-- Target: clean                                 --> 
+    <!-- ============================================  -->
+    <target name="clean">
+        <echo msg="Cleaning..." />
+        <delete dir="${project.basedir}/tests/vendor" quiet="true" />
+        <delete includeemptydirs="true">
+            <fileset dir="${project.basedir}/cache">
+                <include name="**/*" />
+                <exclude name=".htaccess" />
+            </fileset>
+        </delete>
+        <delete includeemptydirs="true">
+            <fileset dir="${project.basedir}/cache_public">
+                <include name="**/*" />
+                <exclude name=".htaccess" />
+            </fileset>
+        </delete>
+        <delete includeemptydirs="true">
+            <fileset dir="${project.basedir}/tmp">
+                <include name="**/*" />
+                <exclude name=".htaccess" />
+            </fileset>
+        </delete>
+    </target>
+</project>

+ 8 - 0
tests/bootstrap.php

@@ -0,0 +1,8 @@
+<?php
+
+$aPathInfo = pathinfo(__FILE__);
+$sHeaderPath = $aPathInfo['dirname'] . '/../inc/header.inc.php';
+if (!file_exists($sHeaderPath))
+    die("Script is not installed\n");
+require_once($sHeaderPath);
+

+ 1 - 1
tests/phpunit.xml

@@ -1,4 +1,4 @@
-<phpunit>
+<phpunit bootstrap="bootstrap.php">
   <testsuites>
     <testsuite name="AllTests">
       <directory>units</directory>

+ 27 - 0
tests/units/inc/UtilTest.php

@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * This test performs test install, it can do it only if script is not installed yet.
+ */
+class UtilTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @dataProvider providerForReturnBytes
+     */
+    public function testReturnBytes($sInput, $sOutput)
+    {
+        $this->assertEquals(return_bytes($sInput), $sOutput);
+    }
+
+    public function providerForReturnBytes()
+    {
+        return array(
+            array('2k', 2048),
+            array('2K', 2048),
+            array('2 k', 2048),
+            array('2 K', 2048),
+            array('1m', 1048576),
+            array('1g', 1073741824),
+        );
+    }
+}

+ 0 - 75
tests/units/install/InstallTest.php

@@ -1,75 +0,0 @@
-<?php
-
-/**
- * This test performs test install, it can do it only if script is not installed yet.
- */
-class InstallTest extends PHPUnit_Framework_TestCase
-{
-    protected $_aSiteConfig;
-
-    public function __construct() 
-    {
-        $aPathInfo = pathinfo(__FILE__);
-        $this->_aSiteConfig = array (
-            'server_http_host' => 'localhost',
-            'server_php_self' => '/install/index.php',
-            'server_doc_root' => str_replace('tests/units/install', '', $aPathInfo['dirname']),
-            'form_data' => array (
-                'site_config' => true,
-                'db_name' => 'test',
-                'db_user' => 'root',
-                'db_password' => 'root',
-                'site_title' => 'Dolphin Test',
-                'site_desc' => 'Dolphin Test',
-                'site_email' => 'no-reply@example.com',
-                'admin_email' => 'admin@example.com',
-                'admin_username' => 'admin',
-                'admin_password' => 'dolphin',
-                'language' => 'en',
-            ),
-        );
-    }
-
-    protected function setUp()
-    {
-        // skip this test if script is already installed
-        if (file_exists('../inc/header.inc.php')) 
-            $this->markTestSkipped('Script is installed. Can\'t perform test install.');
-
-        // include necessary files to perform install
-        $_REQUEST['action'] = 'empty';
-        require_once('../install/index.php');
-    }
-
-    public function testRequirements()
-    {
-        $oAudit = new BxDolStudioToolsAudit();
-        $aErrors = $oAudit->checkRequirements(BX_DOL_AUDIT_FAIL);
-
-        $this->assertEmpty($aErrors);
-    }
-
-    /**
-     * @depends testRequirements
-     */
-    public function testPermissions()
-    {
-        $oAdmTools = new BxDolStudioTools();
-        $bPermissionsOk = $oAdmTools->checkPermissions(false, false);
-
-        $this->assertTrue($bPermissionsOk);
-    }
-
-    /**
-     * @depends testPermissions
-     */
-    public function testCreateSiteConfig()
-    {
-        $oSiteConfig = new BxDolInstallSiteConfig($this->_aSiteConfig['server_http_host'], $this->_aSiteConfig['server_php_self'], $this->_aSiteConfig['server_doc_root'], false);
-        $sErrorMessage = '';
-        $mixedResult = $oSiteConfig->getFormHtml(array_merge($oSiteConfig->getAutoValues(), $this->_aSiteConfig['form_data']), false, $sErrorMessage);
-
-        if (true !== $mixedResult)
-            $this->fail($sErrorMessage ? $sErrorMessage : 'Form data was not submitted');
-    }
-}