}
public function testGetWithAlreadyExistingFileAndOutdatedTimestamp() {
- $this->config
- ->expects($this->at(0))
- ->method('getSystemValue')
- ->with('appstoreenabled', true)
- ->willReturn(true);
- $this->config
- ->expects($this->at(1))
- ->method('getSystemValue')
- ->with('appstoreenabled', true)
- ->willReturn(true);
- $this->config
- ->expects($this->at(2))
- ->method('getSystemValue')
- ->with(
- $this->equalTo('version'),
- $this->anything()
- )->willReturn('11.0.0.2');
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function($key, $default) {
+ if ($key === 'appstoreenabled') {
+ return true;
+ } else if ($key === 'version') {
+ return '11.0.0.2';
+ } else {
+ return $default;
+ }
+ });
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
}
public function testGetWithExceptionInClient() {
- $this->config
- ->expects($this->at(0))
- ->method('getSystemValue')
- ->with('appstoreenabled', true)
- ->willReturn(true);
- $this->config
- ->expects($this->at(1))
- ->method('getSystemValue')
- ->with('appstoreenabled', true)
- ->willReturn(true);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function($key, $default) {
+ if ($key === 'appstoreenabled') {
+ return true;
+ } else {
+ return $default;
+ }
+ });
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
->expects($this->at(0))
->method('getContent')
->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}');
- $this->timeFactory
- ->expects($this->at(0))
- ->method('getTime')
- ->willReturn(1501);
$client = $this->createMock(IClient::class);
$this->clientService
->expects($this->once())
}
public function testGetMatchingETag() {
- $this->config
- ->expects($this->at(0))
- ->method('getSystemValue')
- ->with('appstoreenabled', true)
- ->willReturn(true);
- $this->config
- ->expects($this->at(1))
- ->method('getSystemValue')
- ->with('appstoreenabled', true)
- ->willReturn(true);
- $this->config
- ->expects($this->at(2))
- ->method('getSystemValue')
- ->with(
- $this->equalTo('version'),
- $this->anything()
- )->willReturn('11.0.0.2');
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function($key, $default) {
+ if ($key === 'appstoreenabled') {
+ return true;
+ } else if ($key === 'version') {
+ return '11.0.0.2';
+ } else {
+ return $default;
+ }
+ });
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
}
public function testGetNoMatchingETag() {
- $this->config
- ->expects($this->at(0))
- ->method('getSystemValue')
- ->with('appstoreenabled', true)
- ->willReturn(true);
- $this->config
- ->expects($this->at(1))
- ->method('getSystemValue')
- ->with('appstoreenabled', true)
- ->willReturn(true);
- $this->config
- ->expects($this->at(2))
- ->method('getSystemValue')
- ->with(
- $this->equalTo('version'),
- $this->anything()
- )->willReturn('11.0.0.2');
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function($key, $default) {
+ if ($key === 'appstoreenabled') {
+ return true;
+ } else if ($key === 'version') {
+ return '11.0.0.2';
+ } else {
+ return $default;
+ }
+ });
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
];
$this->assertSame($expected, $this->fetcher->get());
}
+
+
+ public function testFetchAfterUpgradeNoETag() {
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function($key, $default) {
+ if ($key === 'appstoreenabled') {
+ return true;
+ } else if ($key === 'version') {
+ return '11.0.0.3';
+ } else {
+ return $default;
+ }
+ });
+
+ $folder = $this->createMock(ISimpleFolder::class);
+ $file = $this->createMock(ISimpleFile::class);
+ $this->appData
+ ->expects($this->once())
+ ->method('getFolder')
+ ->with('/')
+ ->willReturn($folder);
+ $folder
+ ->expects($this->at(0))
+ ->method('getFile')
+ ->with($this->fileName)
+ ->willReturn($file);
+ $file
+ ->expects($this->at(0))
+ ->method('getContent')
+ ->willReturn('{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}');
+ $client = $this->createMock(IClient::class);
+ $this->clientService
+ ->expects($this->once())
+ ->method('newClient')
+ ->willReturn($client);
+ $response = $this->createMock(IResponse::class);
+ $client
+ ->expects($this->once())
+ ->method('get')
+ ->with(
+ $this->equalTo($this->endpoint),
+ $this->equalTo([])
+ )
+ ->willReturn($response);
+ $response->method('getStatusCode')
+ ->willReturn(200);
+ $response
+ ->expects($this->once())
+ ->method('getBody')
+ ->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
+ $response->method('getHeader')
+ ->with($this->equalTo('ETag'))
+ ->willReturn('"newETag"');
+ $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}';
+ $file
+ ->expects($this->at(1))
+ ->method('putContent')
+ ->with($fileData);
+ $file
+ ->expects($this->at(2))
+ ->method('getContent')
+ ->willReturn($fileData);
+ $this->timeFactory
+ ->expects($this->once())
+ ->method('getTime')
+ ->willReturn(1501);
+
+ $expected = [
+ [
+ 'id' => 'MyNewApp',
+ 'foo' => 'foo',
+ ],
+ [
+ 'id' => 'bar',
+ ],
+ ];
+ $this->assertSame($expected, $this->fetcher->get());
+ }
}