Source

Repustate Clients / php / RepustateTest.php

Full commit
<?php
//
//  Unit tests for the Repustate PHP API client.
//
//  Requirements:
//  - phpunit - http://www.phpunit.de/manual/3.6/en/phpunit-book.html
//

require 'Repustate.php';

class RepustateTest extends PHPUnit_Framework_TestCase
{
    const key = 'YOUR_KEY_HERE';

    function getAccessor()
    {
        return new Repustate(self::key);
    }

    function checkCall()
    {
        $accessor = $this->getAccessor();
        $args = func_get_args();
        $method = $args[0];
        $methodArgs = $args[1];
        $result = $accessor->{$method}($methodArgs);
        $this->assertInternalType('object', $result, 'Invalid result');
        $status = (string) $result->status;
        $this->assertEquals($status, 'OK', $status);
    }

    public function textUrlProvider()
    {
        return array(
            array(array('text' => 'iPad')),
            array(array('url' => 'http://tcrn.ch/aav9Ty')),
        );
    }

    /**
     * @dataProvider textUrlProvider
     */
    public function testSentiment($args)
    {
        $this->checkCall('sentiment', $args);
    }

    public function testBulkSentiment()
    {
        $this->checkCall('bulkSentiment', array('I love candy'));
    }

    /**
     * @dataProvider textUrlProvider
     */
    public function testAdjectives($args)
    {
        $this->checkCall('adjectives', $args);
    }

    /**
     * @dataProvider textUrlProvider
     */
    public function testVerbs($args)
    {
        $this->checkCall('verbs', $args);
    }

    public function testCleanHtml()
    {
        $this->checkCall('clean_html', array('url' => 'http://tcrn.ch/aav9Ty'));
    }

    /**
     * @dataProvider textUrlProvider
     */
    public function testNgrams($args)
    {
        $this->checkCall('ngrams', $args);
    }

    public function testDateExtraction()
    {
        $this->checkCall('dateExtraction', array('text' => 'iPad'));
    }

    public function testPowerpoint()
    {
        $args = array(
            'reportTitle' => 'Test Report',
            'author' => 'Martin Ostrovsky',
            'images' => array('repustate.gif'),
            'titles' => array('A test title'),
            'notes' => array('What a pretty slide.'),
        );
        $accessor = $this->getAccessor();
        $result = $accessor->powerpoint($args);
        $this->assertNotEmpty($result, 'Result should not be empty');
    }
}

?>