summaryrefslogtreecommitdiffstats
path: root/tests/library/SSRS/Object/CatalogItemsTest.php
blob: e50df39cd6e6b9ece28bc8a8332129537a1db1b3 (plain)
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
<?php

require_once('SSRS/Object/Abstract.php');
require_once('SSRS/Object/CatalogItems.php');
require_once('SSRS/Object/CatalogItem.php');

/**
 * Description of CatalogItemsTest
 *
 * @author arron
 */
class SSRS_Object_CatalogItemsTest extends PHPUnit_Framework_TestCase {

    public function testSetCatalogItems() {
        $catalogItem1 = new stdClass;
        $catalogItem1->ID = '1386fc6d-9c58-489f-adea-081146b62799';
        $catalogItem1->Name = 'Reference Report';
        $catalogItem1->Path = '/Reports/Reference Report';
        $catalogItem1->TypeName = 'Report';
        $catalogItem1->Size = '234413';
        $catalogItem1->CreationDate = '2011-03-03T12:32:57.063';
        $catalogItem1->ModifiedDate = '2011-03-03T12:51:12.05';
        $catalogItem1->CreatedBy = 'MSSQL\WebAccount';
        $catalogItem1->ModifiedBy = 'MSSQL\WebAccount';

        $data = new stdClass;
        $data->CatalogItems = new stdClass;
        $data->CatalogItems->CatalogItem = array($catalogItem1);

        $expected = new SSRS_Object_CatalogItems();
        $expected->addCatalogItem(new SSRS_Object_CatalogItem($catalogItem1));

        $object = new SSRS_Object_CatalogItems($data);
        $this->assertEquals($expected, $object);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testPassingInvalidObjectToAddCatalogItemThrowsError() {
        $object = new SSRS_Object_CatalogItems();
        $object->addCatalogItem(new SSRS_Object_Abstract());
    }

    public function testCatalogItemsEmptyArrayOnInit() {
        $object = new SSRS_Object_CatalogItems();
        $this->assertEquals(array(), $object->CatalogItems);
    }

    public function testAddCatalogItem() {
        $object = new SSRS_Object_CatalogItems();
        $object->addCatalogItem(new SSRS_Object_CatalogItem());

        $this->assertEquals(1, count($object->CatalogItems));
    }

    public function testSetCatalogItemsKeepsCurrentItems() {
        $dummy = new stdClass;
        $dummy->CatalogItem[] = new SSRS_Object_CatalogItem();

        $object = new SSRS_Object_CatalogItems();
        $object->setCatalogItems($dummy);
        $this->assertEquals(1, count($object->CatalogItems));

        $object->setCatalogItems($dummy);
        $this->assertEquals(2, count($object->CatalogItems));
    }

}