Browse Source

Add example test

Abdullah Almsaeed 7 years ago
parent
commit
fa46fc2d5c
3 changed files with 43 additions and 17 deletions
  1. 0 1
      phpunit.xml
  2. 43 0
      tests/TripalJobsTest.test
  3. 0 16
      tests/tripal_test.test

+ 0 - 1
phpunit.xml

@@ -6,7 +6,6 @@
     <testsuites>
         <testsuite name="default">
             <directory suffix=".test">./tests/</directory>
-            <exclude>tests/bootstrap.php</exclude>
         </testsuite>
     </testsuites>
 </phpunit>

+ 43 - 0
tests/TripalJobsTest.test

@@ -0,0 +1,43 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+class TripalJobsTest extends TestCase {
+
+  /**
+   * Holds the job id to delete when done.
+   *
+   * @var int|bool
+   */
+  protected $job_id;
+
+  /**
+   * Tests the ability to create a tripal job.
+   *
+   * @test
+   */
+  public function should_create_a_tripal_job() {
+    $this->job_id = tripal_add_job('Test adding jobs', 'test_module', 'test_callback', [], 1);
+    $this->assertTrue(is_numeric($this->job_id));
+  }
+
+  /**
+   * Tests whether creating a duplicate job is possible.
+   *
+   * @test
+   */
+  public function should_refuse_to_create_duplicate_job() {
+    $job = tripal_add_job('Test adding jobs', 'test_module', 'test_callback', [], 1, 10, TRUE);
+    $this->assertEmpty($job);
+  }
+
+  /**
+   * Run clean up
+   */
+  public function __destruct() {
+    // Clean up any data inserted to the DB
+    if ($this->job_id) {
+      db_query('DELETE FROM {tripal_jobs} WHERE job_id = :id', [':id' => $this->job_id]);
+    }
+  }
+}

+ 0 - 16
tests/tripal_test.test

@@ -1,16 +0,0 @@
-<?php
-
-use PHPUnit\Framework\TestCase;
-
-//some reading for organizing and annotating tests
-//https://stackoverflow.com/questions/8313283/phpunit-best-practices-to-organize-tests
-//https://jtreminio.com/2013/03/unit-testing-tutorial-introduction-to-phpunit/
-
-final class tripal_test extends TestCase {
-
-  public function testTrueIsTrue() {
-    $foo = TRUE;
-    $this->assertTrue($foo);
-
-  }
-}