cloudflare/Cloudflare-WordPress

Public

mirrored fromhttps://github.com/cloudflare/Cloudflare-WordPress

CodeCommitsIssuesPull requestsActionsInsightsSecurity
d1e4063807bfb21163868b42718ba475be20b74d

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Test/WordPress/PluginActionsTest.php

124lines · modecode

1<?php
2
3namespace CF\WordPress\Test;
4
5use CF\Integration\DefaultIntegration;
6use CF\WordPress\Constants\Plans;
7use CF\WordPress\PluginActions;
8use phpmock\phpunit\PHPMock;
9
10class PluginActionsTest extends \PHPUnit_Framework_TestCase
11{
12 use PHPMock;
13
14 private $mockConfig;
15 private $mockDataStore;
16 private $mockDefaultIntegration;
17 private $mockGetAdminUrl;
18 private $mockLogger;
19 private $mockPluginAPIClient;
20 private $mockWordPressAPI;
21 private $mockWordPressClientAPI;
22 private $mockWPLoginUrl;
23 private $mockRequest;
24 private $pluginActions;
25
26 public function setup()
27 {
28 $this->mockConfig = $this->getMockBuilder('CF\Integration\DefaultConfig')
29 ->disableOriginalConstructor()
30 ->getMock();
31 $this->mockDataStore = $this->getMockBuilder('CF\WordPress\DataStore')
32 ->disableOriginalConstructor()
33 ->getMock();
34 $this->mockGetAdminUrl = $this->getFunctionMock('CF\WordPress', 'get_admin_url');
35 $this->mockLogger = $this->getMockBuilder('\Psr\Log\LoggerInterface')
36 ->disableOriginalConstructor()
37 ->getMock();
38 $this->mockPluginAPIClient = $this->getMockBuilder('CF\API\Plugin')
39 ->disableOriginalConstructor()
40 ->getMock();
41 $this->mockWordPressAPI = $this->getMockBuilder('CF\WordPress\WordPressAPI')
42 ->disableOriginalConstructor()
43 ->getMock();
44 $this->mockWordPressClientAPI = $this->getMockBuilder('CF\WordPress\WordPressClientAPI')
45 ->disableOriginalConstructor()
46 ->getMock();
47 $this->mockWPLoginUrl = $this->getFunctionMock('CF\WordPress', 'wp_login_url');
48 $this->mockRequest = $this->getMockBuilder('CF\API\Request')
49 ->disableOriginalConstructor()
50 ->getMock();
51
52 $this->mockDefaultIntegration = new DefaultIntegration($this->mockConfig, $this->mockWordPressAPI, $this->mockDataStore, $this->mockLogger);
53 $this->pluginActions = new PluginActions($this->mockDefaultIntegration, $this->mockPluginAPIClient, $this->mockRequest);
54 $this->pluginActions->setClientAPI($this->mockWordPressClientAPI);
55 }
56
57 public function testReturnApplyDefaultSettingsWithZoneWithPlanBIZ()
58 {
59 $this->mockRequest->method('getUrl')->willReturn('/plugin/:id/settings/default_settings');
60
61 $this->mockWordPressClientAPI->method('zoneGetDetails')->willReturn(
62 array(
63 'result' => array(
64 'plan' => array(
65 'legacy_id' => Plans::BIZ_PLAN,
66 ),
67 ),
68 )
69 );
70 $this->mockWordPressClientAPI->method('responseOk')->willReturn(true);
71 $this->mockWordPressClientAPI->method('changeZoneSettings')->willReturn(true);
72 $this->mockWordPressClientAPI->expects($this->exactly(16))->method('changeZoneSettings');
73
74 $this->pluginActions->applyDefaultSettings();
75 }
76
77 public function testReturnApplyDefaultSettingsWithZoneWithFreePlan()
78 {
79 $this->mockRequest->method('getUrl')->willReturn('/plugin/:id/settings/default_settings');
80
81 $this->mockWordPressClientAPI->method('zoneGetDetails')->willReturn(
82 array(
83 'result' => array(
84 'plan' => array(
85 'legacy_id' => Plans::FREE_PLAN,
86 ),
87 ),
88 )
89 );
90 $this->mockWordPressClientAPI->method('responseOk')->willReturn(true);
91 $this->mockWordPressClientAPI->method('changeZoneSettings')->willReturn(true);
92 $this->mockWordPressClientAPI->expects($this->exactly(14))->method('changeZoneSettings');
93
94 $this->pluginActions->applyDefaultSettings();
95 }
96
97 /**
98 * @expectedException CF\API\Exception\ZoneSettingFailException
99 */
100 public function testReturnApplyDefaultSettingsZoneDetailsThrowsZoneSettingFailException()
101 {
102 $this->mockRequest->method('getUrl')->willReturn('/plugin/:id/settings/default_settings');
103
104 $this->mockWordPressClientAPI->method('zoneGetDetails')->willReturn(false);
105
106 $this->pluginActions->applyDefaultSettings();
107 }
108
109 /**
110 * @expectedException CF\API\Exception\ZoneSettingFailException
111 */
112 public function testReturnApplyDefaultSettingsChangeZoneSettingsThrowsZoneSettingFailException()
113 {
114 $this->mockRequest->method('getUrl')->willReturn('/plugin/:id/settings/default_settings');
115
116 $this->mockWordPressClientAPI->method('zoneGetDetails')->willReturn(false);
117
118 $this->mockWordPressClientAPI->method('zoneGetDetails')->willReturn(true);
119 $this->mockWordPressClientAPI->method('responseOk')->willReturn(true);
120 $this->mockWordPressClientAPI->method('changeZoneSettings')->willReturn(false);
121
122 $this->pluginActions->applyDefaultSettings();
123 }
124}