Completed
Pull Request — master (#230)
by Helpful
03:29
created

WorkflowEmbargoExpiryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * @author [email protected]
5
 * @license BSD License http://silverstripe.org/bsd-license/
6
 */
7
class WorkflowEmbargoExpiryTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
10
    public function setUp()
11
    {
12
        parent::setUp();
13
14
        SS_Datetime::set_mock_now('2014-01-05 12:00:00');
15
    }
16
17
    public function tearDown()
18
    {
19
        SS_Datetime::clear_mock_now();
20
        parent::tearDown();
21
    }
22
23
    /**
24
     * @var array
25
     */
26
    protected $requiredExtensions = array(
27
        'SiteTree' => array(
28
            'WorkflowEmbargoExpiryExtension',
29
            'Versioned',
30
        )
31
    );
32
33
    /**
34
     * @var array
35
     */
36
    protected $illegalExtensions = array(
37
        'SiteTree' => array(
38
            "Translatable",
39
        )
40
    );
41
42
    public function __construct()
43
    {
44
        if (!class_exists('AbstractQueuedJob')) {
45
            $this->skipTest = true;
46
        }
47
        parent::__construct();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SapphireTest as the method __construct() does only exist in the following sub-classes of SapphireTest: FileFinderTest, ManifestFileFinderTest, MemberTest, WorkflowEmbargoExpiryTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
48
    }
49
50
    public function testFutureDatesJobs()
51
    {
52
        $page = new Page();
53
54
        $page->PublishOnDate = '2020-01-01 00:00:00';
55
        $page->UnPublishOnDate = '2020-01-01 01:00:00';
56
57
        // Two writes are necessary for this to work on new objects
58
        $page->write();
59
        $page->write();
60
61
        $this->assertTrue($page->PublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
        $this->assertTrue($page->UnPublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
64
        // Check date ranges
65
        $now = strtotime(SS_Datetime::now()->getValue());
66
        $publish = strtotime($page->PublishJob()->StartAfter);
67
        $unPublish = strtotime($page->UnPublishJob()->StartAfter);
68
69
        $this->assertGreaterThan($now, $publish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
        $this->assertGreaterThan($now, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
        $this->assertGreaterThan($publish, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
    }
73
74
    public function testDesiredRemovesJobs()
75
    {
76
        $page = new Page();
77
78
        $page->PublishOnDate = '2020-01-01 00:00:00';
79
        $page->UnPublishOnDate = '2020-01-01 01:00:00';
80
81
        // Two writes are necessary for this to work on new objects
82
        $page->write();
83
        $page->write();
84
85
        $this->assertTrue($page->PublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
        $this->assertTrue($page->UnPublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
88
        // Check date ranges
89
        $now = strtotime(SS_Datetime::now()->getValue());
90
        $publish = strtotime($page->PublishJob()->StartAfter);
91
        $unPublish = strtotime($page->UnPublishJob()->StartAfter);
92
93
        $this->assertGreaterThan($now, $publish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
94
        $this->assertGreaterThan($now, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
95
        $this->assertGreaterThan($publish, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
97
        $page->DesiredPublishDate = '2020-02-01 00:00:00';
98
        $page->DesiredUnPublishDate = '2020-02-01 02:00:00';
99
100
        $page->write();
101
102
        $this->assertTrue($page->PublishJobID == 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
        $this->assertTrue($page->UnPublishJobID == 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
    }
105
106
    public function testPublishActionWithFutureDates()
107
    {
108
        $action = new PublishItemWorkflowAction();
109
        $instance = new WorkflowInstance();
110
111
        $page = new Page();
112
        $page->Title = 'stuff';
113
        $page->DesiredPublishDate = '2020-02-01 00:00:00';
114
        $page->DesiredUnPublishDate = '2020-02-01 02:00:00';
115
116
        $page->write();
117
118
        $instance->TargetClass = $page->ClassName;
0 ignored issues
show
Documentation introduced by
The property TargetClass does not exist on object<WorkflowInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
119
        $instance->TargetID = $page->ID;
0 ignored issues
show
Documentation introduced by
The property TargetID does not exist on object<WorkflowInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
120
121
        $action->execute($instance);
122
123
        $page = DataObject::get_by_id('Page', $page->ID);
124
        $this->assertTrue($page->PublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
        $this->assertTrue($page->UnPublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
126
127
        // Check date ranges
128
        $now = strtotime(SS_Datetime::now()->getValue());
129
        $publish = strtotime($page->PublishJob()->StartAfter);
130
        $unPublish = strtotime($page->UnPublishJob()->StartAfter);
131
132
        $this->assertGreaterThan($now, $publish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
133
        $this->assertGreaterThan($now, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
134
        $this->assertGreaterThan($publish, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
    }
136
137
    /**
138
     * Test that a page with a past publish date creates the correct jobs
139
     */
140 View Code Duplication
    public function testPastPublishThenUnpublish()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    {
142
        $page = new Page();
143
        $page->Title = 'My Page';
144
        $page->write();
145
146
        // No publish
147
        $this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
148
        $this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
149
150
        // Set a past publish date
151
        $page->PublishOnDate = '2010-01-01 00:00:00';
152
        $page->write();
153
154
        // We should still have a job to publish this page, but not unpublish
155
        $this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
        $this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
157
158
        // Check that this job is set for immediate run
159
        $publish = strtotime($page->PublishJob()->StartAfter);
160
        $this->assertEmpty($publish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
161
162
        // Now add an expiry date in the past, but after the current publish job,
163
        // and ensure that this correctly overrides the open publish request
164
        $page->UnPublishOnDate = '2010-01-02 00:00:00';
165
        $page->write();
166
167
        // Now we should have an unpublish job, but the publish job is noticably absent
168
        $this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
169
        $this->assertNotEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
170
171
        // Check that this unpublish job is set for immediate run
172
        $unpublish = strtotime($page->UnPublishJob()->StartAfter);
173
        $this->assertEmpty($unpublish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
174
175
        // Now add an expiry date in the future, and ensure that we get the correct combination of
176
        // publish and unpublish jobs
177
        $page->UnPublishOnDate = '2015-01-01 12:00:00';
178
        $page->write();
179
180
        // Both jobs exist
181
        $this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
182
        $this->assertNotEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
183
184
        // Check that this unpublish job is set for immediate run and the unpublish for future
185
        $publish = strtotime($page->PublishJob()->StartAfter);
186
        $unpublish = strtotime($page->UnPublishJob()->StartAfter);
187
        $this->assertEmpty($publish); // for immediate run
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
188
        $this->assertGreaterThan(strtotime(SS_Datetime::now()->getValue()), $unpublish); // for later run
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
189
    }
190
191
    /**
192
     * Test that a page with a past unpublish date creates the correct jobs
193
     */
194 View Code Duplication
    public function testPastUnPublishThenPublish()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
195
    {
196
        $page = new Page();
197
        $page->Title = 'My Page';
198
        $page->write();
199
200
        // No publish
201
        $this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
202
        $this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
203
204
        // Set a past unpublish date
205
        $page->UnPublishOnDate = '2010-01-01 00:00:00';
206
        $page->write();
207
208
        // We should still have a job to unpublish this page, but not publish
209
        $this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
210
        $this->assertNotEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
211
212
        // Check that this job is set for immediate run
213
        $unpublish = strtotime($page->UnPublishJob()->StartAfter);
214
        $this->assertEmpty($unpublish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
215
216
        // Now add an publish date in the past, but after the unpublish job,
217
        // and ensure that this correctly overrides the open unpublish request
218
        $page->PublishOnDate = '2010-01-02 00:00:00';
219
        $page->write();
220
221
        // Now we should have an publish job, but the unpublish job is noticably absent
222
        $this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
223
        $this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
224
225
        // Check that this publish job is set for immediate run
226
        $publish = strtotime($page->PublishJob()->StartAfter);
227
        $this->assertEmpty($publish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
228
229
        // Now add a publish date in the future, and ensure that we get the correct combination of
230
        // publish and unpublish jobs
231
        $page->PublishOnDate = '2015-01-01 12:00:00';
232
        $page->write();
233
234
        // Both jobs exist
235
        $this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
236
        $this->assertNotEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
237
238
        // Check that this unpublish job is set for immediate run and the unpublish for future
239
        $publish = strtotime($page->PublishJob()->StartAfter);
240
        $unpublish = strtotime($page->UnPublishJob()->StartAfter);
241
        $this->assertEmpty($unpublish); // for immediate run
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
242
        $this->assertGreaterThan(strtotime(SS_Datetime::now()->getValue()), $publish); // for later run
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
243
    }
244
245
    public function testPastPublishWithWorkflowInEffect()
246
    {
247
        $definition = $this->createDefinition();
248
249
        $page = new Page();
250
        $page->Title = 'My page';
251
        $page->WorkflowDefinitionID = $definition->ID;
252
        $page->write();
253
254
        // No publish
255
        $this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
256
        $this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
257
258
        // Set a past publish date
259
        $page->DesiredPublishDate = '2010-01-01 00:00:00';
260
        $page->write();
261
262
        // Workflow is in effect. No jobs have been created yet as it's not approved.
263
        $this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
264
        $this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
265
266
        // Advance the workflow so we can see what happens
267
        $instance = new WorkflowInstance();
268
        $instance->beginWorkflow($definition, $page);
269
        $instance->execute();
270
271
        // execute the "publish" workflow action
272
        $action = new PublishItemWorkflowAction();
273
        $action->execute($instance);
274
275
        // re-fetch the Page again.
276
        $page = Page::get()->byId($page->ID);
277
278
        // We now have a PublishOnDate field set
279
        $this->assertEquals('2010-01-01 00:00:00', $page->PublishOnDate);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
280
        $this->assertEmpty($page->DesiredPublishDate);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
281
282
        // Publish job has been setup
283
        $this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
284
        $this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
285
286
        // Check that this publish job is set for immediate run
287
        $publish = strtotime($page->PublishJob()->StartAfter);
288
        $this->assertEmpty($publish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
289
    }
290
291 View Code Duplication
    protected function createDefinition()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
292
    {
293
        $definition = new WorkflowDefinition();
294
        $definition->Title = 'Dummy Workflow Definition';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<WorkflowDefinition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
295
        $definition->write();
296
297
        $stepOne = new WorkflowAction();
298
        $stepOne->Title = 'Step One';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
299
        $stepOne->WorkflowDefID = $definition->ID;
0 ignored issues
show
Documentation introduced by
The property WorkflowDefID does not exist on object<WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
300
        $stepOne->write();
301
302
        $stepTwo = new WorkflowAction();
303
        $stepTwo->Title = 'Step Two';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
304
        $stepTwo->WorkflowDefID = $definition->ID;
0 ignored issues
show
Documentation introduced by
The property WorkflowDefID does not exist on object<WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
305
        $stepTwo->write();
306
307
        $transitionOne = new WorkflowTransition();
308
        $transitionOne->Title = 'Step One T1';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
309
        $transitionOne->ActionID = $stepOne->ID;
0 ignored issues
show
Documentation introduced by
The property ActionID does not exist on object<WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
310
        $transitionOne->NextActionID = $stepTwo->ID;
0 ignored issues
show
Documentation introduced by
The property NextActionID does not exist on object<WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
311
        $transitionOne->write();
312
313
        return $definition;
314
    }
315
}
316