~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to tests/integration/TemplateTest.php

  • Committer: Dan Garner
  • Date: 2015-03-26 14:08:33 UTC
  • Revision ID: git-v1:70d14044444f8dc5d602b99890d59dea46d9470c
Moved web servable files to web folder

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Spring Signage Ltd - http://www.springsignage.com
4
 
 * Copyright (C) 2015 Spring Signage Ltd
5
 
 * (TemplateTest.php)
6
 
 */
7
 
 
8
 
namespace Xibo\Tests\Integration;
9
 
use Xibo\Helper\Random;
10
 
use Xibo\OAuth2\Client\Entity\XiboLayout;
11
 
use Xibo\Tests\LocalWebTestCase;
12
 
 
13
 
/**
14
 
 * Class TemplateTest
15
 
 * @package Xibo\Tests
16
 
 */
17
 
class TemplateTest extends LocalWebTestCase
18
 
{
19
 
    /**
20
 
     * Show Templates
21
 
     */
22
 
    public function testListAll()
23
 
    {
24
 
        $this->client->get('/template');
25
 
 
26
 
        $this->assertSame(200, $this->client->response->status());
27
 
        $this->assertNotEmpty($this->client->response->body());
28
 
        $object = json_decode($this->client->response->body());
29
 
        $this->assertObjectHasAttribute('data', $object);
30
 
    }
31
 
 
32
 
    /**
33
 
     * Add Template
34
 
     */
35
 
    public function testAdd()
36
 
    {
37
 
        # Create random name and new layout
38
 
        $name1 = Random::generateString(8, 'phpunit');
39
 
        $layout = (new XiboLayout($this->getEntityProvider()))->create($name1, 'phpunit description', '', 9);
40
 
        # Generate second random name
41
 
        $name2 = Random::generateString(8, 'phpunit');
42
 
        # Create template using our layout and new name
43
 
        $this->client->post('/template/' . $layout->layoutId, [
44
 
            'name' => $name2,
45
 
            'includeWidgets' =>1,
46
 
            'tags' => $layout->tags,
47
 
            'description' => $layout->description 
48
 
        ]);
49
 
        # Check if successful
50
 
        $this->assertSame(200, $this->client->response->status(), $this->client->response->body());
51
 
        $object = json_decode($this->client->response->body());
52
 
        $this->assertObjectHasAttribute('data', $object);
53
 
        $this->assertObjectHasAttribute('id', $object);
54
 
        # Check if it has edited name
55
 
        $this->assertSame($name2, $object->data->layout);
56
 
        $templateId = $object->id;
57
 
        # delete template as we no longer need it
58
 
        $template = (new XiboLayout($this->getEntityProvider()))->getByTemplateId($object->id);
59
 
        $template->delete();
60
 
        # delete layout as we no longer need it
61
 
        $layout->delete();
62
 
    }
63
 
}