fontyourface.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @file
  4. * Provides tests for simpletest.
  5. */
  6. class FontyourfaceSaveFontTestCase extends DrupalWebTestCase {
  7. public function getInfo() {
  8. return array(
  9. 'name' => t('Save font'),
  10. 'description' => t('Saves new font and updates existing font.'),
  11. 'group' => t('@font-your-face'),
  12. );
  13. } // getInfo
  14. public function setUp() {
  15. parent::setUp('fontyourface');
  16. } // setUp
  17. public function test() {
  18. // Save font.
  19. $best_font_ever = new stdClass;
  20. $best_font_ever->name = 'Best Font Ever';
  21. $best_font_ever->url = 'http://www.bestfontever.com/';
  22. $best_font_ever->provider = 'best_font_provider';
  23. $best_font_ever->css_family = 'best-font-ever';
  24. $best_font_ever->foundry = 'Best Foundry';
  25. $best_font_ever->license = 'Best License Agreement';
  26. $best_font_ever->license_url = 'http://www.bestfontever.com/license.html';
  27. $best_font_ever->tags = array('sans-serif', 'best');
  28. fontyourface_save_font($best_font_ever);
  29. // Check a font is inserted.
  30. $fids = array();
  31. $results = db_query('SELECT fid FROM {fontyourface_font}');
  32. while ($result = $results->fetchObject()) {
  33. $fids[] = $result->fid;
  34. } // while
  35. $this->assertIdentical(count($fids), 1, '1 fid in database.');
  36. // Check font loads.
  37. $font = fontyourface_get_font($fids[0], TRUE);
  38. $this->assertTrue($font, 'Font loaded.');
  39. // Check font matches.
  40. $this->assertIdentical($font->name, $best_font_ever->name, 'Font name matches insert.');
  41. $this->assertIdentical($font->fid, $best_font_ever->fid, 'Font fid matches insert.');
  42. // Save update.
  43. $updated_best_font_ever = new stdClass;
  44. $updated_best_font_ever->name = 'Updated Best Font Ever';
  45. $updated_best_font_ever->url = 'http://www.bestfontever.com/';
  46. $updated_best_font_ever->provider = 'best_font_provider';
  47. $updated_best_font_ever->css_family = 'updated-best-font-ever';
  48. $updated_best_font_ever->foundry = 'Best Foundry';
  49. $updated_best_font_ever->license = 'Best License Agreement';
  50. $updated_best_font_ever->license_url = 'http://www.bestfontever.com/license.html';
  51. $updated_best_font_ever->tags = array('sans-serif', 'best', 'updated');
  52. fontyourface_save_font($updated_best_font_ever);
  53. // Check font was not inserted.
  54. $fids = array();
  55. $results = db_query('SELECT fid FROM {fontyourface_font}');
  56. while ($result = $results->fetchObject()) {
  57. $fids[] = $result->fid;
  58. } // while
  59. $this->assertIdentical(count($fids), 1, 'Still 1 fid in database.');
  60. // Check font loads.
  61. $font = fontyourface_get_font($fids[0], TRUE);
  62. $this->assertTrue($font, 'Font loaded again.');
  63. // Check font matches.
  64. $this->assertIdentical($font->name, $updated_best_font_ever->name, 'Font name matches update.');
  65. $this->assertIdentical($font->fid, $updated_best_font_ever->fid, 'Font fid matches update.');
  66. } // test
  67. } // FontyourfaceSaveFontTestCase