You are here

class RecipeUnitTest in Recipe 7

Same name and namespace in other branches
  1. 7.2 src/Tests/RecipeUnitTest.php \Drupal\recipe\Tests\RecipeUnitTest

Tests isolated Recipe module functions.

Hierarchy

  • class \Drupal\recipe\Tests\RecipeUnitTest extends \Drupal\recipe\Tests\DrupalUnitTestCase

Expanded class hierarchy of RecipeUnitTest

See also

\DrupalUnitTestCase

File

src/Tests/RecipeUnitTest.php, line 10

Namespace

Drupal\recipe\Tests
View source
class RecipeUnitTest extends \DrupalUnitTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Recipe unit tests',
      'description' => 'Test that Recipe functions work properly.',
      'group' => 'Recipe',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    drupal_load('module', 'recipe');
    parent::setUp();
  }

  /**
   * Test ingredient quantity conversion functions.
   */
  public function testIngredientQuantityConversion() {
    $quantities = array(
      // Test a couple of whole numbers.
      '1',
      '10',
      // Test a couple of mixed numbers.
      '1 1/2',
      '10 1/2',
      // Test the fractions which convert to repeating decimals that are
      // converted by recipe_ingredient_quantity_from_decimal().
      '1/3',
      '2/3',
      '1/6',
      '5/6',
      '1/9',
      '2/9',
      '4/9',
      '5/9',
      '7/9',
      '8/9',
      '1/12',
      '5/12',
      '7/12',
      '11/12',
    );
    foreach ($quantities as $quantity) {

      // Convert the fraction quantity to a decimal.
      $decimal = recipe_ingredient_quantity_from_fraction($quantity);

      // Convert the decimal quantity back to a fraction string.
      $fraction = recipe_ingredient_quantity_from_decimal($decimal);

      // Replace the '⁄' in the fraction string with '/'.
      $fraction = str_replace('⁄', '/', $fraction);

      // Verify the fraction result is the same as the original quantity.
      $this
        ->assertEqual($quantity, $fraction);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RecipeUnitTest::getInfo public static function
RecipeUnitTest::setUp public function
RecipeUnitTest::testIngredientQuantityConversion public function Test ingredient quantity conversion functions.