Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c5b4fbfc4d
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 73 lines (61 sloc) 2.064 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<?php
/**
* Tests for snipplr.core.php
* This test case is specific for CakePHP and requires CakeMate (Textmate plugin) in order to be run.
* It allows you to easily debug the output of method calls and also validate that you config settings
* are valid and working correctly.
*
* CakeMate URL: http://mark-story.com/posts/view/running-cakephp-unit-tests-with-textmate
*/

require_once('..'.DIRECTORY_SEPARATOR.'snipplr.core.php');

class SnipplrCoreTest extends UnitTestCase {
var $SnipplrCore;


function setup() {
$this->SnipplrCore = new SnipplrCore();
}

function testGet() {
$snippet = $this->SnipplrCore->get("18153");
$this->assertTrue(isset($snippet['id']));
//debug($snippet);
}

function testGetNotFound() {
$snippet = $this->SnipplrCore->get("00000");
$this->assertTrue(empty($snippet));
//debug($snippet);
}

function testGetAll() {
$snippets = $this->SnipplrCore->getAll();
$this->assertTrue(isset($snippets[0]['id']));
$this->assertTrue(isset($snippets[1]['id']));
//debug($snippets);
}

function testGetAllOptionTags() {
// Multiple tags don't seem to work in the Snipplr API. Only the last tag will be used.
$snippets = $this->SnipplrCore->getAll(array('tags' => 'css'));
//debug($snippets);
}

function testGetAllOptionSortTitle() {
$snippets = $this->SnipplrCore->getAll(array('sort' => 'title'));
// check its in alphabetical order against php sort method
$titles = array();
foreach($snippets as $snippet) {
$titles[] = strtoupper($snippet['title']);
}
$sort_titles = $titles;
sort($sort_titles);
$this->assertEqual($titles, $sort_titles);
//debug($snippets);
}

function testGetAllOptionLimit() {
$snippets = $this->SnipplrCore->getAll(array('limit' => '4'));
$this->assertEqual(sizeof($snippets), 4);
//debug($snippets);
}

function testGetAllLanguages() {
$languages = $this->SnipplrCore->getAllLanguages();
$this->assertEqual($languages[0]['slug'], 'actionscript');
$this->assertEqual($languages[0]['name'], 'ActionScript');
//debug($languages);
}
}
?>
Something went wrong with that request. Please try again.