<?php

/**
 * Generated by PHPUnit_SkeletonGenerator on 2015-07-30 at 15:39:12.
 */
class ReportTest extends PHPUnit_Framework_TestCase {

    /**
     * @var Report
     */
    protected $object;
    protected $paramValueList;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp() {
        $this->paramValueList = array();
    }

    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     */
    protected function tearDown() {

    }

    /**
     * @covers Report::applyDateRange
     * @todo   Implement testApplyDateRange().
     */
    public function testApplyDateRange() {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    /**
     * @covers Report::run
     * @todo   Implement testRun().
     */
    public function testRun() {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    /**
     * @covers Report::getOutliers
     * @todo   Implement testGetOutliers().
     */
    public function testGetOutliers() {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    /**
     * @covers Report::getParameters
     * @todo   Implement testGetParameters().
     */
    public function testGetParameters() {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    /**
     * @covers Report::getColumnData
     * @todo   Implement testGetColumnData().
     */
    public function testGetColumnData() {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    /**
     * @covers Report::getUsageTitle
     * @todo   Implement testGetUsageTitle().
     */
    public function testGetUsageTitle() {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    /**
     * @covers Report::getLinkResolverLink
     * @todo   Implement testGetLinkResolverLink().
     */
    public function testGetLinkResolverLink() {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    /**
     * @dataProvider reportIdProvider
     */
    public function testParams($reportID) {
        $this->setUp();

        $report = ReportFactory::makeReport($reportID);
        Parameter::setReport($report);

        $params = $report->getParameters();
        foreach ($params as $parm ) {
            $this->initParamValues($parm);
        }

        $imax = 0;
        foreach ($this->paramValueList as $paramVals) {
            $n = count($paramVals);
            if ($n>$imax) {
                $imax = $n;
            }
        }

        $i = 0;
        while ($i<$imax) {
            $params = $report->getParameters();
            foreach ($params as $parm ) {
                $this->initParamValues($parm);
            }
            foreach ($params as $p) {
                if (isset($this->paramValueList[$p->id])) {
                    $list = $this->paramValueList[$p->id];
                    $n = count($list);
                    if ($i<$n) {
                        $p->value = $this->paramValueList[$p->id][$i];
                    } else if ($n>0) {
                        $p->value = $this->paramValueList[$p->id][$n-1];
                    }
                }
            }
            ++$i;
        }
    }

    /**
     * @dataProvider reportIdProvider
     * @depends testParams
     */
    public function testReportId($reportID) {
        $report = ReportFactory::makeReport($reportID);
        Parameter::setReport($report);
        foreach ($report->getParameters() as $parm ) {
            $parm->process();
        }
        $report->run(false,true);
        $report->run(true,true);
    }

    public function reportIdProvider() {
        $db = new DBService();
        $ids = array();
        foreach ( $db->query("SELECT reportID FROM Report")->fetchRows(MYSQLI_ASSOC) as $report ) {
            $ids[] = array($report['reportID']);
        }

        return $ids;
    }

    // only partial coverage
    public function initParamValues($parm) {
        $this->paramValueList = array($parm->id => $parm->value);

        if (is_a($parm,'CheckboxParameter')) {
            $this->paramValueList[$parm->id] = array('Y');
        } else if (is_a($parm,'DropdownParameter')) {
            if (trim($parm->sql)==='') {
                throw new RuntimeException("parameter missing sql for test");
            }
            foreach ($parm->getSelectValues($parm->parentID) as $v) {
                $this->paramValueList[$parm->id][] = $v['cde'];
            }
        }
    }

    public function testReportHeaders() {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

}
